[llvm] [InstCombine] Improve coverage of `foldSelectValueEquivalence` (PR #88298)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 5 23:43:14 PDT 2024
================
@@ -1308,11 +1310,52 @@ Instruction *InstCombinerImpl::foldSelectValueEquivalence(SelectInst &Sel,
if (match(V, m_ImmConstant()))
return replaceOperand(Sel, Swapped ? 2 : 1, V);
- // If NewOp is a constant and OldOp is not replace iff NewOp doesn't
- // contain and undef/poison elements.
- if (match(NewOp, m_ImmConstant()) &&
- isGuaranteedNotToBeUndefOrPoison(NewOp, SQ.AC, &Sel, &DT))
+ // We can't do any further replacement if NewOp may be undef/poison.
+ if (!isGuaranteedNotToBeUndefOrPoison(NewOp, SQ.AC, &Sel, &DT))
+ return nullptr;
+
+ // If NewOp is a constant, replace.
+ if (match(NewOp, m_ImmConstant()))
+ return replaceOperand(Sel, Swapped ? 2 : 1, V);
+
+ // If we simplified the TrueArm -> NewOp then replace.
+ // This handles things like `select`/`min`/`max`/`or`/`and`/etc...
+ if (NewOp == V)
----------------
goldsteinn wrote:
Hmm, maybe a case like `(select (icmp eq (or x, y), y), (or x, y), Q)`. Where we replace `y` with `(or x, y)` and then `(or x, y), x/y)` -> `(or x, y)`.
I think for it to inf loop through would need `NewOp == TrueArm`. I think we can probably safely just return null for that case.
Either way, ill run csmith for a bit.
What do you mean 128C server?
https://github.com/llvm/llvm-project/pull/88298
More information about the llvm-commits
mailing list