[PATCH] D28406: [InstCombine] icmp sgt (shl nsw X, C1), C0 --> icmp sgt X, C0 >> C1

bryant via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 18 22:05:29 PST 2017


bryant added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:1915
 
-  // If this is a signed comparison to 0 and the shift is sign preserving,
-  // use the shift LHS operand instead; isSignTest may change 'Pred', so only
-  // do that if we're sure to not continue on in this function.
-  if (Shl->hasNoSignedWrap() && isSignTest(Pred, *C))
-    return new ICmpInst(Pred, X, Constant::getNullValue(ShType));
+  // A 'shl nsw' is just shifting out sign bits, so adjust the compare constant
+  // and eliminate the shift.
----------------
bryant wrote:
> `shl nsw` is also shifting out zeroes, no? It's `ashr` that shifts in sign bits.
What I mean is (also for the ugt summary): It's because **shl shifts in zeroes** that warrants this transform. In other words, in the un-transformed icmp, we're comparing against known zero bits introduced by the shl.


https://reviews.llvm.org/D28406





More information about the llvm-commits mailing list