[llvm] [InstCombine] Fold (X == 0 ? Y : 0) | X to X == 0 ? Y : X (PR #138373)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Wed May 7 09:58:46 PDT 2025
================
@@ -3658,6 +3658,15 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
return R;
}
+ // (X == 0 ? Y : 0) | X -> X == 0 ? Y : X
+ // X | (X == 0 ? Y : 0) -> X == 0 ? Y : X
+ for (Value *Op : {Op0, Op1}) {
+ if (auto *SI = dyn_cast<SelectInst>(Op)) {
+ if (auto *R = FoldOpIntoSelect(I, SI, /* FoldWithMultiUse */ false))
+ return R;
+ }
+ }
----------------
s-barannikov wrote:
I guess the reverse transformation is done by `foldSelectIntoOp()`.
See the comment near `getSelectFoldableOperands()` (initially introduced by 56e4d3d8ad0f185d1245fa43d12b1dbe64ea5981 back in 2004).
https://github.com/llvm/llvm-project/pull/138373
More information about the llvm-commits
mailing list