Index: lib/Analysis/ValueTracking.cpp =================================================================== --- lib/Analysis/ValueTracking.cpp +++ lib/Analysis/ValueTracking.cpp @@ -2556,6 +2556,9 @@ 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 @@ 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 @@ if (const IntrinsicInst *II = dyn_cast(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: test/Transforms/InstSimplify/floating-point-compare.ll =================================================================== --- test/Transforms/InstSimplify/floating-point-compare.ll +++ test/Transforms/InstSimplify/floating-point-compare.ll @@ -8,6 +8,8 @@ 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 @@ 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