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:
12
%shl = shl i32 %a, %and
14
%and3 = and i32 %0, 31
15
%shr = lshr i32 %a, %and3
16
%or = or i32 %shl, %shr
20
define i32 @rotate_right_32(i32 %a, i32 %b) {
21
; CHECK-LABEL: rotate_right_32:
26
%shl = lshr i32 %a, %and
28
%and3 = and i32 %0, 31
29
%shr = shl i32 %a, %and3
30
%or = or i32 %shl, %shr
34
define i64 @rotate_left_64(i64 %a, i64 %b) {
35
; CHECK-LABEL: rotate_left_64:
40
%shl = shl i64 %a, %and
42
%and3 = and i64 %0, 63
43
%shr = lshr i64 %a, %and3
44
%or = or i64 %shl, %shr
48
define i64 @rotate_right_64(i64 %a, i64 %b) {
49
; CHECK-LABEL: rotate_right_64:
54
%shl = lshr i64 %a, %and
56
%and3 = and i64 %0, 63
57
%shr = shl i64 %a, %and3
58
%or = or i64 %shl, %shr
62
; Also check mem operand.
64
define void @rotate_left_m32(i32 *%pa, i32 %b) {
65
; CHECK-LABEL: rotate_left_m32:
71
%a = load i32, i32* %pa, align 16
73
%shl = shl i32 %a, %and
75
%and3 = and i32 %0, 31
76
%shr = lshr i32 %a, %and3
77
%or = or i32 %shl, %shr
78
store i32 %or, i32* %pa, align 32
82
define void @rotate_right_m32(i32 *%pa, i32 %b) {
83
; CHECK-LABEL: rotate_right_m32:
89
%a = load i32, i32* %pa, align 16
91
%shl = lshr i32 %a, %and
93
%and3 = and i32 %0, 31
94
%shr = shl i32 %a, %and3
95
%or = or i32 %shl, %shr
96
store i32 %or, i32* %pa, align 32
100
define void @rotate_left_m64(i64 *%pa, i64 %b) {
101
; CHECK-LABEL: rotate_left_m64:
107
%a = load i64, i64* %pa, align 16
108
%and = and i64 %b, 63
109
%shl = shl i64 %a, %and
111
%and3 = and i64 %0, 63
112
%shr = lshr i64 %a, %and3
113
%or = or i64 %shl, %shr
114
store i64 %or, i64* %pa, align 64
118
define void @rotate_right_m64(i64 *%pa, i64 %b) {
119
; CHECK-LABEL: rotate_right_m64:
125
%a = load i64, i64* %pa, align 16
126
%and = and i64 %b, 63
127
%shl = lshr i64 %a, %and
129
%and3 = and i64 %0, 63
130
%shr = shl i64 %a, %and3
131
%or = or i64 %shl, %shr
132
store i64 %or, i64* %pa, align 64