[PATCH] D126591: [InstCombine] Optimise shift+and+boolean conversion pattern to simple comparison

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 20 03:51:00 PDT 2022


spatel added a comment.

I added a similar fold here:
0399473de886 <https://reviews.llvm.org/rG0399473de886595d8ce3346f2cc99c94267496e5>

It seems like we might be missing some generalization for power-of-2 values, but this patch seems fine. Please add alive2 links to the patch summary (these are in issue #56124?).



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:5568-5569
+        if (C1->isOne() && C2.isPowerOf2()) {
           // ((1 << X) & 8) == 0 -> X != 3
           // ((1 << X) & 8) != 0 -> X == 3
+          auto *CmpC = ConstantInt::get(XTy, C2.countTrailingZeros());
----------------
Is this just a special-case of the next pattern? If so, I think it is better to reduce the patch. We might have slightly less efficiency at run-time, but there's less code to maintain here.


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

https://reviews.llvm.org/D126591



More information about the llvm-commits mailing list