CannotBeOrderedLessThanZero: add some missing cases
authorFiona Glaser <escha@apple.com>
Tue, 12 Jan 2016 23:37:30 +0000 (23:37 +0000)
committerFiona Glaser <escha@apple.com>
Tue, 12 Jan 2016 23:37:30 +0000 (23:37 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257542 91177308-0d34-0410-b5e6-96231b3b80d8

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

index abc57ed8bca06770df264cd8d55b3fd13ee4db67..a83e207bd265a5b2a45c5d6bb753125244c1e134 100644 (file)
@@ -2556,6 +2556,9 @@ bool llvm::CannotBeOrderedLessThanZero(const Value *V, unsigned Depth) {
 
   switch (I->getOpcode()) {
   default: break;
+  // Unsigned integers are always nonnegative.
+  case Instruction::UIToFP:
+    return true;
   case Instruction::FMul:
     // x*x is always non-negative or a NaN.
     if (I->getOperand(0) == I->getOperand(1)) 
@@ -2566,6 +2569,9 @@ bool llvm::CannotBeOrderedLessThanZero(const Value *V, unsigned Depth) {
   case Instruction::FRem:
     return CannotBeOrderedLessThanZero(I->getOperand(0), Depth+1) &&
            CannotBeOrderedLessThanZero(I->getOperand(1), Depth+1);
+  case Instruction::Select:
+    return CannotBeOrderedLessThanZero(I->getOperand(1), Depth+1) &&
+           CannotBeOrderedLessThanZero(I->getOperand(2), Depth+1);
   case Instruction::FPExt:
   case Instruction::FPTrunc:
     // Widening/narrowing never change sign.
@@ -2574,6 +2580,12 @@ bool llvm::CannotBeOrderedLessThanZero(const Value *V, unsigned Depth) {
     if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) 
       switch (II->getIntrinsicID()) {
       default: break;
+      case Intrinsic::maxnum:
+        return CannotBeOrderedLessThanZero(I->getOperand(0), Depth+1) ||
+               CannotBeOrderedLessThanZero(I->getOperand(1), Depth+1);
+      case Intrinsic::minnum:
+        return CannotBeOrderedLessThanZero(I->getOperand(0), Depth+1) &&
+               CannotBeOrderedLessThanZero(I->getOperand(1), Depth+1);
       case Intrinsic::exp:
       case Intrinsic::exp2:
       case Intrinsic::fabs:
index 8174f5834533232209065fc01c76ffebfb7f3ead..b148d9961d33870b70840ae0128e09892dd5f61f 100644 (file)
@@ -8,6 +8,8 @@ declare float @llvm.fabs.f32(float)
 declare float @llvm.sqrt.f32(float)
 declare double @llvm.powi.f64(double,i32)
 declare float @llvm.exp.f32(float)
+declare float @llvm.minnum.f32(float, float)
+declare float @llvm.maxnum.f32(float, float)
 declare double @llvm.exp2.f64(double)
 declare float @llvm.fma.f32(float,float,float)
 
@@ -58,6 +60,45 @@ define i1 @orderedLessZeroPowi(double,double) {
   ret i1 %olt
 }
 
+; CHECK-LABEL: @orderedLessZeroUIToFP(
+define i1 @orderedLessZeroUIToFP(i32) {
+  %a = uitofp i32 %0 to float
+  %uge = fcmp uge float %a, 0.000000e+00
+; CHECK: ret i1 true
+  ret i1 %uge
+}
+
+; CHECK-LABEL: @orderedLessZeroSelect(
+define i1 @orderedLessZeroSelect(float, float) {
+  %a = call float @llvm.exp.f32(float %0)
+  %b = call float @llvm.fabs.f32(float %1)
+  %c = fcmp olt float %0, %1
+  %d = select i1 %c, float %a, float %b
+  %e = fadd float %d, 1.0
+  %uge = fcmp uge float %e, 0.000000e+00
+; CHECK: ret i1 true
+  ret i1 %uge
+}
+
+; CHECK-LABEL: @orderedLessZeroMinNum(
+define i1 @orderedLessZeroMinNum(float, float) {
+  %a = call float @llvm.exp.f32(float %0)
+  %b = call float @llvm.fabs.f32(float %1)
+  %c = call float @llvm.minnum.f32(float %a, float %b)
+  %uge = fcmp uge float %c, 0.000000e+00
+; CHECK: ret i1 true
+  ret i1 %uge
+}
+
+; CHECK-LABEL: @orderedLessZeroMaxNum(
+define i1 @orderedLessZeroMaxNum(float, float) {
+  %a = call float @llvm.exp.f32(float %0)
+  %b = call float @llvm.maxnum.f32(float %a, float %1)
+  %uge = fcmp uge float %b, 0.000000e+00
+; CHECK: ret i1 true
+  ret i1 %uge
+}
+
 define i1 @nonans1(double %in1, double %in2) {
   %cmp = fcmp nnan uno double %in1, %in2
   ret i1 %cmp