3 ; RUN: llc < %s -mtriple=x86_64-linux-gnu | FileCheck %s
5 ; fold (shl (zext (lshr (A, X))), X) -> (zext (shl (lshr (A, X)), X))
7 ; Canolicalize the sequence shl/zext/lshr performing the zeroextend
8 ; as the last instruction of the sequence.
9 ; This will help DAGCombiner to identify and then fold the sequence
10 ; of shifts into a single AND.
11 ; This transformation is profitable if the shift amounts are the same
12 ; and if there is only one use of the zext.
14 define i16 @fun1(i8 zeroext %v) {
17 %ext = zext i8 %shr to i16
18 %shl = shl i16 %ext, 4
28 define i32 @fun2(i8 zeroext %v) {
31 %ext = zext i8 %shr to i32
32 %shl = shl i32 %ext, 4
42 define i32 @fun3(i16 zeroext %v) {
45 %ext = zext i16 %shr to i32
46 %shl = shl i32 %ext, 4
56 define i64 @fun4(i8 zeroext %v) {
59 %ext = zext i8 %shr to i64
60 %shl = shl i64 %ext, 4
70 define i64 @fun5(i16 zeroext %v) {
73 %ext = zext i16 %shr to i64
74 %shl = shl i64 %ext, 4
84 define i64 @fun6(i32 zeroext %v) {
87 %ext = zext i32 %shr to i64
88 %shl = shl i64 %ext, 4
98 ; Don't fold the pattern if we use arithmetic shifts.
100 define i64 @fun7(i8 zeroext %v) {
103 %ext = zext i8 %shr to i64
104 %shl = shl i64 %ext, 4
113 define i64 @fun8(i16 zeroext %v) {
115 %shr = ashr i16 %v, 4
116 %ext = zext i16 %shr to i64
117 %shl = shl i64 %ext, 4
126 define i64 @fun9(i32 zeroext %v) {
128 %shr = ashr i32 %v, 4
129 %ext = zext i32 %shr to i64
130 %shl = shl i64 %ext, 4
139 ; Don't fold the pattern if there is more than one use of the
140 ; operand in input to the shift left.
142 define i64 @fun10(i8 zeroext %v) {
145 %ext = zext i8 %shr to i64
146 %shl = shl i64 %ext, 4
147 %add = add i64 %shl, %ext
151 ; CHECK-LABEL: @fun10
156 define i64 @fun11(i16 zeroext %v) {
158 %shr = lshr i16 %v, 4
159 %ext = zext i16 %shr to i64
160 %shl = shl i64 %ext, 4
161 %add = add i64 %shl, %ext
165 ; CHECK-LABEL: @fun11
170 define i64 @fun12(i32 zeroext %v) {
172 %shr = lshr i32 %v, 4
173 %ext = zext i32 %shr to i64
174 %shl = shl i64 %ext, 4
175 %add = add i64 %shl, %ext
179 ; CHECK-LABEL: @fun12
185 ; Make sure that the combined dags are legal if we run the DAGCombiner after
186 ; Legalization took place. The add instruction is redundant and increases by
187 ; one the number of uses of the zext. This prevents the transformation from
188 ; firing before dags are legalized and optimized.
189 ; Once the add is removed, the number of uses becomes one and therefore the
190 ; dags are canonicalized. After Legalization, we need to make sure that the
191 ; valuetype for the shift count is legal.
193 define void @g(i32 %a) {
195 %c = zext i32 %b to i64
198 tail call void @f(i64 %e)