From a8708708cf8bf1f90fd5262c14cc12035a8dea0b Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Wed, 24 Mar 2021 11:19:35 -0400 Subject: [PATCH] [InstSimplify] add tests for min/max intrinsic analysis; NFC --- llvm/test/Transforms/InstSimplify/AndOrXor.ll | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/llvm/test/Transforms/InstSimplify/AndOrXor.ll b/llvm/test/Transforms/InstSimplify/AndOrXor.ll index e232628..9940691 100644 --- a/llvm/test/Transforms/InstSimplify/AndOrXor.ll +++ b/llvm/test/Transforms/InstSimplify/AndOrXor.ll @@ -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:%.*]], +; CHECK-NEXT: [[P2:%.*]] = shl <2 x i32> , [[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]], +; CHECK-NEXT: [[R:%.*]] = and <2 x i32> [[M]], [[A]] +; CHECK-NEXT: ret <2 x i32> [[R]] +; + %p1 = and <2 x i32> %x, + %p2 = shl <2 x i32> , %y + %m = call <2 x i32> @llvm.umin.v2i32(<2 x i32> %p1, <2 x i32> %p2) + %a = add <2 x i32> %m, + %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 -- 2.7.4