[llvm] [InstCombine] Missed optimization: Fold (sext(a) & c1) == c2 to (a & c3) == trunc(c2) (PR #112646)

via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 25 07:59:03 PDT 2024


goldsteinn wrote:

> > Instead you can do `match(Op1, m_APInt(C2))` then check its okay with `C->getNumSignBits() <= A->getType()->getScalarSizeInBits() && C2->getNumSignBits() <= A->getType()->getScalarSizeInBits()` which is all the constraint that the proof needs.
> 
> @goldsteinn Thanks for the pointers! I tried your approach but I think the approach is a bit different from your example. Example: https://alive2.llvm.org/ce/z/GPZPJD. I can see that `C1->getNumSignBits()` relates to `%b_signbits = select i1 %b_neg, i32 %b_cl1, i32 %b_clz`. However, I also see that there is a `%b_bits = sub i32 33, %b_signbits` before comparing with `%a`'s bit width. Is this step also required to make it work?
> 
Sorry for missing this message.

The PR is coming along, think you have the right approach now and after another cycle or so if reviews should be good to merge.


https://github.com/llvm/llvm-project/pull/112646


More information about the llvm-commits mailing list