[llvm] r219406 - [InstCombine] Fix wrong folding of constant comparisons involving ashr and negative values.
Andrea Di Biagio
Andrea_DiBiagio at sn.scee.net
Thu Oct 9 05:41:50 PDT 2014
Author: adibiagio
Date: Thu Oct 9 07:41:49 2014
New Revision: 219406
URL: http://llvm.org/viewvc/llvm-project?rev=219406&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/trunk/test/Transforms/InstCombine/icmp-shr.ll
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=219406&r1=219405&r2=219406&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Thu Oct 9 07:41:49 2014
@@ -1107,7 +1107,8 @@ Instruction *InstCombiner::FoldICmpCstSh
// 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();
Modified: llvm/trunk/test/Transforms/InstCombine/icmp-shr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/icmp-shr.ll?rev=219406&r1=219405&r2=219406&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/icmp-shr.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/icmp-shr.ll Thu Oct 9 07:41:49 2014
@@ -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
+}
More information about the llvm-commits
mailing list