Skip to content

Commit f5c0e6c

Browse files
committedMay 17, 2018
[SROA] pr37267: fix assertion failure in integer widening
The current integer widening does not support rewriting partial split slices in rewriteIntegerStore (and rewriteIntegerLoad). This patch adds explicit checks for this case in isIntegerWideningViableForSlice. Before r322533, splitting is allowed only for the whole-alloca slice and hence the above case is implicitly rejected by another check `if (DL.getTypeStoreSize(ValueTy) > Size)` because whole-alloca slice is larger than the partition. Differential Revision: https://reviews.llvm.org/D46750 llvm-svn: 332575
1 parent cea6db0 commit f5c0e6c

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
 

‎llvm/lib/Transforms/Scalar/SROA.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -1968,6 +1968,10 @@ static bool isIntegerWideningViableForSlice(const Slice &S,
19681968
// We can't handle loads that extend past the allocated memory.
19691969
if (DL.getTypeStoreSize(LI->getType()) > Size)
19701970
return false;
1971+
// So far, AllocaSliceRewriter does not support widening split slice tails
1972+
// in rewriteIntegerLoad.
1973+
if (S.beginOffset() < AllocBeginOffset)
1974+
return false;
19711975
// Note that we don't count vector loads or stores as whole-alloca
19721976
// operations which enable integer widening because we would prefer to use
19731977
// vector widening instead.
@@ -1989,6 +1993,10 @@ static bool isIntegerWideningViableForSlice(const Slice &S,
19891993
// We can't handle stores that extend past the allocated memory.
19901994
if (DL.getTypeStoreSize(ValueTy) > Size)
19911995
return false;
1996+
// So far, AllocaSliceRewriter does not support widening split slice tails
1997+
// in rewriteIntegerStore.
1998+
if (S.beginOffset() < AllocBeginOffset)
1999+
return false;
19922000
// Note that we don't count vector loads or stores as whole-alloca
19932001
// operations which enable integer widening because we would prefer to use
19942002
// vector widening instead.

‎llvm/test/Transforms/SROA/pr37267.ll

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
; RUN: opt < %s -sroa -S | FileCheck %s
2+
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-n32:64-S128"
3+
target triple = "sparcv9-sun-solaris"
4+
5+
; PR37267
6+
; Check that we don't crash on this test.
7+
8+
define i16 @f1() {
9+
; CHECK-LABEL: @f1
10+
; CHECK: %[[retval:.*]] = add i16 2, 2
11+
; CHECK: ret i16 %[[retval]]
12+
13+
bb1:
14+
; This 12-byte alloca is split into partitions as [0,2), [2,4), [4,8), [8,10), [10, 12).
15+
; The reported error happened when rewriteIntegerStore try to widen a split tail of slice 1 for [4, 8) partition.
16+
; alloca 012345678901
17+
; slice 1: WWWW
18+
; slice 2: WWWW
19+
; slice 3: RR
20+
; slice 4: RR
21+
22+
%a.3 = alloca [6 x i16], align 1
23+
; slice 1: [2,6)
24+
%_tmp3 = getelementptr inbounds [6 x i16], [6 x i16]* %a.3, i16 0, i16 1
25+
%_tmp5 = bitcast i16* %_tmp3 to i32*
26+
store i32 131074, i32* %_tmp5, align 1
27+
; slice 2: [8,12)
28+
%_tmp8 = getelementptr inbounds [6 x i16], [6 x i16]* %a.3, i16 0, i16 4
29+
%_tmp10 = bitcast i16* %_tmp8 to i32*
30+
store i32 131074, i32* %_tmp10, align 1
31+
; slice 3: [8,10)
32+
%_tmp12 = getelementptr inbounds [6 x i16], [6 x i16]* %a.3, i16 0, i16 4
33+
%_tmp13 = load i16, i16* %_tmp12, align 1
34+
; slice 4: [2,4)
35+
%_tmp15 = getelementptr inbounds [6 x i16], [6 x i16]* %a.3, i16 0, i16 1
36+
%_tmp16 = load i16, i16* %_tmp15, align 1
37+
38+
%rc = add i16 %_tmp13, %_tmp16
39+
ret i16 %rc
40+
}
41+
42+
define i16 @f2() {
43+
; CHECK-LABEL: @f2
44+
; CHECK: %[[retval:.*]] = add i16 2, undef
45+
; CHECK: ret i16 %[[retval]]
46+
47+
bb1:
48+
; This 12-byte alloca is split into partitions as [0,2), [2,4), [4,8), [8,10), [10, 12).
49+
; The reported error happened when visitLoadInst rewrites a split tail of slice 1 for [4, 8) partition.
50+
; alloca 012345678901
51+
; slice 1: RRRR
52+
; slice 2: WWWW
53+
; slice 3: RR
54+
; slice 4: RR
55+
56+
%a.3 = alloca [6 x i16], align 1
57+
; slice 1: [2,6)
58+
%_tmp3 = getelementptr inbounds [6 x i16], [6 x i16]* %a.3, i16 0, i16 1
59+
%_tmp5 = bitcast i16* %_tmp3 to i32*
60+
%_tmp6 = load i32, i32* %_tmp5, align 1
61+
; slice 2: [8,12)
62+
%_tmp8 = getelementptr inbounds [6 x i16], [6 x i16]* %a.3, i16 0, i16 4
63+
%_tmp10 = bitcast i16* %_tmp8 to i32*
64+
store i32 131074, i32* %_tmp10, align 1
65+
; slice 3: [8,10)
66+
%_tmp12 = getelementptr inbounds [6 x i16], [6 x i16]* %a.3, i16 0, i16 4
67+
%_tmp13 = load i16, i16* %_tmp12, align 1
68+
; slice 4: [2,4)
69+
%_tmp15 = getelementptr inbounds [6 x i16], [6 x i16]* %a.3, i16 0, i16 1
70+
%_tmp16 = load i16, i16* %_tmp15, align 1
71+
72+
%rc = add i16 %_tmp13, %_tmp16
73+
ret i16 %rc
74+
}

0 commit comments

Comments
 (0)
Please sign in to comment.