1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 declare i8 @llvm.fshl.i8(i8, i8, i8)
5 declare i8 @llvm.fshr.i8(i8, i8, i8)
6 declare <2 x i5> @llvm.fshl.v2i5(<2 x i5>, <2 x i5>, <2 x i5>)
9 define i1 @rotl_eq_0(i8 %x, i8 %y) {
10 ; CHECK-LABEL: @rotl_eq_0(
11 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[X:%.*]], 0
12 ; CHECK-NEXT: ret i1 [[R]]
14 %rot = tail call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 %y)
15 %r = icmp eq i8 %rot, 0
21 define i1 @rotl_ne_0(i8 %x, i8 %y) {
22 ; CHECK-LABEL: @rotl_ne_0(
23 ; CHECK-NEXT: [[ROT:%.*]] = tail call i8 @llvm.fshl.i8(i8 [[X:%.*]], i8 [[X]], i8 [[Y:%.*]])
24 ; CHECK-NEXT: call void @use(i8 [[ROT]])
25 ; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[X]], 0
26 ; CHECK-NEXT: ret i1 [[R]]
28 %rot = tail call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 %y)
29 call void @use(i8 %rot)
30 %r = icmp ne i8 %rot, 0
34 define i1 @rotl_eq_n1(i8 %x, i8 %y) {
35 ; CHECK-LABEL: @rotl_eq_n1(
36 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[X:%.*]], -1
37 ; CHECK-NEXT: ret i1 [[R]]
39 %rot = tail call i8 @llvm.fshl.i8(i8 %x, i8 %x, i8 %y)
40 %r = icmp eq i8 %rot, -1
46 define <2 x i1> @rotl_ne_n1(<2 x i5> %x, <2 x i5> %y) {
47 ; CHECK-LABEL: @rotl_ne_n1(
48 ; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i5> [[X:%.*]], <i5 -1, i5 -1>
49 ; CHECK-NEXT: ret <2 x i1> [[R]]
51 %rot = tail call <2 x i5> @llvm.fshl.v2i5(<2 x i5>%x, <2 x i5> %x, <2 x i5> %y)
52 %r = icmp ne <2 x i5> %rot, <i5 -1, i5 -1>
56 ; TODO: We filter out vector constants with undef elts, but that isn't needed for this transform.
58 define <2 x i1> @rotl_ne_n1_undef(<2 x i5> %x, <2 x i5> %y) {
59 ; CHECK-LABEL: @rotl_ne_n1_undef(
60 ; CHECK-NEXT: [[ROT:%.*]] = tail call <2 x i5> @llvm.fshl.v2i5(<2 x i5> [[X:%.*]], <2 x i5> [[X]], <2 x i5> [[Y:%.*]])
61 ; CHECK-NEXT: [[R:%.*]] = icmp ne <2 x i5> [[ROT]], <i5 -1, i5 undef>
62 ; CHECK-NEXT: ret <2 x i1> [[R]]
64 %rot = tail call <2 x i5> @llvm.fshl.v2i5(<2 x i5>%x, <2 x i5> %x, <2 x i5> %y)
65 %r = icmp ne <2 x i5> %rot, <i5 -1, i5 undef>
69 define i1 @rotr_eq_0(i8 %x, i8 %y) {
70 ; CHECK-LABEL: @rotr_eq_0(
71 ; CHECK-NEXT: [[ROT:%.*]] = tail call i8 @llvm.fshr.i8(i8 [[X:%.*]], i8 [[X]], i8 [[Y:%.*]])
72 ; CHECK-NEXT: call void @use(i8 [[ROT]])
73 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[X]], 0
74 ; CHECK-NEXT: ret i1 [[R]]
76 %rot = tail call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 %y)
77 call void @use(i8 %rot)
78 %r = icmp eq i8 %rot, 0
82 define i1 @rotr_ne_0(i8 %x, i8 %y) {
83 ; CHECK-LABEL: @rotr_ne_0(
84 ; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[X:%.*]], 0
85 ; CHECK-NEXT: ret i1 [[R]]
87 %rot = tail call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 %y)
88 %r = icmp ne i8 %rot, 0
92 define i1 @rotr_eq_n1(i8 %x, i8 %y) {
93 ; CHECK-LABEL: @rotr_eq_n1(
94 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[X:%.*]], -1
95 ; CHECK-NEXT: ret i1 [[R]]
97 %rot = tail call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 %y)
98 %r = icmp eq i8 %rot, -1
102 define i1 @rotr_ne_n1(i8 %x, i8 %y) {
103 ; CHECK-LABEL: @rotr_ne_n1(
104 ; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[X:%.*]], -1
105 ; CHECK-NEXT: ret i1 [[R]]
107 %rot = tail call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 %y)
108 %r = icmp ne i8 %rot, -1
112 ; negative test - wrong constant value
114 define i1 @rotr_ne_1(i8 %x, i8 %y) {
115 ; CHECK-LABEL: @rotr_ne_1(
116 ; CHECK-NEXT: [[ROT:%.*]] = tail call i8 @llvm.fshr.i8(i8 [[X:%.*]], i8 [[X]], i8 [[Y:%.*]])
117 ; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[ROT]], 1
118 ; CHECK-NEXT: ret i1 [[R]]
120 %rot = tail call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 %y)
121 %r = icmp ne i8 %rot, 1
125 ; negative test - wrong predicate
127 define i1 @rotr_sgt_n1(i8 %x, i8 %y) {
128 ; CHECK-LABEL: @rotr_sgt_n1(
129 ; CHECK-NEXT: [[ROT:%.*]] = tail call i8 @llvm.fshr.i8(i8 [[X:%.*]], i8 [[X]], i8 [[Y:%.*]])
130 ; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[ROT]], -1
131 ; CHECK-NEXT: ret i1 [[R]]
133 %rot = tail call i8 @llvm.fshr.i8(i8 %x, i8 %x, i8 %y)
134 %r = icmp sgt i8 %rot, -1
138 ; negative test - must be a rotate, not general funnel shift
140 define i1 @fshr_sgt_n1(i8 %x, i8 %y, i8 %z) {
141 ; CHECK-LABEL: @fshr_sgt_n1(
142 ; CHECK-NEXT: [[FSH:%.*]] = tail call i8 @llvm.fshr.i8(i8 [[X:%.*]], i8 [[Y:%.*]], i8 [[Z:%.*]])
143 ; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[FSH]], -1
144 ; CHECK-NEXT: ret i1 [[R]]
146 %fsh = tail call i8 @llvm.fshr.i8(i8 %x, i8 %y, i8 %z)
147 %r = icmp eq i8 %fsh, -1