[ValueTracking] improve analysis for fdiv with same operands

(The 'nnan' variant of this pattern is already tested to produce '1.0'.)

https://alive2.llvm.org/ce/z/D4hPBy

define i1 @src(float %x, i32 %y) {
%0:
  %d = fdiv float %x, %x
  %uge = fcmp uge float %d, 0.000000
  ret i1 %uge
}
=>
define i1 @tgt(float %x, i32 %y) {
%0:
  ret i1 1
}
Transformation seems to be correct!
This commit is contained in:
Sanjay Patel 2020-06-21 08:50:29 -04:00
parent 45cf04ad9d
commit a92fa1323b
2 changed files with 4 additions and 5 deletions

View File

@ -3340,14 +3340,15 @@ static bool cannotBeOrderedLessThanZeroImpl(const Value *V,
case Instruction::UIToFP:
return true;
case Instruction::FMul:
// x*x is always non-negative or a NaN.
case Instruction::FDiv:
// X * X is always non-negative or a NaN.
// X / X is always exactly 1.0 or a NaN.
if (I->getOperand(0) == I->getOperand(1) &&
(!SignBitOnly || cast<FPMathOperator>(I)->hasNoNaNs()))
return true;
LLVM_FALLTHROUGH;
case Instruction::FAdd:
case Instruction::FDiv:
case Instruction::FRem:
return cannotBeOrderedLessThanZeroImpl(I->getOperand(0), TLI, SignBitOnly,
Depth + 1) &&

View File

@ -205,9 +205,7 @@ define i1 @orderedLessZeroTree(float,float,float,float) {
define i1 @orderedLessZero_fdiv(float %x) {
; CHECK-LABEL: @orderedLessZero_fdiv(
; CHECK-NEXT: [[D:%.*]] = fdiv float [[X:%.*]], [[X]]
; CHECK-NEXT: [[UGE:%.*]] = fcmp uge float [[D]], 0.000000e+00
; CHECK-NEXT: ret i1 [[UGE]]
; CHECK-NEXT: ret i1 true
;
%d = fdiv float %x, %x
%uge = fcmp uge float %d, 0.0