[llvm] [DAGCombiner] Fold smax(X, -1) to or(X, ashr(X, BW-1)) for code size (PR #206242)

Aayush Shrivastava via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 27 13:18:20 PDT 2026


iamaayushrivastava wrote:

> finally, since you are here, why not also do
> 
> smin(X, 0) -> and(X, ashr(X, BW-1))
> 
> maybe bonus points if you do
> 
> smax(x, 0) though maybe since selectiondag does it already, hmm. maybe you should move your combine closer there, or if we cannot then I can make a PR to move it closer to you...

Done. added `smin(X, 0) -> and(X, ashr(X, BW-1))` alongside the `smax` fold. Both now share three guards. Thanks for the suggestion!

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


More information about the llvm-commits mailing list