Skip to content

Commit 05488f6

Browse files
committed
Remove restriction on indvar phis, erase PHI if unused, fix mangled comment
1 parent 910dc9f commit 05488f6

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

llvm/lib/Target/RISCV/RISCVCodeGenPrepare.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,16 @@ bool RISCVCodeGenPrepare::visitAnd(BinaryOperator &BO) {
120120
// vectorize any scalar phis that feed into a fadd reduction:
121121
//
122122
// loop:
123-
// %phi = phi <float> [ ..., %entry ], [ %acc, %loop]
124-
// %acc = call float @llvm.vector.reduce.fadd.nxv4f32(float %phi, <vscale x 2 x
125-
// float> %vec)
123+
// %phi = phi <float> [ ..., %entry ], [ %acc, %loop ]
124+
// %acc = call float @llvm.vector.reduce.fadd.nxv4f32(float %phi, <vscale x 2 x float> %vec)
126125
//
127126
// ->
128127
//
129128
// loop:
130-
// %phi = phi <vscale x 2 x float> [ ..., %entry ], [ %acc.vec, %loop]
129+
// %phi = phi <vscale x 2 x float> [ ..., %entry ], [ %acc.vec, %loop ]
131130
// %phi.scalar = extractelement <vscale x 2 x float> %phi, i64 0
132-
// %acc = call float @llvm.vector.reduce.fadd.nxv4f32(float %x, <vscale x 2 x
133-
// float> %vec) %acc.vec = insertelement <vscale x 2 x float> poison, float
134-
// %acc.next, i64 0
131+
// %acc = call float @llvm.vector.reduce.fadd.nxv4f32(float %x, <vscale x 2 x float> %vec)
132+
// %acc.vec = insertelement <vscale x 2 x float> poison, float %acc.next, i64 0
135133
//
136134
// Which eliminates the scalar -> vector -> scalar crossing during instruction
137135
// selection.
@@ -140,7 +138,7 @@ bool RISCVCodeGenPrepare::visitIntrinsicInst(IntrinsicInst &I) {
140138
return false;
141139

142140
auto *PHI = dyn_cast<PHINode>(I.getOperand(0));
143-
if (!PHI || !llvm::is_contained(PHI->incoming_values(), &I))
141+
if (!PHI)
144142
return false;
145143

146144
Type *VecTy = I.getOperand(1)->getType();
@@ -157,6 +155,9 @@ bool RISCVCodeGenPrepare::visitIntrinsicInst(IntrinsicInst &I) {
157155
Builder.SetInsertPoint(&I);
158156
I.setOperand(0, Builder.CreateExtractElement(VecPHI, (uint64_t)0));
159157

158+
if (PHI->hasNUses(0))
159+
PHI->eraseFromParent();
160+
160161
return true;
161162
}
162163

llvm/test/CodeGen/RISCV/rvv/riscv-codegenprepare.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,10 @@ define float @reduce_fadd(ptr nocapture noundef readonly %f, i32 noundef signext
2626
; CHECK: vector.body:
2727
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
2828
; CHECK-NEXT: [[TMP5:%.*]] = phi <vscale x 4 x float> [ insertelement (<vscale x 4 x float> poison, float 0.000000e+00, i64 0), [[VECTOR_PH]] ], [ [[TMP10:%.*]], [[VECTOR_BODY]] ]
29-
; CHECK-NEXT: [[VEC_PHI:%.*]] = phi float [ 0.000000e+00, [[VECTOR_PH]] ], [ [[TMP8:%.*]], [[VECTOR_BODY]] ]
3029
; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds float, ptr [[F]], i64 [[INDEX]]
3130
; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 4 x float>, ptr [[TMP6]], align 4
3231
; CHECK-NEXT: [[TMP7:%.*]] = extractelement <vscale x 4 x float> [[TMP5]], i64 0
33-
; CHECK-NEXT: [[TMP8]] = tail call float @llvm.vector.reduce.fadd.nxv4f32(float [[TMP7]], <vscale x 4 x float> [[WIDE_LOAD]])
32+
; CHECK-NEXT: [[TMP8:%.*]] = tail call float @llvm.vector.reduce.fadd.nxv4f32(float [[TMP7]], <vscale x 4 x float> [[WIDE_LOAD]])
3433
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP4]]
3534
; CHECK-NEXT: [[TMP9:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
3635
; CHECK-NEXT: [[TMP10]] = insertelement <vscale x 4 x float> poison, float [[TMP8]], i64 0

0 commit comments

Comments
 (0)