[PATCH] D101260: [LoopVectorize][SVE] Remove assert for scalable vector in InnerLoopVectorizer::fixReduction

Caroline via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 25 10:29:29 PDT 2021


CarolineConcatto created this revision.
Herald added subscribers: psnobl, hiraditya, tschuett.
Herald added a reviewer: efriedma.
CarolineConcatto requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The function fixReduction used to assert/crash for scalable vector when
a vector reduce could be done with a smaller vector.
This patch removes this assertion as it is safe to use scalable vector for
vector reduce and truncate.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101260

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Transforms/LoopVectorize/sve-reduction-inloop.ll


Index: llvm/test/Transforms/LoopVectorize/sve-reduction-inloop.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopVectorize/sve-reduction-inloop.ll
@@ -0,0 +1,47 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -loop-vectorize -mtriple aarch64-unknown-linux-gnu -mattr=+sve  -S | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+define i8 @reduction_add_trunc(i8* noalias nocapture %A) {
+; CHECK-LABEL: @reduction_add_trunc(
+; CHECK: vector.body:
+; CHECK:  %[[MUL:.*]] = mul i32 %{{.*}}, 16
+; CHECK-NEXT:  %[[INDEXNEXT:.*]] = add i32 %index, %[[MUL]]
+; CHECK-NEXT:  %[[ICMP1:.*]] = icmp eq i32 %[[INDEXNEXT]], %{{.*}}
+; CHECK-NEXT:  %[[TRUNC1:.*]] = trunc <vscale x 8 x i32> %{{.*}} to <vscale x 8 x i8>
+; CHECK-NEXT:  %[[ZEXT1:.*]] = zext <vscale x 8 x i8> %[[TRUNC1]] to <vscale x 8 x i32>
+; CHECK-NEXT:  %[[TRUNC2:.*]] = trunc <vscale x 8 x i32> %{{.*}} to <vscale x 8 x i8>
+; CHECK-NEXT:  %[[ZEXT2:.*]] = zext <vscale x 8 x i8> %[[TRUNC2]] to <vscale x 8 x i32>
+; CHECK: middle.block:
+; CHECK-NEXT:  %[[TRUNC3:.*]] = trunc <vscale x 8 x i32> %[[ZEXT1]] to <vscale x 8 x i8>
+; CHECK-NEXT:  %[[TRUNC4:.*]] = trunc <vscale x 8 x i32> %[[ZEXT2]] to <vscale x 8 x i8>
+; CHECK-NEXT:  %[[BINRDX:.*]] = add <vscale x 8 x i8> %[[TRUNC4]], %[[TRUNC3]]
+; CHECK-NEXT:  %[[REDUCEADD:.*]] = call i8 @llvm.vector.reduce.add.nxv8i8(<vscale x 8 x i8> %[[BINRDX]])
+;
+entry:
+  br label %.lr.ph
+
+.lr.ph:                                           ; preds = %entry, %.lr.ph
+  %indvars.iv = phi i32 [ %indvars.iv.next, %.lr.ph ], [ 0, %entry ]
+  %sum.02p = phi i32 [ %l9, %.lr.ph ], [ 255, %entry ]
+  %sum.02 = and i32 %sum.02p, 255
+  %l2 = getelementptr inbounds i8, i8* %A, i32 %indvars.iv
+  %l3 = load i8, i8* %l2, align 4
+  %l3e = zext i8 %l3 to i32
+  %l9 = add i32 %sum.02, %l3e
+  %indvars.iv.next = add i32 %indvars.iv, 1
+  %exitcond = icmp eq i32 %indvars.iv.next, 256
+  br i1 %exitcond, label %._crit_edge, label %.lr.ph, !llvm.loop !0
+
+._crit_edge:                                      ; preds = %.lr.ph
+  %sum.0.lcssa = phi i32 [ %l9, %.lr.ph ]
+  %ret = trunc i32 %sum.0.lcssa to i8
+  ret i8 %ret
+}
+
+!0 = distinct !{!0, !1, !2, !3, !4}
+!1 = !{!"llvm.loop.vectorize.width", i32 8}
+!2 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
+!3 = !{!"llvm.loop.interleave.count", i32 2}
+!4 = !{!"llvm.loop.vectorize.enable", i1 true}
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4350,7 +4350,6 @@
   // entire expression in the smaller type.
   if (VF.isVector() && PhiTy != RdxDesc.getRecurrenceType()) {
     assert(!IsInLoopReductionPhi && "Unexpected truncated inloop reduction!");
-    assert(!VF.isScalable() && "scalable vectors not yet supported.");
     Type *RdxVecTy = VectorType::get(RdxDesc.getRecurrenceType(), VF);
     Builder.SetInsertPoint(
         LI->getLoopFor(LoopVectorBody)->getLoopLatch()->getTerminator());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101260.340369.patch
Type: text/x-patch
Size: 3293 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210425/9d8b1af0/attachment.bin>


More information about the llvm-commits mailing list