[PATCH] D55745: [InstCombine] Simplify cttz/ctlz + icmp eq/ne into mask check

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 17 13:39:40 PST 2018


spatel added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineCompares.cpp:2796
+        : APInt::getOneBitSet(BitWidth, BitWidth - Num - 1);
+      Cmp.setOperand(0, Builder.CreateAnd(II->getArgOperand(0), Mask1));
+      Cmp.setOperand(1, ConstantInt::get(Ty, Mask2));
----------------
We have to check hasOneUse() on the intrinsic, or we'll end up with extra instructions for an example like this:

```
define i1 @ctlz_eq_other_i32(i32 %x, i32* %p) {
  %lz = tail call i32 @llvm.ctlz.i32(i32 %x, i1 false)
  store i32 %lz, i32* %p
  %cmp = icmp eq i32 %lz, 24
  ret i1 %cmp
}

```

In cases where the 'and' gets removed, you don't need the one-use restriction, but I'm not sure if it's worth trying to differentiate those from the general case.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55745/new/

https://reviews.llvm.org/D55745





More information about the llvm-commits mailing list