1; RUN: llc < %s -frame-pointer=all -verify-coalescing
2; PR13414
3;
4; During coalescing, remat triggers DCE which deletes the penultimate use of a
5; load. This load should not be folded into the remaining use because it is not
6; safe to move, and it would extend the live range of the address.
7;
8; LiveRangeEdit::foldAsLoad() doesn't extend live ranges, so -verify-coalescing
9; catches the problem.
10
11target triple = "i386-unknown-linux-gnu"
12
13%type_a = type { %type_a*, %type_b }
14%type_b = type { %type_c, i32 }
15%type_c = type { i32, %type_d }
16%type_d = type { i64 }
17%type_e = type { %type_c, i64 }
18
19declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i1) nounwind
20
21define linkonce_odr void @test() nounwind {
22entry:
23  br i1 undef, label %while.end.while.end26_crit_edge, label %while.body12.lr.ph
24
25while.end.while.end26_crit_edge:                  ; preds = %entry
26  br label %while.end26
27
28while.body12.lr.ph:                               ; preds = %entry
29  br label %while.body12
30
31while.body12:                                     ; preds = %if.end24, %while.body12.lr.ph
32  %tmp = phi %type_a* [ undef, %while.body12.lr.ph ], [ %tmp18, %if.end24 ]
33  %ins151154161 = phi i128 [ 0, %while.body12.lr.ph ], [ %phitmp, %if.end24 ]
34  %ins135156160 = phi i128 [ 0, %while.body12.lr.ph ], [ %phitmp158, %if.end24 ]
35  %ins151 = or i128 0, %ins151154161
36  %cmp.i.i.i.i.i67 = icmp sgt i32 undef, 8
37  br i1 %cmp.i.i.i.i.i67, label %if.then.i.i.i.i71, label %if.else.i.i.i.i74
38
39if.then.i.i.i.i71:                                ; preds = %while.body12
40  %call4.i.i.i.i68 = call noalias i8* @malloc(i32 undef) nounwind
41  %tmp1 = getelementptr inbounds %type_a, %type_a* %tmp, i32 0, i32 1, i32 0, i32 1
42  %buf_6.i.i.i.i70 = bitcast %type_d* %tmp1 to i8**
43  %tmp2 = load i8*, i8** %buf_6.i.i.i.i70, align 4
44  call void @llvm.memcpy.p0i8.p0i8.i32(i8* undef, i8* %tmp2, i32 undef, i1 false) nounwind
45  unreachable
46
47if.else.i.i.i.i74:                                ; preds = %while.body12
48  %i_.i.i.i.i72 = getelementptr inbounds %type_a, %type_a* %tmp, i32 0, i32 1, i32 0, i32 1, i32 0
49  %tmp3 = load i64, i64* %i_.i.i.i.i72, align 4
50  %tmp4 = zext i64 %tmp3 to i128
51  %tmp5 = shl nuw nsw i128 %tmp4, 32
52  %ins148 = or i128 %tmp5, %ins151
53  %second3.i.i76 = getelementptr inbounds %type_a, %type_a* %tmp, i32 0, i32 1, i32 1
54  %tmp6 = load i32, i32* %second3.i.i76, align 4
55  %tmp7 = zext i32 %tmp6 to i128
56  %tmp8 = shl nuw i128 %tmp7, 96
57  %mask144 = and i128 %ins148, 79228162495817593519834398720
58  %tmp9 = load %type_e*, %type_e** undef, align 4
59  %len_.i.i.i.i86 = getelementptr inbounds %type_e, %type_e* %tmp9, i32 0, i32 0, i32 0
60  %tmp10 = load i32, i32* %len_.i.i.i.i86, align 4
61  %tmp11 = zext i32 %tmp10 to i128
62  %ins135 = or i128 %tmp11, %ins135156160
63  %cmp.i.i.i.i.i88 = icmp sgt i32 %tmp10, 8
64  br i1 %cmp.i.i.i.i.i88, label %if.then.i.i.i.i92, label %if.else.i.i.i.i95
65
66if.then.i.i.i.i92:                                ; preds = %if.else.i.i.i.i74
67  %call4.i.i.i.i89 = call noalias i8* @malloc(i32 %tmp10) nounwind
68  %ins126 = or i128 0, %ins135
69  %tmp12 = getelementptr inbounds %type_e, %type_e* %tmp9, i32 0, i32 0, i32 1
70  %buf_6.i.i.i.i91 = bitcast %type_d* %tmp12 to i8**
71  %tmp13 = load i8*, i8** %buf_6.i.i.i.i91, align 4
72  call void @llvm.memcpy.p0i8.p0i8.i32(i8* %call4.i.i.i.i89, i8* %tmp13, i32 %tmp10, i1 false) nounwind
73  br label %A
74
75if.else.i.i.i.i95:                                ; preds = %if.else.i.i.i.i74
76  %i_.i.i.i.i93 = getelementptr inbounds %type_e, %type_e* %tmp9, i32 0, i32 0, i32 1, i32 0
77  br label %A
78
79A:                                                ; preds = %if.else.i.i.i.i95, %if.then.i.i.i.i92
80  %ins135157 = phi i128 [ %ins126, %if.then.i.i.i.i92 ], [ undef, %if.else.i.i.i.i95 ]
81  %second3.i.i97 = getelementptr inbounds %type_e, %type_e* %tmp9, i32 0, i32 1
82  %tmp14 = load i64, i64* %second3.i.i97, align 4
83  %tmp15 = trunc i64 %tmp14 to i32
84  %cmp.i99 = icmp sgt i32 %tmp6, %tmp15
85  %tmp16 = trunc i128 %ins135157 to i32
86  %cmp.i.i.i.i.i.i101 = icmp sgt i32 %tmp16, 8
87  br i1 %cmp.i.i.i.i.i.i101, label %if.then.i.i.i.i.i103, label %B
88
89if.then.i.i.i.i.i103:                             ; preds = %A
90  unreachable
91
92B:                                                ; preds = %A
93  %tmp17 = trunc i128 %ins148 to i32
94  %cmp.i.i.i.i.i.i83 = icmp sgt i32 %tmp17, 8
95  br i1 %cmp.i.i.i.i.i.i83, label %if.then.i.i.i.i.i85, label %C
96
97if.then.i.i.i.i.i85:                              ; preds = %B
98  unreachable
99
100C:                                                ; preds = %B
101  br i1 %cmp.i99, label %if.then17, label %if.end24
102
103if.then17:                                        ; preds = %C
104  br i1 false, label %if.then.i.i.i.i.i43, label %D
105
106if.then.i.i.i.i.i43:                              ; preds = %if.then17
107  unreachable
108
109D:                                                ; preds = %if.then17
110  br i1 undef, label %if.then.i.i.i.i.i, label %E
111
112if.then.i.i.i.i.i:                                ; preds = %D
113  unreachable
114
115E:                                                ; preds = %D
116  br label %if.end24
117
118if.end24:                                         ; preds = %E, %C
119  %phitmp = or i128 %tmp8, %mask144
120  %phitmp158 = or i128 undef, undef
121  %tmp18 = load %type_a*, %type_a** undef, align 4
122  %tmp19 = load %type_a*, %type_a** undef, align 4
123  %cmp.i49 = icmp eq %type_a* %tmp18, %tmp19
124  br i1 %cmp.i49, label %while.cond10.while.end26_crit_edge, label %while.body12
125
126while.cond10.while.end26_crit_edge:               ; preds = %if.end24
127  %.pre = load %type_e*, %type_e** undef, align 4
128  br label %while.end26
129
130while.end26:                                      ; preds = %while.cond10.while.end26_crit_edge, %while.end.while.end26_crit_edge
131  br i1 undef, label %while.body.lr.ph.i, label %F
132
133while.body.lr.ph.i:                               ; preds = %while.end26
134  br label %while.body.i
135
136while.body.i:                                     ; preds = %while.body.i, %while.body.lr.ph.i
137  br i1 false, label %while.body.i, label %F
138
139F:                                                ; preds = %while.body.i, %while.end26
140  ret void
141}
142
143declare noalias i8* @malloc(i32) nounwind
144