immediate_merging.ll
7.28 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=i386-unknown-linux-gnu | FileCheck %s --check-prefix=X86
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu | FileCheck %s --check-prefix=X64
@a = common global i32 0, align 4
@b = common global i32 0, align 4
@c = common global i32 0, align 4
@e = common global i32 0, align 4
@x = common global i32 0, align 4
@f = common global i32 0, align 4
@h = common global i32 0, align 4
@i = common global i32 0, align 4
; Test -Os to make sure immediates with multiple users don't get pulled in to
; instructions (8-bit immediates are exceptions).
define i32 @foo() optsize {
; X86-LABEL: foo:
; X86: # %bb.0: # %entry
; X86-NEXT: movl $1234, %eax # imm = 0x4D2
; X86-NEXT: movl %eax, a
; X86-NEXT: movl %eax, b
; X86-NEXT: movl $12, c
; X86-NEXT: cmpl $12, e
; X86-NEXT: jne .LBB0_2
; X86-NEXT: # %bb.1: # %if.then
; X86-NEXT: movl $1, x
; X86-NEXT: .LBB0_2: # %if.end
; X86-NEXT: movl $1234, f # imm = 0x4D2
; X86-NEXT: movl $555, %eax # imm = 0x22B
; X86-NEXT: movl %eax, h
; X86-NEXT: addl %eax, i
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: retl
;
; X64-LABEL: foo:
; X64: # %bb.0: # %entry
; X64-NEXT: movl $1234, %eax # imm = 0x4D2
; X64-NEXT: movl %eax, {{.*}}(%rip)
; X64-NEXT: movl %eax, {{.*}}(%rip)
; X64-NEXT: movl $12, {{.*}}(%rip)
; X64-NEXT: cmpl $12, {{.*}}(%rip)
; X64-NEXT: jne .LBB0_2
; X64-NEXT: # %bb.1: # %if.then
; X64-NEXT: movl $1, {{.*}}(%rip)
; X64-NEXT: .LBB0_2: # %if.end
; X64-NEXT: movl $1234, {{.*}}(%rip) # imm = 0x4D2
; X64-NEXT: movl $555, %eax # imm = 0x22B
; X64-NEXT: movl %eax, {{.*}}(%rip)
; X64-NEXT: addl %eax, {{.*}}(%rip)
; X64-NEXT: xorl %eax, %eax
; X64-NEXT: retq
entry:
store i32 1234, i32* @a
store i32 1234, i32* @b
store i32 12, i32* @c
%0 = load i32, i32* @e
%cmp = icmp eq i32 %0, 12
br i1 %cmp, label %if.then, label %if.end
if.then: ; preds = %entry
store i32 1, i32* @x
br label %if.end
; New block.. Make sure 1234 isn't live across basic blocks from before.
if.end: ; preds = %if.then, %entry
store i32 1234, i32* @f
store i32 555, i32* @h
%1 = load i32, i32* @i
%add1 = add nsw i32 %1, 555
store i32 %add1, i32* @i
ret i32 0
}
; Test PGSO to make sure immediates with multiple users don't get pulled in to
; instructions (8-bit immediates are exceptions).
define i32 @foo_pgso() !prof !14 {
; X86-LABEL: foo_pgso:
; X86: # %bb.0: # %entry
; X86-NEXT: movl $1234, %eax # imm = 0x4D2
; X86-NEXT: movl %eax, a
; X86-NEXT: movl %eax, b
; X86-NEXT: movl $12, c
; X86-NEXT: cmpl $12, e
; X86-NEXT: jne .LBB1_2
; X86-NEXT: # %bb.1: # %if.then
; X86-NEXT: movl $1, x
; X86-NEXT: .LBB1_2: # %if.end
; X86-NEXT: movl $1234, f # imm = 0x4D2
; X86-NEXT: movl $555, %eax # imm = 0x22B
; X86-NEXT: movl %eax, h
; X86-NEXT: addl %eax, i
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: retl
;
; X64-LABEL: foo_pgso:
; X64: # %bb.0: # %entry
; X64-NEXT: movl $1234, %eax # imm = 0x4D2
; X64-NEXT: movl %eax, {{.*}}(%rip)
; X64-NEXT: movl %eax, {{.*}}(%rip)
; X64-NEXT: movl $12, {{.*}}(%rip)
; X64-NEXT: cmpl $12, {{.*}}(%rip)
; X64-NEXT: jne .LBB1_2
; X64-NEXT: # %bb.1: # %if.then
; X64-NEXT: movl $1, {{.*}}(%rip)
; X64-NEXT: .LBB1_2: # %if.end
; X64-NEXT: movl $1234, {{.*}}(%rip) # imm = 0x4D2
; X64-NEXT: movl $555, %eax # imm = 0x22B
; X64-NEXT: movl %eax, {{.*}}(%rip)
; X64-NEXT: addl %eax, {{.*}}(%rip)
; X64-NEXT: xorl %eax, %eax
; X64-NEXT: retq
entry:
store i32 1234, i32* @a
store i32 1234, i32* @b
store i32 12, i32* @c
%0 = load i32, i32* @e
%cmp = icmp eq i32 %0, 12
br i1 %cmp, label %if.then, label %if.end
if.then: ; preds = %entry
store i32 1, i32* @x
br label %if.end
; New block.. Make sure 1234 isn't live across basic blocks from before.
if.end: ; preds = %if.then, %entry
store i32 1234, i32* @f
store i32 555, i32* @h
%1 = load i32, i32* @i
%add1 = add nsw i32 %1, 555
store i32 %add1, i32* @i
ret i32 0
}
; Test -O2 to make sure that all immediates get pulled in to their users.
define i32 @foo2() {
; X86-LABEL: foo2:
; X86: # %bb.0: # %entry
; X86-NEXT: movl $1234, a # imm = 0x4D2
; X86-NEXT: movl $1234, b # imm = 0x4D2
; X86-NEXT: xorl %eax, %eax
; X86-NEXT: retl
;
; X64-LABEL: foo2:
; X64: # %bb.0: # %entry
; X64-NEXT: movl $1234, {{.*}}(%rip) # imm = 0x4D2
; X64-NEXT: movl $1234, {{.*}}(%rip) # imm = 0x4D2
; X64-NEXT: xorl %eax, %eax
; X64-NEXT: retq
entry:
store i32 1234, i32* @a
store i32 1234, i32* @b
ret i32 0
}
declare void @llvm.memset.p0i8.i32(i8* nocapture, i8, i32, i1) #1
@AA = common global [100 x i8] zeroinitializer, align 1
; memset gets lowered in DAG. Constant merging should hoist all the
; immediates used to store to the individual memory locations. Make
; sure we don't directly store the immediates.
define void @foomemset() optsize {
; X86-LABEL: foomemset:
; X86: # %bb.0: # %entry
; X86-NEXT: movl $555819297, %eax # imm = 0x21212121
; X86-NEXT: movl %eax, AA+20
; X86-NEXT: movl %eax, AA+16
; X86-NEXT: movl %eax, AA+12
; X86-NEXT: movl %eax, AA+8
; X86-NEXT: movl %eax, AA+4
; X86-NEXT: movl %eax, AA
; X86-NEXT: retl
;
; X64-LABEL: foomemset:
; X64: # %bb.0: # %entry
; X64-NEXT: movabsq $2387225703656530209, %rax # imm = 0x2121212121212121
; X64-NEXT: movq %rax, AA+{{.*}}(%rip)
; X64-NEXT: movq %rax, AA+{{.*}}(%rip)
; X64-NEXT: movq %rax, {{.*}}(%rip)
; X64-NEXT: retq
entry:
call void @llvm.memset.p0i8.i32(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @AA, i32 0, i32 0), i8 33, i32 24, i1 false)
ret void
}
; memset gets lowered in DAG. Constant merging should hoist all the
; immediates used to store to the individual memory locations. Make
; sure we don't directly store the immediates.
define void @foomemset_pgso() !prof !14 {
; X86-LABEL: foomemset_pgso:
; X86: # %bb.0: # %entry
; X86-NEXT: movl $555819297, %eax # imm = 0x21212121
; X86-NEXT: movl %eax, AA+20
; X86-NEXT: movl %eax, AA+16
; X86-NEXT: movl %eax, AA+12
; X86-NEXT: movl %eax, AA+8
; X86-NEXT: movl %eax, AA+4
; X86-NEXT: movl %eax, AA
; X86-NEXT: retl
;
; X64-LABEL: foomemset_pgso:
; X64: # %bb.0: # %entry
; X64-NEXT: movabsq $2387225703656530209, %rax # imm = 0x2121212121212121
; X64-NEXT: movq %rax, AA+{{.*}}(%rip)
; X64-NEXT: movq %rax, AA+{{.*}}(%rip)
; X64-NEXT: movq %rax, {{.*}}(%rip)
; X64-NEXT: retq
entry:
call void @llvm.memset.p0i8.i32(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @AA, i32 0, i32 0), i8 33, i32 24, i1 false)
ret void
}
!llvm.module.flags = !{!0}
!0 = !{i32 1, !"ProfileSummary", !1}
!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
!2 = !{!"ProfileFormat", !"InstrProf"}
!3 = !{!"TotalCount", i64 10000}
!4 = !{!"MaxCount", i64 10}
!5 = !{!"MaxInternalCount", i64 1}
!6 = !{!"MaxFunctionCount", i64 1000}
!7 = !{!"NumCounts", i64 3}
!8 = !{!"NumFunctions", i64 3}
!9 = !{!"DetailedSummary", !10}
!10 = !{!11, !12, !13}
!11 = !{i32 10000, i64 100, i32 1}
!12 = !{i32 999000, i64 100, i32 1}
!13 = !{i32 999999, i64 1, i32 2}
!14 = !{!"function_entry_count", i64 0}