1
1
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2
2
; RUN: opt < %s -instsimplify -S | FileCheck %s
3
3
4
+ declare i32 @llvm.smax.i32 (i32 , i32 )
5
+ declare <2 x i32 > @llvm.umin.v2i32 (<2 x i32 >, <2 x i32 >)
6
+
4
7
define i8 @and0 (i8 %x ) {
5
8
; CHECK-LABEL: @and0(
6
9
; CHECK-NEXT: ret i8 0
@@ -89,6 +92,23 @@ define i64 @pow2b(i32 %x) {
89
92
ret i64 %e2
90
93
}
91
94
95
+ define i32 @pow2b_max (i32 %x , i32 %y ) {
96
+ ; CHECK-LABEL: @pow2b_max(
97
+ ; CHECK-NEXT: [[SHX:%.*]] = shl i32 2, [[X:%.*]]
98
+ ; CHECK-NEXT: [[SHY:%.*]] = shl i32 32, [[Y:%.*]]
99
+ ; CHECK-NEXT: [[M:%.*]] = call i32 @llvm.smax.i32(i32 [[SHX]], i32 [[SHY]])
100
+ ; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[M]]
101
+ ; CHECK-NEXT: [[R:%.*]] = and i32 [[M]], [[NEG]]
102
+ ; CHECK-NEXT: ret i32 [[R]]
103
+ ;
104
+ %shx = shl i32 2 , %x
105
+ %shy = shl i32 32 , %y
106
+ %m = call i32 @llvm.smax.i32 (i32 %shx , i32 %shy )
107
+ %neg = sub i32 0 , %m
108
+ %r = and i32 %m , %neg
109
+ ret i32 %r
110
+ }
111
+
92
112
; Power-of-2-or-zero value has no bits in common with its decrement.
93
113
94
114
define i32 @pow2_decrement (i32 %p ) {
@@ -111,6 +131,23 @@ define <2 x i32> @pow2_decrement_commute_vec(<2 x i32> %p) {
111
131
ret <2 x i32 > %r
112
132
}
113
133
134
+ define <2 x i32 > @pow2_decrement_min_vec (<2 x i32 > %x , <2 x i32 > %y ) {
135
+ ; CHECK-LABEL: @pow2_decrement_min_vec(
136
+ ; CHECK-NEXT: [[P1:%.*]] = and <2 x i32> [[X:%.*]], <i32 2048, i32 2048>
137
+ ; CHECK-NEXT: [[P2:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[Y:%.*]]
138
+ ; CHECK-NEXT: [[M:%.*]] = call <2 x i32> @llvm.umin.v2i32(<2 x i32> [[P1]], <2 x i32> [[P2]])
139
+ ; CHECK-NEXT: [[A:%.*]] = add <2 x i32> [[M]], <i32 -1, i32 -1>
140
+ ; CHECK-NEXT: [[R:%.*]] = and <2 x i32> [[M]], [[A]]
141
+ ; CHECK-NEXT: ret <2 x i32> [[R]]
142
+ ;
143
+ %p1 = and <2 x i32 > %x , <i32 2048 , i32 2048 >
144
+ %p2 = shl <2 x i32 > <i32 1 , i32 1 >, %y
145
+ %m = call <2 x i32 > @llvm.umin.v2i32 (<2 x i32 > %p1 , <2 x i32 > %p2 )
146
+ %a = add <2 x i32 > %m , <i32 -1 , i32 -1 >
147
+ %r = and <2 x i32 > %m , %a
148
+ ret <2 x i32 > %r
149
+ }
150
+
114
151
define i1 @and_of_icmps0 (i32 %b ) {
115
152
; CHECK-LABEL: @and_of_icmps0(
116
153
; CHECK-NEXT: ret i1 false
0 commit comments