llvm.org GIT mirror llvm / fb42ed2
[AlignmentFromAssumptions] Don't divide by zero for unknown starting alignment The routine that determines an alignment given some SCEV returns zero if the answer is unknown. In a case where we could determine the increment of an AddRec but not the starting alignment, we would compute the integer modulus by zero (which is illegal and traps). Prevent this by returning early if either the start or increment alignment is unknown (zero). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217544 91177308-0d34-0410-b5e6-96231b3b80d8 Hal Finkel 5 years ago
2 changed file(s) with 158 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
178178 DEBUG(dbgs() << "\tnew start alignment: " << NewAlignment << "\n");
179179 DEBUG(dbgs() << "\tnew inc alignment: " << NewIncAlignment << "\n");
180180
181 if (NewAlignment > NewIncAlignment) {
181 if (!NewAlignment || !NewIncAlignment) {
182 return 0;
183 } else if (NewAlignment > NewIncAlignment) {
182184 if (NewAlignment % NewIncAlignment == 0) {
183185 DEBUG(dbgs() << "\tnew start/inc alignment: " <<
184186 NewIncAlignment << "\n");
190192 NewAlignment << "\n");
191193 return NewAlignment;
192194 }
193 } else if (NewIncAlignment == NewAlignment && NewIncAlignment) {
195 } else if (NewIncAlignment == NewAlignment) {
194196 DEBUG(dbgs() << "\tnew start/inc alignment: " <<
195197 NewAlignment << "\n");
196198 return NewAlignment;
0 ; RUN: opt -alignment-from-assumptions -S < %s | FileCheck %s
1 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
2 target triple = "x86_64-unknown-linux-gnu"
3
4 %type1 = type { %type2 }
5 %type2 = type { [4 x i8] }
6
7 ; Function Attrs: nounwind
8 declare void @llvm.assume(i1) #0
9
10 ; Function Attrs: nounwind readnone
11 declare i32 @llvm.bswap.i32(i32) #1
12
13 ; Function Attrs: nounwind uwtable
14 define void @test1() unnamed_addr #2 align 2 {
15
16 ; CHECK-LABEL: @test1
17
18 entry:
19 br i1 undef, label %if.then, label %if.end
20
21 if.then: ; preds = %entry
22 unreachable
23
24 if.end: ; preds = %entry
25 br i1 undef, label %return, label %if.end8
26
27 if.end8: ; preds = %if.end
28 br i1 undef, label %if.then13, label %if.end14
29
30 if.then13: ; preds = %if.end8
31 unreachable
32
33 if.end14: ; preds = %if.end8
34 br i1 undef, label %cond.false.i129, label %cond.end.i136
35
36 cond.false.i129: ; preds = %if.end14
37 unreachable
38
39 cond.end.i136: ; preds = %if.end14
40 br i1 undef, label %land.lhs.true.i, label %if.end.i145
41
42 land.lhs.true.i: ; preds = %cond.end.i136
43 br i1 undef, label %if.end.i145, label %if.then.i137
44
45 if.then.i137: ; preds = %land.lhs.true.i
46 br i1 undef, label %cond.false8.i, label %cond.end9.i
47
48 cond.false8.i: ; preds = %if.then.i137
49 unreachable
50
51 cond.end9.i: ; preds = %if.then.i137
52 br i1 undef, label %if.then23, label %if.end24
53
54 if.end.i145: ; preds = %land.lhs.true.i, %cond.end.i136
55 unreachable
56
57 if.then23: ; preds = %cond.end9.i
58 unreachable
59
60 if.end24: ; preds = %cond.end9.i
61 br i1 undef, label %for.end, label %for.body.lr.ph
62
63 for.body.lr.ph: ; preds = %if.end24
64 unreachable
65
66 for.end: ; preds = %if.end24
67 br i1 undef, label %if.end123, label %if.then121
68
69 if.then121: ; preds = %for.end
70 unreachable
71
72 if.end123: ; preds = %for.end
73 br i1 undef, label %if.end150, label %if.then126
74
75 if.then126: ; preds = %if.end123
76 %ptrint.i.i185 = ptrtoint %type1* undef to i64
77 %maskedptr.i.i186 = and i64 %ptrint.i.i185, 1
78 %maskcond.i.i187 = icmp eq i64 %maskedptr.i.i186, 0
79 tail call void @llvm.assume(i1 %maskcond.i.i187) #0
80 %ret.0..sroa_cast.i.i188 = bitcast %type1* undef to i32*
81 %ret.0.copyload.i.i189 = load i32* %ret.0..sroa_cast.i.i188, align 2
82
83 ; CHECK: load {{.*}} align 2
84
85 %0 = tail call i32 @llvm.bswap.i32(i32 %ret.0.copyload.i.i189) #0
86 %conv131 = zext i32 %0 to i64
87 %add.ptr132 = getelementptr inbounds i8* undef, i64 %conv131
88 %1 = bitcast i8* %add.ptr132 to %type1*
89 br i1 undef, label %if.end150, label %if.end.i173
90
91 if.end.i173: ; preds = %if.then126
92 br i1 undef, label %test1.exit, label %cond.false.i.i.i.i174
93
94 cond.false.i.i.i.i174: ; preds = %if.end.i173
95 unreachable
96
97 test1.exit: ; preds = %if.end.i173
98 br i1 undef, label %test1a.exit, label %if.end.i124
99
100 if.end.i124: ; preds = %test1.exit
101 unreachable
102
103 test1a.exit: ; preds = %test1.exit
104 br i1 undef, label %if.end150, label %for.body137.lr.ph
105
106 for.body137.lr.ph: ; preds = %test1a.exit
107 br label %for.body137
108
109 for.body137: ; preds = %test1b.exit, %for.body137.lr.ph
110 %ShndxTable.0309 = phi %type1* [ %1, %for.body137.lr.ph ], [ %incdec.ptr, %test1b.exit ]
111 %ret.0..sroa_cast.i.i106 = bitcast %type1* %ShndxTable.0309 to i32*
112 br i1 undef, label %for.body137.if.end146_crit_edge, label %if.then140
113
114 for.body137.if.end146_crit_edge: ; preds = %for.body137
115 %incdec.ptr = getelementptr inbounds %type1* %ShndxTable.0309, i64 1
116 br i1 undef, label %cond.false.i70, label %cond.end.i
117
118 if.then140: ; preds = %for.body137
119 %ret.0.copyload.i.i102 = load i32* %ret.0..sroa_cast.i.i106, align 2
120
121 ; CHECK: load {{.*}} align 2
122
123 unreachable
124
125 cond.false.i70: ; preds = %for.body137.if.end146_crit_edge
126 unreachable
127
128 cond.end.i: ; preds = %for.body137.if.end146_crit_edge
129 br i1 undef, label %test1b.exit, label %cond.false.i.i
130
131 cond.false.i.i: ; preds = %cond.end.i
132 unreachable
133
134 test1b.exit: ; preds = %cond.end.i
135 br i1 undef, label %if.end150, label %for.body137
136
137 if.end150: ; preds = %test1b.exit, %test1a.exit, %if.then126, %if.end123
138 br i1 undef, label %for.end176, label %for.body155.lr.ph
139
140 for.body155.lr.ph: ; preds = %if.end150
141 unreachable
142
143 for.end176: ; preds = %if.end150
144 unreachable
145
146 return: ; preds = %if.end
147 ret void
148 }
149
150 attributes #0 = { nounwind }
151 attributes #1 = { nounwind readnone }
152 attributes #2 = { nounwind uwtable }
153