1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instsimplify -S -o - | FileCheck %s
4 declare i32 @llvm.fshl.i32(i32, i32, i32)
5 declare i32 @llvm.fshr.i32(i32, i32, i32)
6 declare i7 @llvm.fshl.i7(i7, i7, i7)
7 declare i7 @llvm.fshr.i7(i7, i7, i7)
8 declare <4 x i8> @llvm.fshl.v4i8(<4 x i8>, <4 x i8>, <4 x i8>)
9 declare <4 x i8> @llvm.fshr.v4i8(<4 x i8>, <4 x i8>, <4 x i8>)
11 ; extract(concat(0x12345678, 0xABCDEF01) << 5) = 0x468ACF15
13 define i32 @fshl_i32() {
14 ; CHECK-LABEL: @fshl_i32(
15 ; CHECK-NEXT: ret i32 1183502101
17 %f = call i32 @llvm.fshl.i32(i32 305419896, i32 2882400001, i32 5)
21 ; extract(concat(0x12345678, 0xABCDEF01) >> 5) = 0xC55E6F78
22 ; Try an oversized shift to test modulo functionality.
24 define i32 @fshr_i32() {
25 ; CHECK-LABEL: @fshr_i32(
26 ; CHECK-NEXT: ret i32 -983666824
28 %f = call i32 @llvm.fshr.i32(i32 305419896, i32 2882400001, i32 37)
33 ; Try an oversized shift to test modulo functionality.
35 ; extract(concat(0b1110000, 0b1111111) << 2) = 0b1000011
37 define i7 @fshl_i7() {
38 ; CHECK-LABEL: @fshl_i7(
39 ; CHECK-NEXT: ret i7 -61
41 %f = call i7 @llvm.fshl.i7(i7 112, i7 127, i7 9)
45 ; extract(concat(0b1110000, 0b1111111) >> 2) = 0b0011111
46 ; Try an oversized shift to test modulo functionality.
48 define i7 @fshr_i7() {
49 ; CHECK-LABEL: @fshr_i7(
50 ; CHECK-NEXT: ret i7 31
52 %f = call i7 @llvm.fshr.i7(i7 112, i7 127, i7 16)
56 ; Vectors are folded by handling each scalar element individually, so this is the equivalent of 4 scalar tests:
57 ; extract(concat(0x00, 0xFF) << 0) = 0x00
58 ; extract(concat(0xFF, 0x00) << 0) = 0xFF
59 ; extract(concat(0x10, 0x55) << 1) = 0x20
60 ; extract(concat(0x11, 0xAA) << 2) = 0x46
62 define <4 x i8> @fshl_v4i8() {
63 ; CHECK-LABEL: @fshl_v4i8(
64 ; CHECK-NEXT: ret <4 x i8> <i8 0, i8 -1, i8 32, i8 70>
66 %f = call <4 x i8> @llvm.fshl.v4i8(<4 x i8> <i8 0, i8 -1, i8 16, i8 17>, <4 x i8> <i8 -1, i8 0, i8 85, i8 170>, <4 x i8> <i8 0, i8 8, i8 9, i8 10>)
70 ; Vectors are folded by handling each scalar element individually, so this is the equivalent of 4 scalar tests:
71 ; extract(concat(0x00, 0xFF) >> 0) = 0xFF
72 ; extract(concat(0xFF, 0x00) >> 0) = 0x00
73 ; extract(concat(0x10, 0x55) >> 1) = 0x2A
74 ; extract(concat(0x11, 0xAA) >> 2) = 0x6A
76 define <4 x i8> @fshr_v4i8() {
77 ; CHECK-LABEL: @fshr_v4i8(
78 ; CHECK-NEXT: ret <4 x i8> <i8 -1, i8 0, i8 42, i8 106>
80 %f = call <4 x i8> @llvm.fshr.v4i8(<4 x i8> <i8 0, i8 -1, i8 16, i8 17>, <4 x i8> <i8 -1, i8 0, i8 85, i8 170>, <4 x i8> <i8 0, i8 8, i8 9, i8 10>)
86 define i32 @fshl_scalar_all_undef() {
87 ; CHECK-LABEL: @fshl_scalar_all_undef(
88 ; CHECK-NEXT: ret i32 undef
90 %f = call i32 @llvm.fshl.i32(i32 undef, i32 undef, i32 undef)
94 define i32 @fshr_scalar_all_undef() {
95 ; CHECK-LABEL: @fshr_scalar_all_undef(
96 ; CHECK-NEXT: ret i32 undef
98 %f = call i32 @llvm.fshr.i32(i32 undef, i32 undef, i32 undef)
102 define i32 @fshl_scalar_undef_shamt() {
103 ; CHECK-LABEL: @fshl_scalar_undef_shamt(
104 ; CHECK-NEXT: ret i32 1
106 %f = call i32 @llvm.fshl.i32(i32 1, i32 2, i32 undef)
110 define i32 @fshr_scalar_undef_shamt() {
111 ; CHECK-LABEL: @fshr_scalar_undef_shamt(
112 ; CHECK-NEXT: ret i32 2
114 %f = call i32 @llvm.fshr.i32(i32 1, i32 2, i32 undef)
118 define i32 @fshl_scalar_undef_ops() {
119 ; CHECK-LABEL: @fshl_scalar_undef_ops(
120 ; CHECK-NEXT: ret i32 undef
122 %f = call i32 @llvm.fshl.i32(i32 undef, i32 undef, i32 7)
126 define i32 @fshr_scalar_undef_ops() {
127 ; CHECK-LABEL: @fshr_scalar_undef_ops(
128 ; CHECK-NEXT: ret i32 undef
130 %f = call i32 @llvm.fshr.i32(i32 undef, i32 undef, i32 7)
134 define i32 @fshl_scalar_undef_op1_zero_shift() {
135 ; CHECK-LABEL: @fshl_scalar_undef_op1_zero_shift(
136 ; CHECK-NEXT: ret i32 undef
138 %f = call i32 @llvm.fshl.i32(i32 undef, i32 1, i32 0)
142 define i32 @fshl_scalar_undef_op2_zero_shift() {
143 ; CHECK-LABEL: @fshl_scalar_undef_op2_zero_shift(
144 ; CHECK-NEXT: ret i32 1
146 %f = call i32 @llvm.fshl.i32(i32 1, i32 undef, i32 32)
150 define i32 @fshr_scalar_undef_op1_zero_shift() {
151 ; CHECK-LABEL: @fshr_scalar_undef_op1_zero_shift(
152 ; CHECK-NEXT: ret i32 1
154 %f = call i32 @llvm.fshr.i32(i32 undef, i32 1, i32 64)
158 define i32 @fshr_scalar_undef_op2_zero_shift() {
159 ; CHECK-LABEL: @fshr_scalar_undef_op2_zero_shift(
160 ; CHECK-NEXT: ret i32 undef
162 %f = call i32 @llvm.fshr.i32(i32 1, i32 undef, i32 0)
166 define i32 @fshl_scalar_undef_op1_nonzero_shift() {
167 ; CHECK-LABEL: @fshl_scalar_undef_op1_nonzero_shift(
168 ; CHECK-NEXT: ret i32 255
170 %f = call i32 @llvm.fshl.i32(i32 undef, i32 -1, i32 8)
174 define i32 @fshl_scalar_undef_op2_nonzero_shift() {
175 ; CHECK-LABEL: @fshl_scalar_undef_op2_nonzero_shift(
176 ; CHECK-NEXT: ret i32 -256
178 %f = call i32 @llvm.fshl.i32(i32 -1, i32 undef, i32 8)
182 define i32 @fshr_scalar_undef_op1_nonzero_shift() {
183 ; CHECK-LABEL: @fshr_scalar_undef_op1_nonzero_shift(
184 ; CHECK-NEXT: ret i32 16777215
186 %f = call i32 @llvm.fshr.i32(i32 undef, i32 -1, i32 8)
190 define i32 @fshr_scalar_undef_op2_nonzero_shift() {
191 ; CHECK-LABEL: @fshr_scalar_undef_op2_nonzero_shift(
192 ; CHECK-NEXT: ret i32 -16777216
194 %f = call i32 @llvm.fshr.i32(i32 -1, i32 undef, i32 8)
198 ; Undef/Undef/Undef; 1/2/Undef; Undef/Undef/3; Undef/1/0
199 define <4 x i8> @fshl_vector_mix1() {
200 ; CHECK-LABEL: @fshl_vector_mix1(
201 ; CHECK-NEXT: ret <4 x i8> <i8 undef, i8 1, i8 undef, i8 undef>
203 %f = call <4 x i8> @llvm.fshl.v4i8(<4 x i8> <i8 undef, i8 1, i8 undef, i8 undef>, <4 x i8> <i8 undef, i8 2, i8 undef, i8 1>, <4 x i8> <i8 undef, i8 undef, i8 3, i8 0>)
207 ; 1/Undef/8; Undef/-1/2; -1/Undef/2; 7/8/4
208 define <4 x i8> @fshl_vector_mix2() {
209 ; CHECK-LABEL: @fshl_vector_mix2(
210 ; CHECK-NEXT: ret <4 x i8> <i8 1, i8 3, i8 -4, i8 112>
212 %f = call <4 x i8> @llvm.fshl.v4i8(<4 x i8> <i8 1, i8 undef, i8 -1, i8 7>, <4 x i8> <i8 undef, i8 -1, i8 undef, i8 8>, <4 x i8> <i8 8, i8 2, i8 2, i8 4>)
216 ; Undef/Undef/Undef; 1/2/Undef; Undef/Undef/3; Undef/1/0
217 define <4 x i8> @fshr_vector_mix1() {
218 ; CHECK-LABEL: @fshr_vector_mix1(
219 ; CHECK-NEXT: ret <4 x i8> <i8 undef, i8 2, i8 undef, i8 1>
221 %f = call <4 x i8> @llvm.fshr.v4i8(<4 x i8> <i8 undef, i8 1, i8 undef, i8 undef>, <4 x i8> <i8 undef, i8 2, i8 undef, i8 1>, <4 x i8> <i8 undef, i8 undef, i8 3, i8 0>)
225 ; 1/Undef/8; Undef/-1/2; -1/Undef/2; 7/8/4
226 define <4 x i8> @fshr_vector_mix2() {
227 ; CHECK-LABEL: @fshr_vector_mix2(
228 ; CHECK-NEXT: ret <4 x i8> <i8 undef, i8 63, i8 -64, i8 112>
230 %f = call <4 x i8> @llvm.fshr.v4i8(<4 x i8> <i8 1, i8 undef, i8 -1, i8 7>, <4 x i8> <i8 undef, i8 -1, i8 undef, i8 8>, <4 x i8> <i8 8, i8 2, i8 2, i8 4>)