Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 222b8be

Browse files
committed
[LV] Fix for PR38110, LV encountered llvm_unreachable()
Summary: truncateToMinimalBitWidths() doesn't handle all Instructions and the worst case is compiler crash via llvm_unreachable(). Fix is to add a case to handle PHINode and changed the worst case to NO-OP (from compiler crash). Reviewers: sbaranga, mssimpso, hsaito Reviewed By: hsaito Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D49461 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337861 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 78dd298 commit 222b8be

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3276,7 +3276,7 @@ void InnerLoopVectorizer::truncateToMinimalBitwidths() {
32763276
SI->getOperand(1), VectorType::get(ScalarTruncatedTy, Elements1));
32773277

32783278
NewI = B.CreateShuffleVector(O0, O1, SI->getMask());
3279-
} else if (isa<LoadInst>(I)) {
3279+
} else if (isa<LoadInst>(I) || isa<PHINode>(I)) {
32803280
// Don't do anything with the operands, just extend the result.
32813281
continue;
32823282
} else if (auto *IE = dyn_cast<InsertElementInst>(I)) {
@@ -3291,7 +3291,8 @@ void InnerLoopVectorizer::truncateToMinimalBitwidths() {
32913291
EE->getOperand(0), VectorType::get(ScalarTruncatedTy, Elements));
32923292
NewI = B.CreateExtractElement(O0, EE->getOperand(2));
32933293
} else {
3294-
llvm_unreachable("Unhandled instruction type!");
3294+
// If we don't know what to do, be conservative and don't do anything.
3295+
continue;
32953296
}
32963297

32973298
// Lastly, extend the result.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
; RUN: opt -passes='loop-vectorize' -mcpu=z13 -force-vector-width=2 -S < %s | FileCheck %s
2+
;
3+
; Forcing VF=2 to trigger vector code gen
4+
;
5+
; This is a test case to exercise more cases in truncateToMinimalBitWidths().
6+
; Test passes if vector code is generated w/o hitting llvm_unreachable().
7+
;
8+
; Performing minimal check in the output to ensure the loop is actually
9+
; vectorized.
10+
;
11+
; CHECK: vector.body
12+
13+
target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"
14+
target triple = "s390x-ibm-linux"
15+
16+
define void @test(i32 zeroext %width, i8* nocapture %row, i16 zeroext %src, i16* nocapture readonly %dst) {
17+
entry:
18+
%cmp10 = icmp eq i32 %width, 0
19+
br i1 %cmp10, label %for.end, label %for.body.lr.ph
20+
21+
for.body.lr.ph: ; preds = %entry
22+
%conv1 = zext i16 %src to i32
23+
br label %for.body
24+
25+
for.body: ; preds = %for.inc, %for.body.lr.ph
26+
%i.012 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
27+
%sp.011 = phi i8* [ %row, %for.body.lr.ph ], [ %incdec.ptr, %for.inc ]
28+
%0 = load i8, i8* %sp.011, align 1
29+
%conv = zext i8 %0 to i32
30+
%cmp2 = icmp eq i32 %conv, %conv1
31+
br i1 %cmp2, label %if.then, label %for.inc
32+
33+
if.then: ; preds = %for.body
34+
%1 = load i16, i16* %dst, align 2
35+
%conv4 = trunc i16 %1 to i8
36+
store i8 %conv4, i8* %sp.011, align 1
37+
br label %for.inc
38+
39+
for.inc: ; preds = %for.body, %if.then
40+
%inc = add nuw i32 %i.012, 1
41+
%incdec.ptr = getelementptr inbounds i8, i8* %sp.011, i64 1
42+
%exitcond = icmp eq i32 %inc, %width
43+
br i1 %exitcond, label %for.end.loopexit, label %for.body
44+
45+
for.end.loopexit: ; preds = %for.inc
46+
br label %for.end
47+
48+
for.end: ; preds = %for.end.loopexit, %entry
49+
ret void
50+
}

0 commit comments

Comments
 (0)