[llvm] [InstCombine] Fold X + umax(X, 1) -> umax(X << 1, 1) (PR #222727)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 01:46:06 PDT 2026


nikic wrote:

Looking at the llvm-opt-benchmark IR, the main optimization opportunity I see is that we can drop the unnecessary select, like so: https://alive2.llvm.org/ce/z/dGTJWT

I don't get how we can avoid the umin -- it does not actually seem to use ssize_t_max as the constant?

My main worry with this transform, if we want to build on top of it, is that the fact that something like `shl nsw (ashr exact x, 4), 2` gets folded to `ashr exact x, 3` means that we end up with two different values used in the umax and the icmp, which no longer trivially correlate.

Not necessarily saying that this is the wrong direction, just want to make sure that if followup folds here are planned, we need to check that they will actually interact in the expected way first.

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


More information about the llvm-commits mailing list