Skip to content

Commit 2187df8

Browse files
committed
[InstCombine] Improve select equiv fold for float type
1 parent da2d545 commit 2187df8

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,11 +517,11 @@ static bool simplifySeqSelectWithSameCond(SelectInst &SI,
517517
Type *SelType = SINext->getType();
518518
Value *ValOp = SINext->getOperand(OpIndex);
519519
Value *CondNext;
520-
// Only support the type of select is an integer type as float type need
521-
// address FMF flag.
520+
// Don't need propagate FMF flag because we update the operand of SINext
521+
// directly.
522+
// It is not profitable to build a new select for SINext with multi-arms.
522523
while (match(ValOp, m_Select(m_Value(CondNext), m_Value(), m_Value()))) {
523-
if (CondNext == CondVal && SelType->isIntOrIntVectorTy() &&
524-
SINext->hasOneUse()) {
524+
if (CondNext == CondVal && SINext->hasOneUse()) {
525525
IC.replaceOperand(*SINext, OpIndex,
526526
cast<SelectInst>(ValOp)->getOperand(OpIndex));
527527
return true;

llvm/test/Transforms/InstCombine/select.ll

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4551,9 +4551,8 @@ define i32 @sequence_select_with_same_cond_true(i1 %c1, i1 %c2){
45514551

45524552
define double @sequence_select_with_same_cond_double(double %a, i1 %c1, i1 %c2, double %r1, double %r2){
45534553
; CHECK-LABEL: @sequence_select_with_same_cond_double(
4554-
; CHECK-NEXT: [[S1:%.*]] = select i1 [[C1:%.*]], double 1.000000e+00, double 0.000000e+00
4555-
; CHECK-NEXT: [[S2:%.*]] = select i1 [[C2:%.*]], double [[S1]], double 2.000000e+00
4556-
; CHECK-NEXT: [[S3:%.*]] = select i1 [[C1]], double [[S2]], double 3.000000e+00
4554+
; CHECK-NEXT: [[S2:%.*]] = select i1 [[C2:%.*]], double 1.000000e+00, double 2.000000e+00
4555+
; CHECK-NEXT: [[S3:%.*]] = select i1 [[C1:%.*]], double [[S2]], double 3.000000e+00
45574556
; CHECK-NEXT: ret double [[S3]]
45584557
;
45594558
%s1 = select i1 %c1, double 1.0, double 0.0
@@ -4565,9 +4564,8 @@ define double @sequence_select_with_same_cond_double(double %a, i1 %c1, i1 %c2,
45654564
; Confirm the FMF flag is propagated
45664565
define float @sequence_select_with_same_cond_float_and_fmf_flag1(i1 %c1, i1 %c2){
45674566
; CHECK-LABEL: @sequence_select_with_same_cond_float_and_fmf_flag1(
4568-
; CHECK-NEXT: [[S1:%.*]] = select i1 [[C1:%.*]], float 2.300000e+01, float 4.500000e+01
4569-
; CHECK-NEXT: [[S2:%.*]] = select fast i1 [[C2:%.*]], float 6.660000e+02, float [[S1]]
4570-
; CHECK-NEXT: [[S3:%.*]] = select fast i1 [[C1]], float 7.890000e+02, float [[S2]]
4567+
; CHECK-NEXT: [[S2:%.*]] = select fast i1 [[C2:%.*]], float 6.660000e+02, float 4.500000e+01
4568+
; CHECK-NEXT: [[S3:%.*]] = select fast i1 [[C1:%.*]], float 7.890000e+02, float [[S2]]
45714569
; CHECK-NEXT: ret float [[S3]]
45724570
;
45734571
%s1 = select i1 %c1, float 23.0, float 45.0
@@ -4578,9 +4576,8 @@ define float @sequence_select_with_same_cond_float_and_fmf_flag1(i1 %c1, i1 %c2)
45784576

45794577
define float @sequence_select_with_same_cond_float_and_fmf_flag2(i1 %c1, i1 %c2){
45804578
; CHECK-LABEL: @sequence_select_with_same_cond_float_and_fmf_flag2(
4581-
; CHECK-NEXT: [[S1:%.*]] = select fast i1 [[C1:%.*]], float 2.300000e+01, float 4.500000e+01
4582-
; CHECK-NEXT: [[S2:%.*]] = select i1 [[C2:%.*]], float 6.660000e+02, float [[S1]]
4583-
; CHECK-NEXT: [[S3:%.*]] = select fast i1 [[C1]], float 7.890000e+02, float [[S2]]
4579+
; CHECK-NEXT: [[S2:%.*]] = select i1 [[C2:%.*]], float 6.660000e+02, float 4.500000e+01
4580+
; CHECK-NEXT: [[S3:%.*]] = select fast i1 [[C1:%.*]], float 7.890000e+02, float [[S2]]
45844581
; CHECK-NEXT: ret float [[S3]]
45854582
;
45864583
%s1 = select fast i1 %c1, float 23.0, float 45.0

0 commit comments

Comments
 (0)