summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBob Wilson <bob.wilson@apple.com>2012-08-07 22:35:16 +0000
committerBob Wilson <bob.wilson@apple.com>2012-08-07 22:35:16 +0000
commit61f3ad575911f72cbfcd328d1221e943b687ebf2 (patch)
treedac10fc42a864c49fab0eae70a309d1ec6ed531c
parentfbdd25c13576d68ad2517390513c7a0f23d93919 (diff)
downloadbcm5719-llvm-61f3ad575911f72cbfcd328d1221e943b687ebf2.tar.gz
bcm5719-llvm-61f3ad575911f72cbfcd328d1221e943b687ebf2.zip
Fix a serious typo in InstCombine's optimization of comparisons.
An unsigned value converted to floating-point will always be greater than a negative constant. Unfortunately InstCombine reversed the check so that unsigned values were being optimized to always be greater than all positive floating-point constants. <rdar://problem/12029145> llvm-svn: 161452
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp2
-rw-r--r--llvm/test/Transforms/InstCombine/2008-11-08-FCmp.ll9
2 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 7076d88554d..bdd310e97f6 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2824,7 +2824,7 @@ Instruction *InstCombiner::FoldFCmp_IntToFP_Cst(FCmpInst &I,
case ICmpInst::ICMP_UGE:
// (float)int >= -4.4 --> true
// (float)int >= 4.4 --> int > 4
- if (!RHS.isNegative())
+ if (RHS.isNegative())
return ReplaceInstUsesWith(I, ConstantInt::getTrue(I.getContext()));
Pred = ICmpInst::ICMP_UGT;
break;
diff --git a/llvm/test/Transforms/InstCombine/2008-11-08-FCmp.ll b/llvm/test/Transforms/InstCombine/2008-11-08-FCmp.ll
index c636288661b..f33a1f59f61 100644
--- a/llvm/test/Transforms/InstCombine/2008-11-08-FCmp.ll
+++ b/llvm/test/Transforms/InstCombine/2008-11-08-FCmp.ll
@@ -45,3 +45,12 @@ define i1 @test6(i32 %val) {
ret i1 %2
; CHECK: ret i1 false
}
+
+; Check that optimizing unsigned >= comparisons correctly distinguishes
+; positive and negative constants. <rdar://problem/12029145>
+define i1 @test7(i32 %val) {
+ %1 = uitofp i32 %val to double
+ %2 = fcmp oge double %1, 3.200000e+00
+ ret i1 %2
+; CHECK: icmp ugt i32 %val, 3
+}
OpenPOWER on IntegriCloud