[PATCH] D78115: [LV] Fix PR45525: Incorrect assert in blend recipe

Gil Rapaport via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 15 00:30:16 PDT 2020


gilr updated this revision to Diff 257611.
gilr retitled this revision from "[LV] Fix PR45525" to "[LV] Fix PR45525: Incorrect assert in blend recipe".
gilr added a comment.

Addressed comments and narrowed LIT checks to the relevant vectorized instructions.
Thanks @fhahn !


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78115/new/

https://reviews.llvm.org/D78115

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/lib/Transforms/Vectorize/VPlan.h
  llvm/test/Transforms/LoopVectorize/pr45525.ll


Index: llvm/test/Transforms/LoopVectorize/pr45525.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopVectorize/pr45525.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -loop-vectorize -force-vector-width=4 -S | FileCheck %s
+
+; Test case for PR45525. Checks that phi's with a single predecessor and a mask are supported.
+
+define void @main(i1 %cond, i32* %arr) {
+; CHECK-LABEL: @main(
+; CHECK-NEXT:  bb.0:
+; CHECK-NEXT:    br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
+; CHECK:       vector.ph:
+; CHECK:         br label [[VECTOR_BODY:%.*]]
+; CHECK:       vector.body:
+; CHECK:         [[VEC_IND:%.*]] = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
+; CHECK:         [[TMP5:%.*]] = mul <4 x i32> [[VEC_IND]], <i32 3, i32 3, i32 3, i32 3>
+;
+bb.0:
+  br label %bb.1
+
+bb.1:                                             ; preds = %bb.3, %bb.0
+  %iv = phi i32 [ 0, %bb.0 ], [ %iv.next, %bb.3 ]
+  br i1 %cond, label %bb.3, label %bb.2
+
+bb.2:                                             ; preds = %bb.1
+  %single.pred = phi i32 [ %iv, %bb.1 ]
+  %mult = mul i32 %single.pred, 3
+  br label %bb.3
+
+bb.3:                                             ; preds = %bb.2, %bb.1
+  %stored.value = phi i32 [ 7, %bb.1 ], [ %mult, %bb.2 ]
+  %arrayidx = getelementptr inbounds i32, i32* %arr, i32 %iv
+  store i32 %stored.value, i32* %arrayidx
+  %iv.next = add i32 %iv, 1
+  %continue = icmp ult i32 %iv.next, 32
+  br i1 %continue, label %bb.1, label %bb.4
+
+bb.4:                                             ; preds = %bb.3
+  ret void
+}
Index: llvm/lib/Transforms/Vectorize/VPlan.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.h
+++ llvm/lib/Transforms/Vectorize/VPlan.h
@@ -929,16 +929,16 @@
 
   /// The blend operation is a User of the incoming values and of their
   /// respective masks, ordered [I0, M0, I1, M1, ...]. Note that a single value
-  /// would be incoming with a full mask for which there is no VPValue.
+  /// might be incoming with a full mask for which there is no VPValue.
   VPUser User;
 
 public:
   VPBlendRecipe(PHINode *Phi, ArrayRef<VPValue *> Operands)
       : VPRecipeBase(VPBlendSC), Phi(Phi), User(Operands) {
-    assert(((Operands.size() == 1) ||
-            (Operands.size() > 2 && Operands.size() % 2 == 0)) &&
-           "Expected either a single incoming value or a greater than two and "
-           "even number of operands");
+    assert(Operands.size() > 0 &&
+           ((Operands.size() == 1) || (Operands.size() % 2 == 0)) &&
+           "Expected either a single incoming value or a positive even number "
+           "of operands");
   }
 
   /// Method to support type inquiry through isa, cast, and dyn_cast.
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7463,8 +7463,11 @@
 
   // Generate a sequence of selects of the form:
   // SELECT(Mask3, In3,
-  //      SELECT(Mask2, In2,
-  //                   ( ...)))
+  //        SELECT(Mask2, In2,
+  //               SELECT(Mask1, In1,
+  //                      In0)))
+  // Note that Mask0 is never used: lanes for which no path reaches this phi and
+  // are essentially undef are taken from In0.
   InnerLoopVectorizer::VectorParts Entry(State.UF);
   for (unsigned In = 0; In < NumIncoming; ++In) {
     for (unsigned Part = 0; Part < State.UF; ++Part) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78115.257611.patch
Type: text/x-patch
Size: 3646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200415/9de275dd/attachment-0001.bin>


More information about the llvm-commits mailing list