llvm.org GIT mirror llvm / 2ec0cda
Avoid folding loads that are unsafe to move. LiveRangeEdit::foldAsLoad() can eliminate a register by folding a load into its only use. Only do that when the load is safe to move, and it won't extend any live ranges. This fixes PR13414. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160575 91177308-0d34-0410-b5e6-96231b3b80d8 Jakob Stoklund Olesen 7 years ago
2 changed file(s) with 156 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
176176 if (!DefMI || !UseMI)
177177 return false;
178178
179 // Since we're moving the DefMI load, make sure we're not extending any live
180 // ranges.
181 if (!allUsesAvailableAt(DefMI,
182 LIS.getInstructionIndex(DefMI),
183 LIS.getInstructionIndex(UseMI)))
184 return false;
185
186 // We also need to make sure it is safe to move the load.
187 // Assume there are stores between DefMI and UseMI.
188 bool SawStore = true;
189 if (!DefMI->isSafeToMove(&TII, 0, SawStore))
190 return false;
191
179192 DEBUG(dbgs() << "Try to fold single def: " << *DefMI
180193 << " into single use: " << *UseMI);
181194
0 ; RUN: llc < %s -disable-fp-elim -verify-coalescing
1 ; PR13414
2 ;
3 ; During coalescing, remat triggers DCE which deletes the penultimate use of a
4 ; load. This load should not be folded into the remaining use because it is not
5 ; safe to move, and it would extend the live range of the address.
6 ;
7 ; LiveRangeEdit::foldAsLoad() doesn't extend live ranges, so -verify-coalescing
8 ; catches the problem.
9
10 target triple = "i386-unknown-linux-gnu"
11
12 %type_a = type { %type_a*, %type_b }
13 %type_b = type { %type_c, i32 }
14 %type_c = type { i32, %type_d }
15 %type_d = type { i64 }
16 %type_e = type { %type_c, i64 }
17
18 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind
19
20 define linkonce_odr void @test() nounwind {
21 entry:
22 br i1 undef, label %while.end.while.end26_crit_edge, label %while.body12.lr.ph
23
24 while.end.while.end26_crit_edge: ; preds = %entry
25 br label %while.end26
26
27 while.body12.lr.ph: ; preds = %entry
28 br label %while.body12
29
30 while.body12: ; preds = %if.end24, %while.body12.lr.ph
31 %tmp = phi %type_a* [ undef, %while.body12.lr.ph ], [ %tmp18, %if.end24 ]
32 %ins151154161 = phi i128 [ 0, %while.body12.lr.ph ], [ %phitmp, %if.end24 ]
33 %ins135156160 = phi i128 [ 0, %while.body12.lr.ph ], [ %phitmp158, %if.end24 ]
34 %ins151 = or i128 0, %ins151154161
35 %cmp.i.i.i.i.i67 = icmp sgt i32 undef, 8
36 br i1 %cmp.i.i.i.i.i67, label %if.then.i.i.i.i71, label %if.else.i.i.i.i74
37
38 if.then.i.i.i.i71: ; preds = %while.body12
39 %call4.i.i.i.i68 = call noalias i8* @malloc(i32 undef) nounwind
40 %tmp1 = getelementptr inbounds %type_a* %tmp, i32 0, i32 1, i32 0, i32 1
41 %buf_6.i.i.i.i70 = bitcast %type_d* %tmp1 to i8**
42 %tmp2 = load i8** %buf_6.i.i.i.i70, align 4
43 call void @llvm.memcpy.p0i8.p0i8.i32(i8* undef, i8* %tmp2, i32 undef, i32 1, i1 false) nounwind
44 unreachable
45
46 if.else.i.i.i.i74: ; preds = %while.body12
47 %i_.i.i.i.i72 = getelementptr inbounds %type_a* %tmp, i32 0, i32 1, i32 0, i32 1, i32 0
48 %tmp3 = load i64* %i_.i.i.i.i72, align 4
49 %tmp4 = zext i64 %tmp3 to i128
50 %tmp5 = shl nuw nsw i128 %tmp4, 32
51 %ins148 = or i128 %tmp5, %ins151
52 %second3.i.i76 = getelementptr inbounds %type_a* %tmp, i32 0, i32 1, i32 1
53 %tmp6 = load i32* %second3.i.i76, align 4
54 %tmp7 = zext i32 %tmp6 to i128
55 %tmp8 = shl nuw i128 %tmp7, 96
56 %mask144 = and i128 %ins148, 79228162495817593519834398720
57 %tmp9 = load %type_e** undef, align 4
58 %len_.i.i.i.i86 = getelementptr inbounds %type_e* %tmp9, i32 0, i32 0, i32 0
59 %tmp10 = load i32* %len_.i.i.i.i86, align 4
60 %tmp11 = zext i32 %tmp10 to i128
61 %ins135 = or i128 %tmp11, %ins135156160
62 %cmp.i.i.i.i.i88 = icmp sgt i32 %tmp10, 8
63 br i1 %cmp.i.i.i.i.i88, label %if.then.i.i.i.i92, label %if.else.i.i.i.i95
64
65 if.then.i.i.i.i92: ; preds = %if.else.i.i.i.i74
66 %call4.i.i.i.i89 = call noalias i8* @malloc(i32 %tmp10) nounwind
67 %ins126 = or i128 0, %ins135
68 %tmp12 = getelementptr inbounds %type_e* %tmp9, i32 0, i32 0, i32 1
69 %buf_6.i.i.i.i91 = bitcast %type_d* %tmp12 to i8**
70 %tmp13 = load i8** %buf_6.i.i.i.i91, align 4
71 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %call4.i.i.i.i89, i8* %tmp13, i32 %tmp10, i32 1, i1 false) nounwind
72 br label %A
73
74 if.else.i.i.i.i95: ; preds = %if.else.i.i.i.i74
75 %i_.i.i.i.i93 = getelementptr inbounds %type_e* %tmp9, i32 0, i32 0, i32 1, i32 0
76 br label %A
77
78 A: ; preds = %if.else.i.i.i.i95, %if.then.i.i.i.i92
79 %ins135157 = phi i128 [ %ins126, %if.then.i.i.i.i92 ], [ undef, %if.else.i.i.i.i95 ]
80 %second3.i.i97 = getelementptr inbounds %type_e* %tmp9, i32 0, i32 1
81 %tmp14 = load i64* %second3.i.i97, align 4
82 %tmp15 = trunc i64 %tmp14 to i32
83 %cmp.i99 = icmp sgt i32 %tmp6, %tmp15
84 %tmp16 = trunc i128 %ins135157 to i32
85 %cmp.i.i.i.i.i.i101 = icmp sgt i32 %tmp16, 8
86 br i1 %cmp.i.i.i.i.i.i101, label %if.then.i.i.i.i.i103, label %B
87
88 if.then.i.i.i.i.i103: ; preds = %A
89 unreachable
90
91 B: ; preds = %A
92 %tmp17 = trunc i128 %ins148 to i32
93 %cmp.i.i.i.i.i.i83 = icmp sgt i32 %tmp17, 8
94 br i1 %cmp.i.i.i.i.i.i83, label %if.then.i.i.i.i.i85, label %C
95
96 if.then.i.i.i.i.i85: ; preds = %B
97 unreachable
98
99 C: ; preds = %B
100 br i1 %cmp.i99, label %if.then17, label %if.end24
101
102 if.then17: ; preds = %C
103 br i1 false, label %if.then.i.i.i.i.i43, label %D
104
105 if.then.i.i.i.i.i43: ; preds = %if.then17
106 unreachable
107
108 D: ; preds = %if.then17
109 br i1 undef, label %if.then.i.i.i.i.i, label %E
110
111 if.then.i.i.i.i.i: ; preds = %D
112 unreachable
113
114 E: ; preds = %D
115 br label %if.end24
116
117 if.end24: ; preds = %E, %C
118 %phitmp = or i128 %tmp8, %mask144
119 %phitmp158 = or i128 undef, undef
120 %tmp18 = load %type_a** undef, align 4
121 %tmp19 = load %type_a** undef, align 4
122 %cmp.i49 = icmp eq %type_a* %tmp18, %tmp19
123 br i1 %cmp.i49, label %while.cond10.while.end26_crit_edge, label %while.body12
124
125 while.cond10.while.end26_crit_edge: ; preds = %if.end24
126 %.pre = load %type_e** undef, align 4
127 br label %while.end26
128
129 while.end26: ; preds = %while.cond10.while.end26_crit_edge, %while.end.while.end26_crit_edge
130 br i1 undef, label %while.body.lr.ph.i, label %F
131
132 while.body.lr.ph.i: ; preds = %while.end26
133 br label %while.body.i
134
135 while.body.i: ; preds = %while.body.i, %while.body.lr.ph.i
136 br i1 false, label %while.body.i, label %F
137
138 F: ; preds = %while.body.i, %while.end26
139 ret void
140 }
141
142 declare noalias i8* @malloc(i32) nounwind