diff options
author | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2014-10-09 12:41:49 +0000 |
---|---|---|
committer | Andrea Di Biagio <Andrea_DiBiagio@sn.scee.net> | 2014-10-09 12:41:49 +0000 |
commit | 458a669f49e30a30b0fbfcc34fc4e556befbb73b (patch) | |
tree | 3910473c2104a4a7138d9c50220f32f2bca5a13a | |
parent | 9b280eab6699e4d1e3e203254ec93b424f10f40d (diff) | |
download | bcm5719-llvm-458a669f49e30a30b0fbfcc34fc4e556befbb73b.tar.gz bcm5719-llvm-458a669f49e30a30b0fbfcc34fc4e556befbb73b.zip |
[InstCombine] Fix wrong folding of constant comparisons involving ashr and negative values.
This patch fixes a bug in method InstCombiner::FoldCmpCstShrCst where we
wrongly computed the distance between the highest bits set of two negative
values.
This fixes PR21222.
Differential Revision: http://reviews.llvm.org/D5700
llvm-svn: 219406
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 3 | ||||
-rw-r--r-- | llvm/test/Transforms/InstCombine/icmp-shr.ll | 8 |
2 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 00623b1cbf6..2918f031b3f 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1107,7 +1107,8 @@ Instruction *InstCombiner::FoldICmpCstShrCst(ICmpInst &I, Value *Op, Value *A, // Get the distance between the highest bit that's set. int Shift; if (IsNegative) - Shift = (-AP2).logBase2() - (-AP1).logBase2(); + // Get the ones' complement of AP2 and AP1 when computing the distance. + Shift = (~AP2).logBase2() - (~AP1).logBase2(); else Shift = AP2.logBase2() - AP1.logBase2(); diff --git a/llvm/test/Transforms/InstCombine/icmp-shr.ll b/llvm/test/Transforms/InstCombine/icmp-shr.ll index 8e7c906a545..7562f24a35d 100644 --- a/llvm/test/Transforms/InstCombine/icmp-shr.ll +++ b/llvm/test/Transforms/InstCombine/icmp-shr.ll @@ -688,3 +688,11 @@ define i1 @PR20945(i32 %B) { %cmp = icmp ne i32 %shr, -5 ret i1 %cmp } + +; CHECK-LABEL: @PR21222 +; CHECK: icmp eq i32 %B, 6 +define i1 @PR21222(i32 %B) { + %shr = ashr i32 -93, %B + %cmp = icmp eq i32 %shr, -2 + ret i1 %cmp +} |