1 ; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=generic | FileCheck %s
3 ; Check that we recognize this idiom for rotation too:
4 ; a << (b & (OpSize-1)) | a >> ((0 - b) & (OpSize-1))
6 define i32 @rotate_left_32(i32 %a, i32 %b) {
7 ; CHECK-LABEL: rotate_left_32:
11 %shl = shl i32 %a, %and
13 %and3 = and i32 %0, 31
14 %shr = lshr i32 %a, %and3
15 %or = or i32 %shl, %shr
19 define i32 @rotate_right_32(i32 %a, i32 %b) {
20 ; CHECK-LABEL: rotate_right_32:
24 %shl = lshr i32 %a, %and
26 %and3 = and i32 %0, 31
27 %shr = shl i32 %a, %and3
28 %or = or i32 %shl, %shr
32 define i64 @rotate_left_64(i64 %a, i64 %b) {
33 ; CHECK-LABEL: rotate_left_64:
37 %shl = shl i64 %a, %and
39 %and3 = and i64 %0, 63
40 %shr = lshr i64 %a, %and3
41 %or = or i64 %shl, %shr
45 define i64 @rotate_right_64(i64 %a, i64 %b) {
46 ; CHECK-LABEL: rotate_right_64:
50 %shl = lshr i64 %a, %and
52 %and3 = and i64 %0, 63
53 %shr = shl i64 %a, %and3
54 %or = or i64 %shl, %shr
58 ; Also check mem operand.
60 define void @rotate_left_m32(i32 *%pa, i32 %b) {
61 ; CHECK-LABEL: rotate_left_m32:
66 %a = load i32* %pa, align 16
68 %shl = shl i32 %a, %and
70 %and3 = and i32 %0, 31
71 %shr = lshr i32 %a, %and3
72 %or = or i32 %shl, %shr
73 store i32 %or, i32* %pa, align 32
77 define void @rotate_right_m32(i32 *%pa, i32 %b) {
78 ; CHECK-LABEL: rotate_right_m32:
83 %a = load i32* %pa, align 16
85 %shl = lshr i32 %a, %and
87 %and3 = and i32 %0, 31
88 %shr = shl i32 %a, %and3
89 %or = or i32 %shl, %shr
90 store i32 %or, i32* %pa, align 32
94 define void @rotate_left_m64(i64 *%pa, i64 %b) {
95 ; CHECK-LABEL: rotate_left_m64:
100 %a = load i64* %pa, align 16
101 %and = and i64 %b, 63
102 %shl = shl i64 %a, %and
104 %and3 = and i64 %0, 63
105 %shr = lshr i64 %a, %and3
106 %or = or i64 %shl, %shr
107 store i64 %or, i64* %pa, align 64
111 define void @rotate_right_m64(i64 *%pa, i64 %b) {
112 ; CHECK-LABEL: rotate_right_m64:
117 %a = load i64* %pa, align 16
118 %and = and i64 %b, 63
119 %shl = lshr i64 %a, %and
121 %and3 = and i64 %0, 63
122 %shr = shl i64 %a, %and3
123 %or = or i64 %shl, %shr
124 store i64 %or, i64* %pa, align 64