[InstSimplify] add tests for min/max intrinsic analysis; NFC

This commit is contained in:
Sanjay Patel 2021-03-24 11:19:35 -04:00
parent 91516925dd
commit a8708708cf
1 changed files with 37 additions and 0 deletions

View File

@ -1,6 +1,9 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
declare i32 @llvm.smax.i32(i32, i32)
declare <2 x i32> @llvm.umin.v2i32(<2 x i32>, <2 x i32>)
define i8 @and0(i8 %x) {
; CHECK-LABEL: @and0(
; CHECK-NEXT: ret i8 0
@ -89,6 +92,23 @@ define i64 @pow2b(i32 %x) {
ret i64 %e2
}
define i32 @pow2b_max(i32 %x, i32 %y) {
; CHECK-LABEL: @pow2b_max(
; CHECK-NEXT: [[SHX:%.*]] = shl i32 2, [[X:%.*]]
; CHECK-NEXT: [[SHY:%.*]] = shl i32 32, [[Y:%.*]]
; CHECK-NEXT: [[M:%.*]] = call i32 @llvm.smax.i32(i32 [[SHX]], i32 [[SHY]])
; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[M]]
; CHECK-NEXT: [[R:%.*]] = and i32 [[M]], [[NEG]]
; CHECK-NEXT: ret i32 [[R]]
;
%shx = shl i32 2, %x
%shy = shl i32 32, %y
%m = call i32 @llvm.smax.i32(i32 %shx, i32 %shy)
%neg = sub i32 0, %m
%r = and i32 %m, %neg
ret i32 %r
}
; Power-of-2-or-zero value has no bits in common with its decrement.
define i32 @pow2_decrement(i32 %p) {
@ -111,6 +131,23 @@ define <2 x i32> @pow2_decrement_commute_vec(<2 x i32> %p) {
ret <2 x i32> %r
}
define <2 x i32> @pow2_decrement_min_vec(<2 x i32> %x, <2 x i32> %y) {
; CHECK-LABEL: @pow2_decrement_min_vec(
; CHECK-NEXT: [[P1:%.*]] = and <2 x i32> [[X:%.*]], <i32 2048, i32 2048>
; CHECK-NEXT: [[P2:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[Y:%.*]]
; CHECK-NEXT: [[M:%.*]] = call <2 x i32> @llvm.umin.v2i32(<2 x i32> [[P1]], <2 x i32> [[P2]])
; CHECK-NEXT: [[A:%.*]] = add <2 x i32> [[M]], <i32 -1, i32 -1>
; CHECK-NEXT: [[R:%.*]] = and <2 x i32> [[M]], [[A]]
; CHECK-NEXT: ret <2 x i32> [[R]]
;
%p1 = and <2 x i32> %x, <i32 2048, i32 2048>
%p2 = shl <2 x i32> <i32 1, i32 1>, %y
%m = call <2 x i32> @llvm.umin.v2i32(<2 x i32> %p1, <2 x i32> %p2)
%a = add <2 x i32> %m, <i32 -1, i32 -1>
%r = and <2 x i32> %m, %a
ret <2 x i32> %r
}
define i1 @and_of_icmps0(i32 %b) {
; CHECK-LABEL: @and_of_icmps0(
; CHECK-NEXT: ret i1 false