[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 01:37:26 PDT 2014
================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:1145
@@ +1144,3 @@
+ if (!AP1) {
+ unsigned zeros = AP2.countTrailingZeros();
+
----------------
This should be named Zeros. Also, please reuse this for the calculation on line 1158.
================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:1147-1150
@@ +1146,6 @@
+
+ if (zeros != 0) {
+ return getICmp(I.ICMP_UGE, A,
+ ConstantInt::get(A->getType(), AP2.getBitWidth() - zeros));
+ }
+ }
----------------
I'd remove the braces around this.
================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:1153-1164
@@ +1152,14 @@
+
+ if (AP1 == AP2) {
+ return getICmp(I.ICMP_EQ, A, ConstantInt::getNullValue(A->getType()));
+ }
+
+ // Get the distance between the lowest bits that are set.
+ int Shift = AP1.countTrailingZeros() - AP2.countTrailingZeros();
+
+ if (Shift > 0) {
+ if (AP2.shl(Shift) == AP1) {
+ return getICmp(I.ICMP_EQ, A, ConstantInt::get(A->getType(), Shift));
+ }
+ }
+
----------------
These cases can be merged:
if (Shift >= 0 && AP2.shl(Shift) == AP1)
return getICmp(I.ICMP_EQ, A, ConstantInt::get(A->getType(), Shift));
http://reviews.llvm.org/D5839
More information about the llvm-commits
mailing list