From 8634c66a7d66476403a0312631f316a31ff9dd78 Mon Sep 17 00:00:00 2001 From: Fiona Glaser Date: Tue, 12 Jan 2016 23:37:30 +0000 Subject: [PATCH] CannotBeOrderedLessThanZero: add some missing cases git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257542 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ValueTracking.cpp | 12 ++++++ .../InstSimplify/floating-point-compare.ll | 41 +++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp index abc57ed8bca..a83e207bd26 100644 --- a/lib/Analysis/ValueTracking.cpp +++ b/lib/Analysis/ValueTracking.cpp @@ -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(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: diff --git a/test/Transforms/InstSimplify/floating-point-compare.ll b/test/Transforms/InstSimplify/floating-point-compare.ll index 8174f583453..b148d9961d3 100644 --- a/test/Transforms/InstSimplify/floating-point-compare.ll +++ b/test/Transforms/InstSimplify/floating-point-compare.ll @@ -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 -- 2.34.1