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

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 17 13:15:26 PDT 2024


goldsteinn wrote:

> > To expand on how to make it generic, see: https://alive2.llvm.org/ce/z/RWYisS
> 
> @goldsteinn I still cannot understand how to make my implementation more generic from your Alive2 example. Can you shed some light on this? Is there any existing code that you can reference me to? Thank you!

Current you are checking


> > To expand on how to make it generic, see: https://alive2.llvm.org/ce/z/RWYisS
> 
> @goldsteinn I still cannot understand how to make my implementation more generic from your Alive2 example. Can you shed some light on this? Is there any existing code that you can reference me to? Thank you!

The `*C == APInt::getSignedMinValue(C->getBitWidth()) + 1` and `match(Op1, m_One())` basically imply that your `c1` and `c2` can only be those two values respectively.

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.

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


More information about the llvm-commits mailing list