Skip to content

Commit abd849e

Browse files
committed
[InstCombine] Fold its select user into select for float type
The pattern matcher checks the operand of the select is also a select instruction, so the condition and the selection type must be both scalar nor both vector types.
1 parent 248a354 commit abd849e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -515,20 +515,17 @@ static bool simplifySeqSelectWithSameCond(SelectInst &SI,
515515
Value *RepOp = OpIndex == 1 ? ConstantInt::getTrue(CondType)
516516
: ConstantInt::getFalse(CondType);
517517
SelectInst *SINext = &SI;
518-
Type *SelType = SINext->getType();
519518
Value *ValOp = SINext->getOperand(OpIndex);
520519
Value *CondNext;
521520
while (match(ValOp, m_Select(m_Value(CondNext), m_Value(), m_Value()))) {
522-
if (CondNext == CondVal && SelType->isIntOrIntVectorTy() &&
523-
CondType->isVectorTy() == SelType->isVectorTy())
521+
if (CondNext == CondVal)
524522
if (Value *S = simplifyWithOpReplaced(ValOp, CondVal, RepOp, SQ,
525523
/* AllowRefinement */ true)) {
526524
IC.replaceOperand(*SINext, OpIndex, S);
527525
return true;
528526
}
529527

530528
SINext = cast<SelectInst>(ValOp);
531-
SelType = SINext->getType();
532529
ValOp = SINext->getOperand(OpIndex);
533530
}
534531
return false;

llvm/test/Transforms/InstCombine/select.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3734,6 +3734,21 @@ define i32 @sequence_select_with_same_cond_true (i1 %c1, i1 %c2){
37343734
ret i32 %s3
37353735
}
37363736

3737+
; https://alive2.llvm.org/ce/z/3Uaiis
3738+
define double @sequence_select_with_same_cond_double(double %a, i1 %c1, i1 %c2, double %r1, double %r2){
3739+
; CHECK-LABEL: @sequence_select_with_same_cond_double(
3740+
; CHECK-NEXT: entry:
3741+
; CHECK-NEXT: [[S2:%.*]] = select i1 [[C2:%.*]], double 1.000000e+00, double 2.000000e+00
3742+
; CHECK-NEXT: [[S3:%.*]] = select i1 [[C1:%.*]], double [[S2]], double 3.000000e+00
3743+
; CHECK-NEXT: ret double [[S3]]
3744+
;
3745+
entry:
3746+
%s1 = select i1 %c1, double 1.0, double 0.0
3747+
%s2 = select i1 %c2, double %s1, double 2.0
3748+
%s3 = select i1 %c1, double %s2, double 3.0
3749+
ret double %s3
3750+
}
3751+
37373752
declare void @use32(i32)
37383753

37393754
define i32 @sequence_select_with_same_cond_extra_use (i1 %c1, i1 %c2){

0 commit comments

Comments
 (0)