[llvm] [InstCombine] Fold its select user into select (PR #83405)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 8 18:49:12 PST 2024
================
@@ -500,6 +500,42 @@ static bool isSelect01(const APInt &C1I, const APInt &C2I) {
return C1I.isOne() || C1I.isAllOnes() || C2I.isOne() || C2I.isAllOnes();
}
+/// Try to simplify a select instruction when the user of its select user
+/// indicates the condition.
+static bool simplifySeqSelectWithSameCond(SelectInst &SI,
+ const SimplifyQuery &SQ,
+ InstCombinerImpl &IC) {
+ Value *CondVal = SI.getCondition();
+ Type *CondType = CondVal->getType();
+
+ SelectInst *SINext = &SI;
+ Type *SelType = SINext->getType();
+ Value *FalseVal = SINext->getFalseValue();
+ Value *CondNext;
+ Value *FalseNext;
+ while (match(FalseVal,
+ m_Select(m_Value(CondNext), m_Value(), m_Value(FalseNext)))) {
+ // If the type of select is not an integer type or if the condition and
+ // the selection type are not both scalar nor both vector types, there is no
+ // point in attempting to match these patterns.
+ if (!isa<Constant>(CondVal) && SelType->isIntOrIntVectorTy() &&
+ CondType->isVectorTy() == SelType->isVectorTy())
----------------
vfdff wrote:
Thanks, also chase true value now.
I don't use `m_Select(m_Specific(CondVal), ...)` because we don't need all the select chains have the same condition.
Just as the case **@src** in [#83225](https://github.com/llvm/llvm-project/issues/83225) shows, the condition of **%s2** is different from that of **%s3**.
```
define i32 @src(i32 %a, i1 %c1, i1 %c2){
entry:
%s1 = select i1 %c1, i32 23, i32 45
%s2 = select i1 %c2, i32 666, i32 %s1
%s3 = select i1 %c1, i32 789, i32 %s2
ret i32 %s3
}
```
https://github.com/llvm/llvm-project/pull/83405
More information about the llvm-commits
mailing list