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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 28 04:04:25 PDT 2025


https://github.com/nikic commented:

I don't think that the "return only use" here is really relevant -- it's a general property of x86 that it can encode a "low 32-bit" mask more compactly than other masks, regardless of where in the code it occurs.

Now, if you remove that special case and expose this to wider test coverage, you'll probably quickly find that this is going to break other optimizations that rely on the current demanded bits reduction.

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.

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


More information about the llvm-commits mailing list