[llvm] [InstCombine] Fold select chain to frozen bool reduction (PR #217482)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 00:05:06 PDT 2026
================
@@ -4582,6 +4582,65 @@ static bool isSelectZeroSignInsignificant(SelectInst &SI) {
return true;
}
+static Instruction *foldSelectExtractEl(SelectInst &SI,
+ InstCombiner::BuilderTy &Builder) {
+ // select (extractelement (icmp Pred X, Y), C1)
+ // (extractelement (icmp Pred X, Y) C2), 0
+ // ->
+ // icmp eq (bitcast (freeze (icmp Pred X, Y)) to iN), C3
+ Value *X;
+ Value *Y;
+ CmpPredicate Pred1, Pred2;
+ const APInt *C1, *C2;
+ if (match(&SI,
+ m_Select(m_ExtractElt(m_ICmp(Pred1, m_Value(X), m_Value(Y)),
+ m_APInt(C1)),
+ m_ExtractElt(m_ICmp(Pred2, m_Deferred(X), m_Deferred(Y)),
+ m_APInt(C2)),
+ m_Zero()))
----------------
RKSimon wrote:
(style) early out:
```
if (!match(&SI,
m_Select(m_ExtractElt(m_ICmp(Pred1, m_Value(X), m_Value(Y)), m_APInt(C1)),
m_ExtractElt(m_ICmp(Pred2, m_Deferred(X), m_Deferred(Y)), m_APInt(C2)),
m_Zero()) ||
!CmpPredicate::getMatching(Pred1, Pred2);)
return nullptr;
```
https://github.com/llvm/llvm-project/pull/217482
More information about the llvm-commits
mailing list