[llvm] [InstCombine] Prevent constant operand shrinkage on returns of zero-extension ANDs (PR #146201)

Hanyang Xu via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 28 22:51:47 PDT 2025


ericxu233 wrote:

> The fact that the demanded constant shrinking can cause the introduction of unfavorable immediates is a known problem, and the case being addressed here is one of the less problematic ones. The most problematic are probably the cases where you have a small negative immediate like -8 and then zero out the top bits, creating a huge positive immediate instead.
> 
> This is challenging to undo in the backend if the information comes from assume (currently not persisted during codegen) or control flow (not really available at the SDAG level).
> 
> I don't have any particularly good idea on how to fix this case.

Ah, I see. May I suggest that we add a helper function called bool GuardShrinkConstant() so that we can add cases where we want to prevent constant operand shrinkage from happening? This change could be one of the first ones to go into it.

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


More information about the llvm-commits mailing list