PR16726: extend rol/ror matching
[oota-llvm.git] / test / CodeGen / X86 / rotate3.ll
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.
4
5 ; RUN: llc < %s -march=x86-64 -mcpu=corei7 | FileCheck %s
6
7 define zeroext i8 @rolbyte(i32 %nBits_arg, i8 %x_arg) nounwind readnone {
8 entry:
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
15   ret i8 %tmp12
16 }
17 ; CHECK:    rolb %cl, %{{[a-z0-9]+}}
18
19
20 define zeroext i8 @rorbyte(i32 %nBits_arg, i8 %x_arg) nounwind readnone {
21 entry:
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
28   ret i8 %tmp12
29 }
30 ; CHECK:    rorb %cl, %{{[a-z0-9]+}}
31
32 define zeroext i16 @rolword(i32 %nBits_arg, i16 %x_arg) nounwind readnone {
33 entry:
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
40   ret i16 %tmp12
41 }
42 ; CHECK:    rolw %cl, %{{[a-z0-9]+}}
43
44 define zeroext i16 @rorword(i32 %nBits_arg, i16 %x_arg) nounwind readnone {
45 entry:
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
52   ret i16 %tmp12
53 }
54 ; CHECK:    rorw %cl, %{{[a-z0-9]+}}
55
56 define i64 @roldword(i64 %nBits_arg, i32 %x_arg) nounwind readnone {
57 entry:
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
63   ret i64 %tmp11
64 }
65 ; CHECK:    roll %cl, %{{[a-z0-9]+}}
66
67 define zeroext i64 @rordword(i64 %nBits_arg, i32 %x_arg) nounwind readnone {
68 entry:
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
74   ret i64 %tmp11
75 }
76 ; CHECK:    rorl %cl, %{{[a-z0-9]+}}