Skip to content

Commit e8be733

Browse files
committed
[VPlan] Remove redundant ExtractLastElement from vector-to-scalar VPI.
Recipes that are vector-to-scalar are guaranteed to generate a scalar value, so the extract is redundant after VPlan unrolling. Remove it. This removes unneeded ExtractLastElement VPInstruction of reduction result computations.
1 parent 1b83f10 commit e8be733

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ inline match_combine_and<LTy, RTy> m_CombineAnd(const LTy &L, const RTy &R) {
192192
/// Match a VPValue, capturing it if we match.
193193
inline bind_ty<VPValue> m_VPValue(VPValue *&V) { return V; }
194194

195+
/// Match a VPInstruction, capturing if we match.
196+
inline bind_ty<VPInstruction> m_VPInstruction(VPInstruction *&V) { return V; }
197+
195198
template <typename Ops_t, unsigned Opcode, bool Commutative,
196199
typename... RecipeTys>
197200
struct Recipe_match {

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,14 @@ static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
11631163
});
11641164
return;
11651165
}
1166+
1167+
VPInstruction *OpVPI;
1168+
if (match(Def, m_VPInstruction<VPInstruction::ExtractLastElement>(
1169+
m_VPInstruction(OpVPI))) &&
1170+
OpVPI->isVectorToScalar()) {
1171+
Def->replaceAllUsesWith(OpVPI);
1172+
return;
1173+
}
11661174
}
11671175

11681176
void VPlanTransforms::simplifyRecipes(VPlan &Plan, Type &CanonicalIVTy) {

llvm/test/Transforms/LoopVectorize/AArch64/vplan-printing.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,12 @@ define i32 @print_partial_reduction(ptr %a, ptr %b) {
106106
; CHECK-EMPTY:
107107
; CHECK-NEXT: middle.block:
108108
; CHECK-NEXT: EMIT vp<[[RED_RESULT:%.+]]> = compute-reduction-result ir<%accum>, ir<%add>
109-
; CHECK-NEXT: EMIT vp<[[EXTRACT:%.+]]> = extract-last-element vp<[[RED_RESULT]]>
110109
; CHECK-NEXT: EMIT vp<[[CMP:%.+]]> = icmp eq ir<1024>, ir<1024>
111110
; CHECK-NEXT: EMIT branch-on-cond vp<[[CMP]]>
112111
; CHECK-NEXT: Successor(s): ir-bb<exit>, ir-bb<scalar.ph>
113112
; CHECK-EMPTY:
114113
; CHECK-NEXT: ir-bb<exit>:
115-
; CHECK-NEXT: IR %add.lcssa = phi i32 [ %add, %for.body ] (extra operand: vp<[[EXTRACT]]> from middle.block)
114+
; CHECK-NEXT: IR %add.lcssa = phi i32 [ %add, %for.body ] (extra operand: vp<[[RED_RESULT]]> from middle.block)
116115
; CHECK-NEXT: No successors
117116
; CHECK-EMPTY:
118117
; CHECK-NEXT: ir-bb<scalar.ph>:

0 commit comments

Comments
 (0)