Skip to content

Commit a870870

Browse files
committed
[InstSimplify] add tests for min/max intrinsic analysis; NFC
1 parent 9151692 commit a870870

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

llvm/test/Transforms/InstSimplify/AndOrXor.ll

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
22
; RUN: opt < %s -instsimplify -S | FileCheck %s
33

4+
declare i32 @llvm.smax.i32(i32, i32)
5+
declare <2 x i32> @llvm.umin.v2i32(<2 x i32>, <2 x i32>)
6+
47
define i8 @and0(i8 %x) {
58
; CHECK-LABEL: @and0(
69
; CHECK-NEXT: ret i8 0
@@ -89,6 +92,23 @@ define i64 @pow2b(i32 %x) {
8992
ret i64 %e2
9093
}
9194

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+
92112
; Power-of-2-or-zero value has no bits in common with its decrement.
93113

94114
define i32 @pow2_decrement(i32 %p) {
@@ -111,6 +131,23 @@ define <2 x i32> @pow2_decrement_commute_vec(<2 x i32> %p) {
111131
ret <2 x i32> %r
112132
}
113133

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+
114151
define i1 @and_of_icmps0(i32 %b) {
115152
; CHECK-LABEL: @and_of_icmps0(
116153
; CHECK-NEXT: ret i1 false

0 commit comments

Comments
 (0)