[llvm] InstCombine: fold mul (select (icmp ugt X, 1) (1, add nuw nsw X, 1)), Y -> shl Y, zext (icmp eq X, 1) (PR #215162)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 14 22:27:10 PDT 2026


user1342234 wrote:

> I do not currently have an exact real-world occurrence. The testcase was derived from test2 in llvm/test/CodeGen/NVPTX/combine-mad.ll, which contains (s < 1 ? 1 : n + 1) * m. A bounded variant that correlates the condition with n gives (n < 2 ? n + 1 : 1) * m.
> 
> The issue is intended to show a representation-sensitive gap around the {0, 1} value set fact. The existing fold handles (x + 1) * y when this fact is expressed directly as a range, while the equivalent fact established by the correlated ternary does not produce the same optimization result. The select is one concrete representation of the fact; the underlying issue is that the optimization result depends on its representation.

 _Originally posted by @134ARG in [#211183](https://github.com/llvm/llvm-project/issues/211183#issuecomment-5261666465)_
@dtcxzyw 


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


More information about the llvm-commits mailing list