[llvm] [IndVarSimplify] Widen select-controlled recurrences (PR #206024)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 30 07:35:38 PDT 2026


https://github.com/antoniofrighetto commented:

Following up on @nikic suggestion, I wonder if we have considered whether it may be possible to bring the IR in a more amenable form to let IndVarSimplify to widen the IV, or whether the widening itself may be done via a series of local optimizations in InstCombine. One thing I've been wondering is whether we could extend foldOpIntoPhi() to push the sext into the phi (obtaining https://alive2.llvm.org/ce/z/5YKiLe). Then, matching our pattern, the i32 phi `%Minlst.011`, whose only use would be select's arm, could just become a `trunc nsw i64 %Minlst.011.wide to i32` (making the phi dead), leading to the simplified form. This might be non-trivial though, so the approach here could be possibly easier.

That said, my understanding is that this would help address the more complicated form with sext/trunc. GVN/MDA recently started featuring load PRE through phi-translated select addresses (0075a8fbcc9928ef5a04a30233b08f67219a4310). Would this help/handle the original simplified instance?

Haven't caught up with the whole background, sorry if I'm missing something.

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


More information about the llvm-commits mailing list