[llvm] Optimize addition of selects (PR #224132)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 17 04:01:11 PDT 2026


https://github.com/antoniofrighetto commented:

I'd suggest considering separately one transform at a time. I think the second transform is essentially already handled for a generic binary operator in SimplifySelectsFeedingBinaryOp(), where we know either one operand (or both) is a select, specifically along the following lines:

https://github.com/llvm/llvm-project/blob/177bbcb1dffa5459436f6472ca23c3d9a1479e73/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp#L1411-L1425

The terms of the selects are rearranged if either one can be constant folded via simplifyBinOp(). What the code does not consider is that when RHS (LHS) is itself a select whose condition is implied by A (D), it can be resolved to one of its arms before being passed to simplifyBinOp() (so possibly using isImpliedCondition() to resolve each select per-arm would generalize this folding).

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


More information about the llvm-commits mailing list