1 ; Check that (or (shl x, y), (srl x, (sub 32, y))) is folded into (rotl x, y)
2 ; and (or (shl x, (sub 32, y)), (srl x, r)) into (rotr x, y) even if the
3 ; argument is zero extended. Fix for PR16726.
5 ; RUN: llc < %s -march=x86-64 -mcpu=corei7 | FileCheck %s
7 define zeroext i8 @rolbyte(i32 %nBits_arg, i8 %x_arg) nounwind readnone {
9 %tmp1 = zext i8 %x_arg to i32
10 %tmp3 = shl i32 %tmp1, %nBits_arg
11 %tmp8 = sub i32 8, %nBits_arg
12 %tmp10 = lshr i32 %tmp1, %tmp8
13 %tmp11 = or i32 %tmp3, %tmp10
14 %tmp12 = trunc i32 %tmp11 to i8
17 ; CHECK: rolb %cl, %{{[a-z0-9]+}}
20 define zeroext i8 @rorbyte(i32 %nBits_arg, i8 %x_arg) nounwind readnone {
22 %tmp1 = zext i8 %x_arg to i32
23 %tmp3 = lshr i32 %tmp1, %nBits_arg
24 %tmp8 = sub i32 8, %nBits_arg
25 %tmp10 = shl i32 %tmp1, %tmp8
26 %tmp11 = or i32 %tmp3, %tmp10
27 %tmp12 = trunc i32 %tmp11 to i8
30 ; CHECK: rorb %cl, %{{[a-z0-9]+}}
32 define zeroext i16 @rolword(i32 %nBits_arg, i16 %x_arg) nounwind readnone {
34 %tmp1 = zext i16 %x_arg to i32
35 %tmp3 = shl i32 %tmp1, %nBits_arg
36 %tmp8 = sub i32 16, %nBits_arg
37 %tmp10 = lshr i32 %tmp1, %tmp8
38 %tmp11 = or i32 %tmp3, %tmp10
39 %tmp12 = trunc i32 %tmp11 to i16
42 ; CHECK: rolw %cl, %{{[a-z0-9]+}}
44 define zeroext i16 @rorword(i32 %nBits_arg, i16 %x_arg) nounwind readnone {
46 %tmp1 = zext i16 %x_arg to i32
47 %tmp3 = lshr i32 %tmp1, %nBits_arg
48 %tmp8 = sub i32 16, %nBits_arg
49 %tmp10 = shl i32 %tmp1, %tmp8
50 %tmp11 = or i32 %tmp3, %tmp10
51 %tmp12 = trunc i32 %tmp11 to i16
54 ; CHECK: rorw %cl, %{{[a-z0-9]+}}
56 define i64 @roldword(i64 %nBits_arg, i32 %x_arg) nounwind readnone {
58 %tmp1 = zext i32 %x_arg to i64
59 %tmp3 = shl i64 %tmp1, %nBits_arg
60 %tmp8 = sub i64 32, %nBits_arg
61 %tmp10 = lshr i64 %tmp1, %tmp8
62 %tmp11 = or i64 %tmp3, %tmp10
65 ; CHECK: roll %cl, %{{[a-z0-9]+}}
67 define zeroext i64 @rordword(i64 %nBits_arg, i32 %x_arg) nounwind readnone {
69 %tmp1 = zext i32 %x_arg to i64
70 %tmp3 = lshr i64 %tmp1, %nBits_arg
71 %tmp8 = sub i64 32, %nBits_arg
72 %tmp10 = shl i64 %tmp1, %tmp8
73 %tmp11 = or i64 %tmp3, %tmp10
76 ; CHECK: rorl %cl, %{{[a-z0-9]+}}