[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 11:12:12 PST 2017


bryant added a comment.

I'm not seeing any test cases for nsw/nuw eq/ne. Should/Can they be added?



================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:1959
+      assert(C->lshr(*ShiftAmt).shl(*ShiftAmt) == *C &&
+             "Compare known true or false was not folded");
+      APInt ShiftedC = C->lshr(*ShiftAmt);
----------------
Can this branch be merged with ugt?

```
if (Cmp.isEquality() || Pred == ICMP_UGT) {
  assert(!Cmp.isEquality || C->lshr(*ShiftAmt).shl(*ShiftAmt) == *C &&
             "Compare known true or false was not folded");
  // do the transform
}
```


================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:1974
 
-  if (Cmp.isEquality()) {
+  if (Cmp.isEquality() && Shl->hasOneUse()) {
+    // Strength-reduce the shift into an 'and'.
----------------
Should this go into its own patch?


https://reviews.llvm.org/D28406





More information about the llvm-commits mailing list