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

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 24 09:22:12 PDT 2021


Author: Sanjay Patel
Date: 2021-03-24T12:21:59-04:00
New Revision: a8708708cf8bf1f90fd5262c14cc12035a8dea0b

URL: https://github.com/llvm/llvm-project/commit/a8708708cf8bf1f90fd5262c14cc12035a8dea0b
DIFF: https://github.com/llvm/llvm-project/commit/a8708708cf8bf1f90fd5262c14cc12035a8dea0b.diff

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

Added: 
    

Modified: 
    llvm/test/Transforms/InstSimplify/AndOrXor.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstSimplify/AndOrXor.ll b/llvm/test/Transforms/InstSimplify/AndOrXor.ll
index e23262835c3cf..9940691453146 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:%.*]], <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


        


More information about the llvm-commits mailing list