[llvm] [InstCombine] Fold (X == 0 ? Y : 0) | X to X == 0 ? Y : X (PR #138373)
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 5 08:22:06 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;
+ }
+ }
----------------
YLChenZ wrote:
If we ignore the sext/zext case and lift constant restriction, then do the test I get the following result:
```
llvm test
********************
Timed Out Tests (6):
LLVM :: Transforms/InstCombine/conditional-variable-length-signext-after-high-bit-extract.ll
LLVM :: Transforms/InstCombine/icmp-and-lowbit-mask.ll
LLVM :: Transforms/InstCombine/logical-select-inseltpoison.ll
LLVM :: Transforms/InstCombine/logical-select.ll
LLVM :: Transforms/InstCombine/vec_sext.ll
LLVM :: Transforms/PhaseOrdering/vector-select.ll
********************
Failed Tests (16):
LLVM :: Transforms/InstCombine/binop-phi-operands.ll
LLVM :: Transforms/InstCombine/binop-select.ll
LLVM :: Transforms/InstCombine/dont-distribute-phi.ll
LLVM :: Transforms/InstCombine/fmul.ll
LLVM :: Transforms/InstCombine/free-inversion.ll
LLVM :: Transforms/InstCombine/icmp-or-of-select-with-zero.ll
LLVM :: Transforms/InstCombine/mul-inseltpoison.ll
LLVM :: Transforms/InstCombine/or-select-zero-icmp.ll
LLVM :: Transforms/InstCombine/pr82877.ll
LLVM :: Transforms/InstCombine/recurrence.ll
LLVM :: Transforms/InstCombine/select-cmp-cttz-ctlz.ll
LLVM :: Transforms/InstCombine/select.ll
LLVM :: Transforms/InstCombine/simplify-demanded-fpclass.ll
LLVM :: Transforms/InstCombine/sub-gep.ll
LLVM :: Transforms/InstCombine/xor.ll
LLVM :: Transforms/PhaseOrdering/AArch64/predicated-reduction.ll
clang test
********************
Timed Out Tests (1):
Clang :: CodeGen/SystemZ/builtins-systemz-zvector5.c
--timeout=100
```
I think the failed may be well handled , but the timed out is tricky, and there should seem to be infinite loops when folding. I don't know if I'm right about this.
https://github.com/llvm/llvm-project/pull/138373
More information about the llvm-commits
mailing list