[ValueTracking] peek through fpext in isKnownNeverInfinity()
authorSanjay Patel <spatel@rotateright.com>
Sun, 2 Oct 2022 15:19:05 +0000 (11:19 -0400)
committerSanjay Patel <spatel@rotateright.com>
Sun, 2 Oct 2022 15:20:23 +0000 (11:20 -0400)
https://alive2.llvm.org/ce/z/BkNoRW

llvm/lib/Analysis/ValueTracking.cpp
llvm/test/Transforms/InstSimplify/floating-point-compare.ll

index ddc96f7..4d63194 100644 (file)
@@ -3801,6 +3801,10 @@ bool llvm::isKnownNeverInfinity(const Value *V, const TargetLibraryInfo *TLI,
       Type *FPTy = Inst->getType()->getScalarType();
       return ilogb(APFloat::getLargest(FPTy->getFltSemantics())) >= IntSize;
     }
+    case Instruction::FPExt: {
+      // Peek through to source op. If it is not infinity, this is not infinity.
+      return isKnownNeverInfinity(Inst->getOperand(0), TLI, Depth + 1);
+    }
     default:
       break;
     }
index 3ff39b0..df0ad62 100644 (file)
@@ -1249,10 +1249,7 @@ define i1 @isNotKnownNeverNegativeInfinity_sitofp(i17 %x) {
 
 define i1 @isKnownNeverInfinity_fpext(float %x) {
 ; CHECK-LABEL: @isKnownNeverInfinity_fpext(
-; CHECK-NEXT:    [[A:%.*]] = fadd ninf float [[X:%.*]], 1.000000e+00
-; CHECK-NEXT:    [[E:%.*]] = fpext float [[A]] to double
-; CHECK-NEXT:    [[R:%.*]] = fcmp une double [[E]], 0x7FF0000000000000
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 true
 ;
   %a = fadd ninf float %x, 1.0
   %e = fpext float %a to double
@@ -1262,10 +1259,7 @@ define i1 @isKnownNeverInfinity_fpext(float %x) {
 
 define i1 @isKnownNeverInfinity_fpext_sitofp(i16 %x) {
 ; CHECK-LABEL: @isKnownNeverInfinity_fpext_sitofp(
-; CHECK-NEXT:    [[F:%.*]] = sitofp i16 [[X:%.*]] to half
-; CHECK-NEXT:    [[E:%.*]] = fpext half [[F]] to double
-; CHECK-NEXT:    [[R:%.*]] = fcmp oeq double [[E]], 0xFFF0000000000000
-; CHECK-NEXT:    ret i1 [[R]]
+; CHECK-NEXT:    ret i1 false
 ;
   %f = sitofp i16 %x to half
   %e = fpext half %f to double