[PATCH] D144777: [InstCombine] Fold signbit test of a pow2 or zero

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 26 17:54:14 PST 2023


spatel added a comment.

In D144777#4153685 <https://reviews.llvm.org/D144777#4153685>, @junaire wrote:

> Hi @spatel, thanks for your comments, I updated the tests according to your
> suggestions. However, everything stop folding after I use div instructions to
> each oprands of and instruction.
>
> Can you take a look? Is this because I missed something? Or my fold pattern is wrong.

There shouldn't be any extra instruction between the `sub` (negate) and `and`. You just need one extra binary-op instruction to create "%x", so it stays operand 0 of the `and`. You don't need any extra instructions if you want "%x" to be operand 1.

I think it would be better to add the transform inside of `InstCombinerImpl::foldICmpAndConstant()`.



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1341
+  Value *X;
+  // icmp slt (and -X, X), 0 --> icmp eq (X, CI)
+  // icmp sgt (and -X, X), -1 --> icmp ne (X, CI)
----------------
"CI" should be "MinSignedC" or something like that in these comments and the code to be more specific.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D144777



More information about the llvm-commits mailing list