pr44242.ll
6.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -instcombine < %s | FileCheck %s
; Check that we don't create two redundant phi nodes when %val is used in a
; form where we can't rewrite it in terms of the new phi node.
; Use %val in an instruction type not supported by optimizeBitCastFromPhi.
define float @sitofp(float %x) {
; CHECK-LABEL: @sitofp(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
; CHECK: loop_header:
; CHECK-NEXT: [[VAL:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[VAL_INCR_CASTED:%.*]], [[LOOP:%.*]] ]
; CHECK-NEXT: [[VAL_CASTED:%.*]] = bitcast i32 [[VAL]] to float
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[VAL_CASTED]], [[X:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[LOOP]]
; CHECK: loop:
; CHECK-NEXT: [[VAL_INCR:%.*]] = fadd float [[VAL_CASTED]], 1.000000e+00
; CHECK-NEXT: [[VAL_INCR_CASTED]] = bitcast float [[VAL_INCR]] to i32
; CHECK-NEXT: br label [[LOOP_HEADER]]
; CHECK: end:
; CHECK-NEXT: [[RESULT:%.*]] = sitofp i32 [[VAL]] to float
; CHECK-NEXT: ret float [[RESULT]]
;
entry:
br label %loop_header
loop_header:
%val = phi i32 [ 0, %entry ], [ %val_incr_casted, %loop ]
%val_casted = bitcast i32 %val to float
%cmp = fcmp ogt float %val_casted, %x
br i1 %cmp, label %end, label %loop
loop:
%val_incr = fadd float %val_casted, 1.0
%val_incr_casted = bitcast float %val_incr to i32
br label %loop_header
end:
%result = sitofp i32 %val to float
ret float %result
}
; Use %val in an incompatible bitcast.
define <2 x i16> @bitcast(float %x) {
; CHECK-LABEL: @bitcast(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
; CHECK: loop_header:
; CHECK-NEXT: [[VAL:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[VAL_INCR_CASTED:%.*]], [[LOOP:%.*]] ]
; CHECK-NEXT: [[VAL_CASTED:%.*]] = bitcast i32 [[VAL]] to float
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[VAL_CASTED]], [[X:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[LOOP]]
; CHECK: loop:
; CHECK-NEXT: [[VAL_INCR:%.*]] = fadd float [[VAL_CASTED]], 1.000000e+00
; CHECK-NEXT: [[VAL_INCR_CASTED]] = bitcast float [[VAL_INCR]] to i32
; CHECK-NEXT: br label [[LOOP_HEADER]]
; CHECK: end:
; CHECK-NEXT: [[RESULT:%.*]] = bitcast i32 [[VAL]] to <2 x i16>
; CHECK-NEXT: ret <2 x i16> [[RESULT]]
;
entry:
br label %loop_header
loop_header:
%val = phi i32 [ 0, %entry ], [ %val_incr_casted, %loop ]
%val_casted = bitcast i32 %val to float
%cmp = fcmp ogt float %val_casted, %x
br i1 %cmp, label %end, label %loop
loop:
%val_incr = fadd float %val_casted, 1.0
%val_incr_casted = bitcast float %val_incr to i32
br label %loop_header
end:
%result = bitcast i32 %val to <2 x i16>
ret <2 x i16> %result
}
@global = global i32 0
; Use %val with a volatile store.
define void @store_volatile(float %x) {
; CHECK-LABEL: @store_volatile(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
; CHECK: loop_header:
; CHECK-NEXT: [[VAL:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[VAL_INCR_CASTED:%.*]], [[LOOP:%.*]] ]
; CHECK-NEXT: [[VAL_CASTED:%.*]] = bitcast i32 [[VAL]] to float
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[VAL_CASTED]], [[X:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[LOOP]]
; CHECK: loop:
; CHECK-NEXT: [[VAL_INCR:%.*]] = fadd float [[VAL_CASTED]], 1.000000e+00
; CHECK-NEXT: [[VAL_INCR_CASTED]] = bitcast float [[VAL_INCR]] to i32
; CHECK-NEXT: br label [[LOOP_HEADER]]
; CHECK: end:
; CHECK-NEXT: store volatile i32 [[VAL]], i32* @global, align 4
; CHECK-NEXT: ret void
;
entry:
br label %loop_header
loop_header:
%val = phi i32 [ 0, %entry ], [ %val_incr_casted, %loop ]
%val_casted = bitcast i32 %val to float
%cmp = fcmp ogt float %val_casted, %x
br i1 %cmp, label %end, label %loop
loop:
%val_incr = fadd float %val_casted, 1.0
%val_incr_casted = bitcast float %val_incr to i32
br label %loop_header
end:
store volatile i32 %val, i32* @global
ret void
}
; Use %val with a store where it's actually the address.
define void @store_address(i32 %x) {
; CHECK-LABEL: @store_address(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
; CHECK: loop_header:
; CHECK-NEXT: [[VAL:%.*]] = phi i32* [ @global, [[ENTRY:%.*]] ], [ [[VAL_INCR1:%.*]], [[LOOP:%.*]] ]
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[LOOP]]
; CHECK: loop:
; CHECK-NEXT: [[VAL_INCR1]] = getelementptr i32, i32* [[VAL]], i64 1
; CHECK-NEXT: br label [[LOOP_HEADER]]
; CHECK: end:
; CHECK-NEXT: store i32 0, i32* [[VAL]], align 4
; CHECK-NEXT: ret void
;
entry:
br label %loop_header
loop_header:
%val = phi i32* [ @global, %entry ], [ %val_incr_casted, %loop ]
%i = phi i32 [ 0, %entry ], [ %i_incr, %loop ]
%val_casted = bitcast i32* %val to float*
%cmp = icmp sgt i32 %i, %x
br i1 %cmp, label %end, label %loop
loop:
%i_incr = add i32 %i, 0
%val_incr = getelementptr float, float* %val_casted, i32 1
%val_incr_casted = bitcast float* %val_incr to i32*
br label %loop_header
end:
store i32 0, i32* %val
ret void
}
; Test where a phi (%val2) other than the original one (%val) has an
; incompatible use.
define i32 @multiple_phis(float %x) {
; CHECK-LABEL: @multiple_phis(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
; CHECK: loop_header:
; CHECK-NEXT: [[VAL:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[VAL2:%.*]], [[LOOP_END:%.*]] ]
; CHECK-NEXT: [[VAL_CASTED:%.*]] = bitcast i32 [[VAL]] to float
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[VAL_CASTED]], [[X:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[END:%.*]], label [[LOOP:%.*]]
; CHECK: loop:
; CHECK-NEXT: [[CMP2:%.*]] = fcmp ogt float [[VAL_CASTED]], 2.000000e+00
; CHECK-NEXT: br i1 [[CMP2]], label [[IF:%.*]], label [[LOOP_END]]
; CHECK: if:
; CHECK-NEXT: [[VAL_INCR:%.*]] = fadd float [[VAL_CASTED]], 1.000000e+00
; CHECK-NEXT: [[VAL_INCR_CASTED:%.*]] = bitcast float [[VAL_INCR]] to i32
; CHECK-NEXT: br label [[LOOP_END]]
; CHECK: loop_end:
; CHECK-NEXT: [[VAL2]] = phi i32 [ [[VAL]], [[LOOP]] ], [ [[VAL_INCR_CASTED]], [[IF]] ]
; CHECK-NEXT: store volatile i32 [[VAL2]], i32* @global, align 4
; CHECK-NEXT: br label [[LOOP_HEADER]]
; CHECK: end:
; CHECK-NEXT: ret i32 [[VAL]]
;
entry:
br label %loop_header
loop_header:
%val = phi i32 [ 0, %entry ], [ %val2, %loop_end ]
%val_casted = bitcast i32 %val to float
%cmp = fcmp ogt float %val_casted, %x
br i1 %cmp, label %end, label %loop
loop:
%cmp2 = fcmp ogt float %val_casted, 2.0
br i1 %cmp2, label %if, label %loop_end
if:
%val_incr = fadd float %val_casted, 1.0
%val_incr_casted = bitcast float %val_incr to i32
br label %loop_end
loop_end:
%val2 = phi i32 [ %val, %loop ], [ %val_incr_casted, %if ]
store volatile i32 %val2, i32* @global ; the incompatible use
br label %loop_header
end:
ret i32 %val
}