[llvm] [InstCombine] Enable FoldOpIntoSelect when the Op's other parameter is non-const (PR #166102)

Gábor Spaits via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 4 00:50:21 PST 2025


spaits wrote:

Thank you @dtcxzyw @andjo403 for reviewing this.

## About this PR
I would prefer just updating the PR description and keep both `FoldOpIntoSelect` and `foldOpIntoPhi`, since the compile time regression isn't significant, so there is no huge downside of enabling both even if one doesn't seem to be that effective.

I will add the tests you have mentioned and see what they do.

## The Motivating Issue
For the issue #163108 I have created a seperate PR #166241. It is still in draft since I did not have enough time to finish the testing and the coverage of all binary operators. The PR is neccessary, since enabling `FoldOpIntoSelect` can only address cases where the one of the constants is 0.

Can I ask you to please check it. Is my approach the right one? Or I should attempt to port the logic into the `simplifyInstr` infrastructure?

The current approach shows good result for `or` and `xor` even when both constants are non-zero. The `and` test cases seem to be working out of the box. Maybe I just haven't found any test cases where my patch is needed for the `and` cases to work.

Thank you for your time and effort for reviwing.

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


More information about the llvm-commits mailing list