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_SEXT_INREG fed by a G_ASHR/G_LSHR into a G_SBFX.
8 name: sextinreg_ashr_to_sbfx
9 tracksRegLiveness: true
14 ; CHECK-LABEL: name: sextinreg_ashr_to_sbfx
17 ; CHECK-NEXT: %x:_(s32) = COPY $w0
18 ; CHECK-NEXT: %lsb:_(s32) = G_CONSTANT i32 5
19 ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 10
20 ; CHECK-NEXT: %sext_inreg:_(s32) = G_SBFX %x, %lsb(s32), [[C]]
21 ; CHECK-NEXT: $w0 = COPY %sext_inreg(s32)
22 ; CHECK-NEXT: RET_ReallyLR implicit $w0
24 %lsb:_(s32) = G_CONSTANT i32 5
25 %shift:_(s32) = G_ASHR %x, %lsb
26 %sext_inreg:_(s32) = G_SEXT_INREG %shift, 10
27 $w0 = COPY %sext_inreg
28 RET_ReallyLR implicit $w0
32 name: sextinreg_lshr_to_sbfx
33 tracksRegLiveness: true
38 ; CHECK-LABEL: name: sextinreg_lshr_to_sbfx
41 ; CHECK-NEXT: %x:_(s32) = COPY $w0
42 ; CHECK-NEXT: %lsb:_(s32) = G_CONSTANT i32 5
43 ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 10
44 ; CHECK-NEXT: %sext_inreg:_(s32) = G_SBFX %x, %lsb(s32), [[C]]
45 ; CHECK-NEXT: $w0 = COPY %sext_inreg(s32)
46 ; CHECK-NEXT: RET_ReallyLR implicit $w0
48 %lsb:_(s32) = G_CONSTANT i32 5
49 %shift:_(s32) = G_LSHR %x, %lsb
50 %sext_inreg:_(s32) = G_SEXT_INREG %shift, 10
51 $w0 = COPY %sext_inreg
52 RET_ReallyLR implicit $w0
57 name: dont_apply_no_constant
58 tracksRegLiveness: true
63 ; AArch64 needs a constant on the shift for this combine.
65 ; CHECK-LABEL: name: dont_apply_no_constant
68 ; CHECK-NEXT: %x:_(s32) = COPY $w0
69 ; CHECK-NEXT: %y:_(s32) = COPY $w0
70 ; CHECK-NEXT: %shift:_(s32) = G_LSHR %x, %y(s32)
71 ; CHECK-NEXT: %sext_inreg:_(s32) = G_SEXT_INREG %shift, 10
72 ; CHECK-NEXT: $w0 = COPY %sext_inreg(s32)
73 ; CHECK-NEXT: RET_ReallyLR implicit $w0
76 %shift:_(s32) = G_LSHR %x, %y
77 %sext_inreg:_(s32) = G_SEXT_INREG %shift, 10
78 $w0 = COPY %sext_inreg
79 RET_ReallyLR implicit $w0
83 name: dont_apply_shift_imm_too_large
84 tracksRegLiveness: true
90 ; LSB must be in 0-31.
92 ; CHECK-LABEL: name: dont_apply_shift_imm_too_large
95 ; CHECK-NEXT: %x:_(s32) = COPY $w0
96 ; CHECK-NEXT: %lsb:_(s32) = G_CONSTANT i32 32
97 ; CHECK-NEXT: %shift:_(s32) = G_ASHR %x, %lsb(s32)
98 ; CHECK-NEXT: $w0 = COPY %shift(s32)
99 ; CHECK-NEXT: RET_ReallyLR implicit $w0
101 %lsb:_(s32) = G_CONSTANT i32 32
102 %shift:_(s32) = G_ASHR %x, %lsb
103 %sext_inreg:_(s32) = G_SEXT_INREG %shift, 1
104 $w0 = COPY %sext_inreg
105 RET_ReallyLR implicit $w0
109 name: dont_apply_negative_shift_imm
110 tracksRegLiveness: true
116 ; LSB must be in 0-31.
118 ; CHECK-LABEL: name: dont_apply_negative_shift_imm
119 ; CHECK: liveins: $w0
121 ; CHECK-NEXT: %x:_(s32) = COPY $w0
122 ; CHECK-NEXT: %lsb:_(s32) = G_CONSTANT i32 -1
123 ; CHECK-NEXT: %shift:_(s32) = G_ASHR %x, %lsb(s32)
124 ; CHECK-NEXT: $w0 = COPY %shift(s32)
125 ; CHECK-NEXT: RET_ReallyLR implicit $w0
127 %lsb:_(s32) = G_CONSTANT i32 -1
128 %shift:_(s32) = G_ASHR %x, %lsb
129 %sext_inreg:_(s32) = G_SEXT_INREG %shift, 1
130 $w0 = COPY %sext_inreg
131 RET_ReallyLR implicit $w0
135 name: dont_apply_more_than_one_use
136 tracksRegLiveness: true
141 ; CHECK-LABEL: name: dont_apply_more_than_one_use
142 ; CHECK: liveins: $w0
144 ; CHECK-NEXT: %x:_(s32) = COPY $w0
145 ; CHECK-NEXT: %lsb:_(s32) = G_CONSTANT i32 1
146 ; CHECK-NEXT: %shift:_(s32) = G_ASHR %x, %lsb(s32)
147 ; CHECK-NEXT: %sext_inreg:_(s32) = G_SEXT_INREG %shift, 1
148 ; CHECK-NEXT: %mul:_(s32) = G_MUL %shift, %sext_inreg
149 ; CHECK-NEXT: $w0 = COPY %mul(s32)
150 ; CHECK-NEXT: RET_ReallyLR implicit $w0
152 %lsb:_(s32) = G_CONSTANT i32 1
153 %shift:_(s32) = G_ASHR %x, %lsb
154 %sext_inreg:_(s32) = G_SEXT_INREG %shift, 1
155 %mul:_(s32) = G_MUL %shift, %sext_inreg
157 RET_ReallyLR implicit $w0