[PATCH] [InstCombineCompares] Added shl optimization for the instruction - icmp eq/ne (shl Const2, A), Const1

David Majnemer david.majnemer at gmail.com
Sat Oct 18 00:47:40 PDT 2014


All of the test cases you have here that return a constant are already handled by InstSimplify (which is run as part of InstCombine) so you aren't really testing them.  Please do not complicate the code by handling impossible cases.

================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:1149
@@ +1148,3 @@
+
+    int zeros = AP2.countTrailingZeros();
+
----------------
This should be `unsigned`. You should also save the result so it can be reused later on.  This isn't always efficient to calculate.

================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:1152
@@ +1151,3 @@
+    if (zeros != 0) {
+      return getICmp(I.ICMP_UGE, A, ConstantInt::get(A->getType(), AP2.getBitWidth() - zeros));
+    } else {
----------------
Run clang format here.

================
Comment at: test/Transforms/InstCombine/icmp.ll:1424-1428
@@ +1423,7 @@
+; CHECK-NEXT: ret i1 true
+define i1 @shl_both_zero(i32 %a) {
+ %shl = shl i32 0, %a
+ %cmp = icmp eq i32 %shl, 0
+ ret i1 %cmp
+}
+
----------------
This is already handled by InstSimplify.

================
Comment at: test/Transforms/InstCombine/icmp.ll:1432-1436
@@ +1431,7 @@
+; CHECK-NEXT: ret i1 false
+define i1 @shl_ap1_zero_ap2_non_zero_1(i32 %a) {
+ %shl = shl i32 1, %a
+ %cmp = icmp eq i32 %shl, 0
+ ret i1 %cmp
+}
+
----------------
This is already handled by InstSimplify.

================
Comment at: test/Transforms/InstCombine/icmp.ll:1449-1453
@@ +1448,7 @@
+; CHECK-NEXT: ret i1 false
+define i1 @shl_ap1_zero_ap2_non_zero_3(i32 %a) {
+ %shl = shl i32 -1, %a
+ %cmp = icmp eq i32 %shl, 0
+ ret i1 %cmp
+}
+
----------------
This is already handled by InstSimplify.

================
Comment at: test/Transforms/InstCombine/icmp.ll:1466-1470
@@ +1465,7 @@
+; CHECK-NEXT: ret i1 false
+define i1 @shl_ap1_non_zero_ap2_zero(i32 %a) {
+ %shl = shl i32 0, %a
+ %cmp = icmp eq i32 %shl, 5
+ ret i1 %cmp
+}
+
----------------
This is already handled by InstSimplify.

http://reviews.llvm.org/D5839






More information about the llvm-commits mailing list