[llvm] [AArch64] Fold CSEL of a CSEL with the same flags (PR #224992)

Valeriy Savchenko via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 02:47:32 PDT 2026


SavchenkoValeriy wrote:

> > Is there any particular reason we want to do it in ISel as opposed to a fold in InstCombine? Folding select of select with the same (or negated) condition sounds like all targets can benefit.
> 
> @SavchenkoValeriy Currently `InstCombine` handles the single use case only. But for our use, we need to support multi use for intermediate ops. It can definitely be implemented in `AggressiveInstCombine` where the IR instruction count is not as strict. A case can be made for implementing it in `InstCombine`, since it is still profitable for downstream optimizations that results in less instructions for both x86 and AArch64.
> 
> But if we implement it during ISel, the fold is guaranteed to not increase instruction count or regress performance.

Please correct me if I'm wrong, but isn't `select %cond (select %cond %a %b) %c` always foldable to `select %cond %a %c`? If the nested `select` has more uses - fine, we can keep it, but a. maintain the same number of IR instructions and b. shorten the critical path. If we block it on the nested `select` having a single use, it sounds like a perfect opportunity to relax it.

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


More information about the llvm-commits mailing list