1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 # RUN: llc -mtriple aarch64 -run-pass=aarch64-postlegalizer-combiner -verify-machineinstrs %s -o - | FileCheck %s
4 # Check that we can fold a G_ASHR/G_LSHR fed by a G_SHL into a G_SBFX/G_UBFX.
7 name: apply_ashr_shl_to_sbfx
11 ; CHECK-LABEL: name: apply_ashr_shl_to_sbfx
12 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
13 ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 16
14 ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 11
15 ; CHECK: [[SBFX:%[0-9]+]]:_(s32) = G_SBFX [[COPY]], [[C1]](s32), [[C]]
16 ; CHECK: $w0 = COPY [[SBFX]](s32)
18 %1:_(s32) = G_CONSTANT i32 5
19 %2:_(s32) = G_CONSTANT i32 16
20 %3:_(s32) = G_SHL %0, %1
21 %4:_(s32) = G_ASHR %3, %2
26 name: apply_ashr_shl_to_sbfx_lower_bound
30 ; CHECK-LABEL: name: apply_ashr_shl_to_sbfx_lower_bound
31 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
32 ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
33 ; CHECK: [[SBFX:%[0-9]+]]:_(s32) = G_SBFX [[COPY]], [[C]](s32), [[C]]
34 ; CHECK: $w0 = COPY [[SBFX]](s32)
36 %1:_(s32) = G_CONSTANT i32 30
37 %2:_(s32) = G_CONSTANT i32 31
38 %3:_(s32) = G_SHL %0, %1
39 %4:_(s32) = G_ASHR %3, %2
44 name: apply_ashr_shl_to_sbfx_upper_bound
48 ; CHECK-LABEL: name: apply_ashr_shl_to_sbfx_upper_bound
49 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
50 ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
51 ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 30
52 ; CHECK: [[SBFX:%[0-9]+]]:_(s32) = G_SBFX [[COPY]], [[C1]](s32), [[C]]
53 ; CHECK: $w0 = COPY [[SBFX]](s32)
55 %1:_(s32) = G_CONSTANT i32 1
56 %2:_(s32) = G_CONSTANT i32 31
57 %3:_(s32) = G_SHL %0, %1
58 %4:_(s32) = G_ASHR %3, %2
63 name: apply_lshr_shl_to_ubfx
67 ; CHECK-LABEL: name: apply_lshr_shl_to_ubfx
68 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
69 ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 16
70 ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 11
71 ; CHECK: [[UBFX:%[0-9]+]]:_(s32) = G_UBFX [[COPY]], [[C1]](s32), [[C]]
72 ; CHECK: $w0 = COPY [[UBFX]](s32)
74 %1:_(s32) = G_CONSTANT i32 5
75 %2:_(s32) = G_CONSTANT i32 16
76 %3:_(s32) = G_SHL %0, %1
77 %4:_(s32) = G_LSHR %3, %2
82 name: apply_lshr_shl_to_ubfx_lower_bound
86 ; CHECK-LABEL: name: apply_lshr_shl_to_ubfx_lower_bound
87 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
88 ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
89 ; CHECK: [[UBFX:%[0-9]+]]:_(s32) = G_UBFX [[COPY]], [[C]](s32), [[C]]
90 ; CHECK: $w0 = COPY [[UBFX]](s32)
92 %1:_(s32) = G_CONSTANT i32 30
93 %2:_(s32) = G_CONSTANT i32 31
94 %3:_(s32) = G_SHL %0, %1
95 %4:_(s32) = G_LSHR %3, %2
100 name: apply_lshr_shl_to_ubfx_upper_bound
104 ; CHECK-LABEL: name: apply_lshr_shl_to_ubfx_upper_bound
105 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
106 ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
107 ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 30
108 ; CHECK: [[UBFX:%[0-9]+]]:_(s32) = G_UBFX [[COPY]], [[C1]](s32), [[C]]
109 ; CHECK: $w0 = COPY [[UBFX]](s32)
111 %1:_(s32) = G_CONSTANT i32 1
112 %2:_(s32) = G_CONSTANT i32 31
113 %3:_(s32) = G_SHL %0, %1
114 %4:_(s32) = G_LSHR %3, %2
119 name: dont_apply_pos_out_of_bounds
123 ; CHECK-LABEL: name: dont_apply_pos_out_of_bounds
124 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
125 ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 5
126 ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
127 ; CHECK: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[COPY]], [[C]](s32)
128 ; CHECK: [[ASHR:%[0-9]+]]:_(s32) = G_ASHR [[SHL]], [[C1]](s32)
129 ; CHECK: $w0 = COPY [[ASHR]](s32)
131 %1:_(s32) = G_CONSTANT i32 5
132 %2:_(s32) = G_CONSTANT i32 2
133 %3:_(s32) = G_SHL %0, %1
134 %4:_(s32) = G_ASHR %3, %2
139 name: dont_apply_no_constant
143 ; CHECK-LABEL: name: dont_apply_no_constant
144 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
145 ; CHECK: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
146 ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 2
147 ; CHECK: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[COPY]], [[COPY1]](s32)
148 ; CHECK: [[ASHR:%[0-9]+]]:_(s32) = G_ASHR [[SHL]], [[C]](s32)
149 ; CHECK: $w0 = COPY [[ASHR]](s32)
152 %2:_(s32) = G_CONSTANT i32 2
153 %3:_(s32) = G_SHL %0, %1
154 %4:_(s32) = G_ASHR %3, %2
159 name: dont_apply_more_than_one_use
163 ; CHECK-LABEL: name: dont_apply_more_than_one_use
164 ; CHECK: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
165 ; CHECK: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 5
166 ; CHECK: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 16
167 ; CHECK: [[SHL:%[0-9]+]]:_(s32) = G_SHL [[COPY]], [[C]](s32)
168 ; CHECK: [[ASHR:%[0-9]+]]:_(s32) = G_ASHR [[SHL]], [[C1]](s32)
169 ; CHECK: [[MUL:%[0-9]+]]:_(s32) = G_MUL [[SHL]], [[ASHR]]
170 ; CHECK: $w0 = COPY [[MUL]](s32)
172 %1:_(s32) = G_CONSTANT i32 5
173 %2:_(s32) = G_CONSTANT i32 16
174 %3:_(s32) = G_SHL %0, %1
175 %4:_(s32) = G_ASHR %3, %2
176 %5:_(s32) = G_MUL %3, %4