[llvm] [InstCombine] Fold (X == 0 ? Y : 0) | X to X == 0 ? Y : X (PR #138373)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon May 5 09:25:26 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;
+ }
+ }
----------------
nikic wrote:
I'd try to lift the constant restrict only for `or` to start with (add an extra parameter AllowNonConstant or something), so we don't have to deal with too many things at once.
https://github.com/llvm/llvm-project/pull/138373
More information about the llvm-commits
mailing list