File: immediates.ll

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (192 lines) | stat: -rw-r--r-- 5,193 bytes parent folder | download
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
; RUN: opt -mtriple=riscv32-unknown-elf -S -passes=consthoist < %s | FileCheck %s
; RUN: opt -mtriple=riscv64-unknown-elf -S -passes=consthoist < %s | FileCheck %s

; Check that we don't hoist immediates with small values.
define i64 @test1(i64 %a) nounwind {
; CHECK-LABEL: test1
; CHECK-NOT: %const = bitcast i64 2 to i64
  %1 = mul i64 %a, 2
  %2 = add i64 %1, 2
  ret i64 %2
}

; Check that we don't hoist immediates with small values.
define i64 @test2(i64 %a) nounwind {
; CHECK-LABEL: test2
; CHECK-NOT: %const = bitcast i64 2047 to i64
  %1 = mul i64 %a, 2047
  %2 = add i64 %1, 2047
  ret i64 %2
}

; Check that we hoist immediates with large values.
define i64 @test3(i64 %a) nounwind {
; CHECK-LABEL: test3
; CHECK: %const = bitcast i64 32767 to i64
  %1 = mul i64 %a, 32767
  %2 = add i64 %1, 32767
  ret i64 %2
}

; Check that we hoist immediates with very large values.
define i128 @test4(i128 %a) nounwind {
; CHECK-LABEL: test4
; CHECK: %const = bitcast i128 12297829382473034410122878 to i128
  %1 = add i128 %a, 12297829382473034410122878
  %2 = add i128 %1, 12297829382473034410122878
  ret i128 %2
}

; Check that we hoist zext.h without Zbb.
define i32 @test5(i32 %a) nounwind {
; CHECK-LABEL: test5
; CHECK: %const = bitcast i32 65535 to i32
  %1 = and i32 %a, 65535
  %2 = and i32 %1, 65535
  ret i32 %2
}

; Check that we don't hoist zext.h with 65535 with Zbb.
define i32 @test6(i32 %a) nounwind "target-features"="+zbb" {
; CHECK-LABEL: test6
; CHECK: and i32 %a, 65535
  %1 = and i32 %a, 65535
  %2 = and i32 %1, 65535
  ret i32 %2
}

; Check that we hoist zext.w without Zba.
define i64 @test7(i64 %a) nounwind {
; CHECK-LABEL: test7
; CHECK: %const = bitcast i64 4294967295 to i64
  %1 = and i64 %a, 4294967295
  %2 = and i64 %1, 4294967295
  ret i64 %2
}

; Check that we don't hoist zext.w with Zba.
define i64 @test8(i64 %a) nounwind "target-features"="+zba" {
; CHECK-LABEL: test8
; CHECK: and i64 %a, 4294967295
  %1 = and i64 %a, 4294967295
  %2 = and i64 %1, 4294967295
  ret i64 %2
}

; Check that we don't hoist mul with negated power of 2.
define i64 @test9(i64 %a) nounwind {
; CHECK-LABEL: test9
; CHECK: mul i64 %a, -4294967296
  %1 = mul i64 %a, -4294967296
  %2 = mul i64 %1, -4294967296
  ret i64 %2
}

define i32 @test10(i32 %a, i32 %b) nounwind {
; CHECK-LABEL: @test10(
; CHECK: shl i32 %a, 8
; CHECK: and i32 %1, 65280
; CHECK: shl i32 %b, 8
; CHECK: and i32 %3, 65280
  %1 = shl i32 %a, 8
  %2 = and i32 %1, 65280
  %3 = shl i32 %b, 8
  %4 = and i32 %3, 65280
  %5 = mul i32 %2, %4
  ret i32 %5
}

; bseti
define i64 @test11(i64 %a) nounwind "target-features"="+zbs" {
; CHECK-LABEL: test11
; CHECK: or i64 %a, 8589934592
  %1 = or i64 %a, 8589934592 ; 1 << 33
  %2 = or i64 %1, 8589934592 ; 1 << 33
  ret i64 %2
}

; binvi
define i64 @test12(i64 %a) nounwind "target-features"="+zbs" {
; CHECK-LABEL: test12
; CHECK: xor i64 %a, -9223372036854775808
  %1 = xor i64 %a, -9223372036854775808 ; 1 << 63
  %2 = xor i64 %1, -9223372036854775808 ; 1 << 63
  ret i64 %2
}

; bclri
define i64 @test13(i64 %a) nounwind "target-features"="+zbs" {
; CHECK-LABEL: test13
; CHECK: and i64 %a, -281474976710657
  %1 = and i64 %a, -281474976710657 ; ~(1 << 48)
  %2 = and i64 %1, -281474976710657 ; ~(1 << 48)
  ret i64 %2
}

; Check that we don't hoist mul by a power of 2.
define i64 @test14(i64 %a) nounwind {
; CHECK-LABEL: test14
; CHECK: mul i64 %a, 2048
  %1 = mul i64 %a, 2048
  %2 = mul i64 %1, 2048
  ret i64 %2
}

; Check that we hoist the absolute address of the stores to the entry block.
define void @test17(ptr %s, i32 %size) nounwind {
; CHECK-LABEL: test17
; CHECK: %const = bitcast i32 -1073741792 to i32
; CHECK: %0 = inttoptr i32 %const to ptr
; CHECK: store i32 20, ptr %0
; CHECK: %1 = inttoptr i32 %const to ptr
; CHECK: store i32 10, ptr %1
entry:
  %cond = icmp eq i32 %size, 0
  br i1 %cond, label %if.true, label %exit
if.true:
  store i32 20, ptr inttoptr (i32 -1073741792 to ptr)
  br label %exit
exit:
  store i32 10, ptr inttoptr (i32 -1073741792 to ptr)
  ret void
}

; Check that we hoist the absolute address of the loads to the entry block.
define i32 @test18(ptr %s, i32 %size) nounwind {
; CHECK-LABEL: test18
; CHECK: %const = bitcast i32 -1073741792 to i32
; CHECK: %0 = inttoptr i32 %const to ptr
; CHECK: %1 = load i32, ptr %0
; CHECK: %2 = inttoptr i32 %const to ptr
; CHECK: %3 = load i32, ptr %2
entry:
  %cond = icmp eq i32 %size, 0
  br i1 %cond, label %if.true, label %if.false
if.true:
  %0 = load i32, ptr inttoptr (i32 -1073741792 to ptr)
  br label %return
if.false:
  %1 = load i32, ptr inttoptr (i32 -1073741792 to ptr)
  br label %return
return:
  %val = phi i32 [%0, %if.true], [%1, %if.false]
  ret i32 %val
}


; For addresses between [0, 2048), we can use ld/sd xN, address(zero), so don't
; hoist.
define void @test19(ptr %s, i32 %size) nounwind {
; CHECK-LABEL: test19
; CHECK: store i32 20, ptr inttoptr (i32 2044 to ptr)
; CHECK: store i32 10, ptr inttoptr (i32 2044 to ptr)
entry:
  %cond = icmp eq i32 %size, 0
  br i1 %cond, label %if.true, label %exit
if.true:
  store i32 20, ptr inttoptr (i32 2044 to ptr)
  br label %exit
exit:
  store i32 10, ptr inttoptr (i32 2044 to ptr)
  ret void
}