1 ; RUN: llc < %s -mtriple=x86_64-linux-gnu | FileCheck %s
3 ; fold (shl (zext (lshr (A, X))), X) -> (zext (shl (lshr (A, X)), X))
5 ; Canolicalize the sequence shl/zext/lshr performing the zeroextend
6 ; as the last instruction of the sequence.
7 ; This will help DAGCombiner to identify and then fold the sequence
8 ; of shifts into a single AND.
9 ; This transformation is profitable if the shift amounts are the same
10 ; and if there is only one use of the zext.
12 define i16 @fun1(i8 zeroext %v) {
15 %ext = zext i8 %shr to i16
16 %shl = shl i16 %ext, 4
26 define i32 @fun2(i8 zeroext %v) {
29 %ext = zext i8 %shr to i32
30 %shl = shl i32 %ext, 4
40 define i32 @fun3(i16 zeroext %v) {
43 %ext = zext i16 %shr to i32
44 %shl = shl i32 %ext, 4
54 define i64 @fun4(i8 zeroext %v) {
57 %ext = zext i8 %shr to i64
58 %shl = shl i64 %ext, 4
68 define i64 @fun5(i16 zeroext %v) {
71 %ext = zext i16 %shr to i64
72 %shl = shl i64 %ext, 4
82 define i64 @fun6(i32 zeroext %v) {
85 %ext = zext i32 %shr to i64
86 %shl = shl i64 %ext, 4
96 ; Don't fold the pattern if we use arithmetic shifts.
98 define i64 @fun7(i8 zeroext %v) {
101 %ext = zext i8 %shr to i64
102 %shl = shl i64 %ext, 4
111 define i64 @fun8(i16 zeroext %v) {
113 %shr = ashr i16 %v, 4
114 %ext = zext i16 %shr to i64
115 %shl = shl i64 %ext, 4
124 define i64 @fun9(i32 zeroext %v) {
126 %shr = ashr i32 %v, 4
127 %ext = zext i32 %shr to i64
128 %shl = shl i64 %ext, 4
137 ; Don't fold the pattern if there is more than one use of the
138 ; operand in input to the shift left.
140 define i64 @fun10(i8 zeroext %v) {
143 %ext = zext i8 %shr to i64
144 %shl = shl i64 %ext, 4
145 %add = add i64 %shl, %ext
149 ; CHECK-LABEL: @fun10
154 define i64 @fun11(i16 zeroext %v) {
156 %shr = lshr i16 %v, 4
157 %ext = zext i16 %shr to i64
158 %shl = shl i64 %ext, 4
159 %add = add i64 %shl, %ext
163 ; CHECK-LABEL: @fun11
168 define i64 @fun12(i32 zeroext %v) {
170 %shr = lshr i32 %v, 4
171 %ext = zext i32 %shr to i64
172 %shl = shl i64 %ext, 4
173 %add = add i64 %shl, %ext
177 ; CHECK-LABEL: @fun12
183 ; Make sure that the combined dags are legal if we run the DAGCombiner after
184 ; Legalization took place. The add instruction is redundant and increases by
185 ; one the number of uses of the zext. This prevents the transformation from
186 ; firing before dags are legalized and optimized.
187 ; Once the add is removed, the number of uses becomes one and therefore the
188 ; dags are canonicalized. After Legalization, we need to make sure that the
189 ; valuetype for the shift count is legal.
190 ; Verify also that we correctly fold the shl-shr sequence into an
193 define void @g(i32 %a) {
195 %c = zext i32 %b to i64
198 tail call void @f(i64 %e)