[llvm] dcc410b - [LoopVectorize] Fix crash on "getNoopOrZeroExtend cannot truncate!" (PR45259)
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 30 10:14:24 PDT 2020
Author: Vedant Kumar
Date: 2020-03-30T10:14:14-07:00
New Revision: dcc410b5cf202e354105df431fad62d2f5f7eac7
URL: https://github.com/llvm/llvm-project/commit/dcc410b5cf202e354105df431fad62d2f5f7eac7
DIFF: https://github.com/llvm/llvm-project/commit/dcc410b5cf202e354105df431fad62d2f5f7eac7.diff
LOG: [LoopVectorize] Fix crash on "getNoopOrZeroExtend cannot truncate!" (PR45259)
In InnerLoopVectorizer::getOrCreateTripCount, when the backedge taken
count is a SCEV add expression, its type is defined by the type of the
last operand of the add expression.
In the test case from PR45259, this last operand happens to be a
pointer, which (according to llvm::Type) does not have a primitive size
in bits. In this case, LoopVectorize fails to truncate the SCEV and
crashes as a result.
Uing ScalarEvolution::getTypeSizeInBits makes the truncation work as expected.
https://bugs.llvm.org/show_bug.cgi?id=45259
Differential Revision: https://reviews.llvm.org/D76669
Added:
llvm/test/Transforms/LoopVectorize/pr45259.ll
Modified:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 4648a4403d6c..3a89fd829384 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -2583,7 +2583,7 @@ Value *InnerLoopVectorizer::getOrCreateTripCount(Loop *L) {
// compare. The only way that we get a backedge taken count is that the
// induction variable was signed and as such will not overflow. In such a case
// truncation is legal.
- if (BackedgeTakenCount->getType()->getPrimitiveSizeInBits() >
+ if (SE->getTypeSizeInBits(BackedgeTakenCount->getType()) >
IdxTy->getPrimitiveSizeInBits())
BackedgeTakenCount = SE->getTruncateOrNoop(BackedgeTakenCount, IdxTy);
BackedgeTakenCount = SE->getNoopOrZeroExtend(BackedgeTakenCount, IdxTy);
diff --git a/llvm/test/Transforms/LoopVectorize/pr45259.ll b/llvm/test/Transforms/LoopVectorize/pr45259.ll
new file mode 100644
index 000000000000..3d1370b14a0f
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/pr45259.ll
@@ -0,0 +1,36 @@
+; RUN: opt < %s -S -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 | FileCheck %s
+
+; Check that we can vectorize this loop without crashing.
+
+; CHECK-LABEL: define {{.*}} @widget(
+; CHECK: [[vecInd:%.*]] = phi <4 x i8> [ <i8 0, i8 1, i8 2, i8 3>
+; CHECK-NEXT: add <4 x i8> [[vecInd]], <i8 1, i8 1, i8 1, i8 1>
+
+define i8 @widget(i8* %arr, i8 %t9) {
+bb:
+ br label %bb6
+
+bb6:
+ %t1.0 = phi i8* [ %arr, %bb ], [ null, %bb6 ]
+ %c = call i1 @cond()
+ br i1 %c, label %for.preheader, label %bb6
+
+for.preheader:
+ br label %for.body
+
+for.body:
+ %iv = phi i8 [ %iv.next, %for.body ], [ 0, %for.preheader ]
+ %iv.next = add i8 %iv, 1
+ %ptr = getelementptr inbounds i8, i8* %arr, i8 %iv.next
+ %t3.i = icmp slt i8 %iv.next, %t9
+ %t3.i8 = zext i1 %t3.i to i8
+ store i8 %t3.i8, i8* %ptr
+ %ec = icmp eq i8* %t1.0, %ptr
+ br i1 %ec, label %for.exit, label %for.body
+
+for.exit:
+ %iv.next.lcssa = phi i8 [ %iv.next, %for.body ]
+ ret i8 %iv.next.lcssa
+}
+
+declare i1 @cond()
More information about the llvm-commits
mailing list