[llvm-branch-commits] [llvm] ba04851 - [InstSimplify] add tests for min/max idioms; NFC

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Aug 16 11:35:56 PDT 2021


Author: Sanjay Patel
Date: 2021-08-16T11:35:24-07:00
New Revision: ba048518e08fcb227359fae94da2a10dd37d2139

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

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

(cherry picked from commit 9b942a545cb53d4bae2071a2dea513be74f68221)

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/InstSimplify/maxmin.ll b/llvm/test/Transforms/InstSimplify/maxmin.ll
index 3fcbfec2f63ad..e9fff33f63114 100644
--- a/llvm/test/Transforms/InstSimplify/maxmin.ll
+++ b/llvm/test/Transforms/InstSimplify/maxmin.ll
@@ -1,9 +1,75 @@
-; NOTE: Assertions have been autogenerated by update_test_checks.py
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
 ; RUN: opt < %s -instsimplify -S | FileCheck %s
 
+define i8 @smax_min_limit(i8 %x) {
+; CHECK-LABEL: @smax_min_limit(
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -128
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i8 [[X]], i8 -128
+; CHECK-NEXT:    ret i8 [[SEL]]
+;
+  %cmp = icmp sgt i8 %x, -128
+  %sel = select i1 %cmp, i8 %x, i8 -128
+  ret i8 %sel
+}
+
+define i8 @smin_max_limit(i8 %x) {
+; CHECK-LABEL: @smin_max_limit(
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 127
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i8 [[X]], i8 127
+; CHECK-NEXT:    ret i8 [[SEL]]
+;
+  %cmp = icmp slt i8 %x, 127
+  %sel = select i1 %cmp, i8 %x, i8 127
+  ret i8 %sel
+}
+
+define <2 x i8> @umax_min_limit(<2 x i8> %x) {
+; CHECK-LABEL: @umax_min_limit(
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ugt <2 x i8> [[X:%.*]], zeroinitializer
+; CHECK-NEXT:    [[SEL:%.*]] = select <2 x i1> [[CMP]], <2 x i8> [[X]], <2 x i8> zeroinitializer
+; CHECK-NEXT:    ret <2 x i8> [[SEL]]
+;
+  %cmp = icmp ugt <2 x i8> %x, zeroinitializer
+  %sel = select <2 x i1> %cmp, <2 x i8> %x, <2 x i8> zeroinitializer
+  ret <2 x i8> %sel
+}
+
+define i8 @umin_max_limit(i8 %x) {
+; CHECK-LABEL: @umin_max_limit(
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i8 [[X:%.*]], -1
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i8 [[X]], i8 -1
+; CHECK-NEXT:    ret i8 [[SEL]]
+;
+  %cmp = icmp ult i8 %x, 255
+  %sel = select i1 %cmp, i8 %x, i8 255
+  ret i8 %sel
+}
+
+define i8 @smax_not_min_limit(i8 %x) {
+; CHECK-LABEL: @smax_not_min_limit(
+; CHECK-NEXT:    [[CMP:%.*]] = icmp sgt i8 [[X:%.*]], -127
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i8 [[X]], i8 -127
+; CHECK-NEXT:    ret i8 [[SEL]]
+;
+  %cmp = icmp sgt i8 %x, -127
+  %sel = select i1 %cmp, i8 %x, i8 -127
+  ret i8 %sel
+}
+
+define i8 @smin_not_min_limit(i8 %x) {
+; CHECK-LABEL: @smin_not_min_limit(
+; CHECK-NEXT:    [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP]], i8 [[X]], i8 0
+; CHECK-NEXT:    ret i8 [[SEL]]
+;
+  %cmp = icmp slt i8 %x, 0
+  %sel = select i1 %cmp, i8 %x, i8 0
+  ret i8 %sel
+}
+
 define i1 @max1(i32 %x, i32 %y) {
 ; CHECK-LABEL: @max1(
-; CHECK:         ret i1 false
+; CHECK-NEXT:    ret i1 false
 ;
   %c = icmp sgt i32 %x, %y
   %m = select i1 %c, i32 %x, i32 %y
@@ -13,7 +79,7 @@ define i1 @max1(i32 %x, i32 %y) {
 
 define i1 @max2(i32 %x, i32 %y) {
 ; CHECK-LABEL: @max2(
-; CHECK:         ret i1 true
+; CHECK-NEXT:    ret i1 true
 ;
   %c = icmp sge i32 %x, %y
   %m = select i1 %c, i32 %x, i32 %y
@@ -23,7 +89,7 @@ define i1 @max2(i32 %x, i32 %y) {
 
 define i1 @max3(i32 %x, i32 %y) {
 ; CHECK-LABEL: @max3(
-; CHECK:         ret i1 false
+; CHECK-NEXT:    ret i1 false
 ;
   %c = icmp ugt i32 %x, %y
   %m = select i1 %c, i32 %x, i32 %y
@@ -33,7 +99,7 @@ define i1 @max3(i32 %x, i32 %y) {
 
 define i1 @max4(i32 %x, i32 %y) {
 ; CHECK-LABEL: @max4(
-; CHECK:         ret i1 true
+; CHECK-NEXT:    ret i1 true
 ;
   %c = icmp uge i32 %x, %y
   %m = select i1 %c, i32 %x, i32 %y
@@ -43,7 +109,7 @@ define i1 @max4(i32 %x, i32 %y) {
 
 define i1 @max5(i32 %x, i32 %y) {
 ; CHECK-LABEL: @max5(
-; CHECK:         ret i1 false
+; CHECK-NEXT:    ret i1 false
 ;
   %c = icmp sgt i32 %x, %y
   %m = select i1 %c, i32 %x, i32 %y
@@ -53,7 +119,7 @@ define i1 @max5(i32 %x, i32 %y) {
 
 define i1 @max6(i32 %x, i32 %y) {
 ; CHECK-LABEL: @max6(
-; CHECK:         ret i1 true
+; CHECK-NEXT:    ret i1 true
 ;
   %c = icmp sge i32 %x, %y
   %m = select i1 %c, i32 %x, i32 %y
@@ -63,7 +129,7 @@ define i1 @max6(i32 %x, i32 %y) {
 
 define i1 @max7(i32 %x, i32 %y) {
 ; CHECK-LABEL: @max7(
-; CHECK:         ret i1 false
+; CHECK-NEXT:    ret i1 false
 ;
   %c = icmp ugt i32 %x, %y
   %m = select i1 %c, i32 %x, i32 %y
@@ -73,7 +139,7 @@ define i1 @max7(i32 %x, i32 %y) {
 
 define i1 @max8(i32 %x, i32 %y) {
 ; CHECK-LABEL: @max8(
-; CHECK:         ret i1 true
+; CHECK-NEXT:    ret i1 true
 ;
   %c = icmp uge i32 %x, %y
   %m = select i1 %c, i32 %x, i32 %y
@@ -83,7 +149,7 @@ define i1 @max8(i32 %x, i32 %y) {
 
 define i1 @min1(i32 %x, i32 %y) {
 ; CHECK-LABEL: @min1(
-; CHECK:         ret i1 false
+; CHECK-NEXT:    ret i1 false
 ;
   %c = icmp sgt i32 %x, %y
   %m = select i1 %c, i32 %y, i32 %x
@@ -93,7 +159,7 @@ define i1 @min1(i32 %x, i32 %y) {
 
 define i1 @min2(i32 %x, i32 %y) {
 ; CHECK-LABEL: @min2(
-; CHECK:         ret i1 true
+; CHECK-NEXT:    ret i1 true
 ;
   %c = icmp sge i32 %x, %y
   %m = select i1 %c, i32 %y, i32 %x
@@ -103,7 +169,7 @@ define i1 @min2(i32 %x, i32 %y) {
 
 define i1 @min3(i32 %x, i32 %y) {
 ; CHECK-LABEL: @min3(
-; CHECK:         ret i1 false
+; CHECK-NEXT:    ret i1 false
 ;
   %c = icmp ugt i32 %x, %y
   %m = select i1 %c, i32 %y, i32 %x
@@ -113,7 +179,7 @@ define i1 @min3(i32 %x, i32 %y) {
 
 define i1 @min4(i32 %x, i32 %y) {
 ; CHECK-LABEL: @min4(
-; CHECK:         ret i1 true
+; CHECK-NEXT:    ret i1 true
 ;
   %c = icmp uge i32 %x, %y
   %m = select i1 %c, i32 %y, i32 %x
@@ -123,7 +189,7 @@ define i1 @min4(i32 %x, i32 %y) {
 
 define i1 @min5(i32 %x, i32 %y) {
 ; CHECK-LABEL: @min5(
-; CHECK:         ret i1 false
+; CHECK-NEXT:    ret i1 false
 ;
   %c = icmp sgt i32 %x, %y
   %m = select i1 %c, i32 %y, i32 %x
@@ -133,7 +199,7 @@ define i1 @min5(i32 %x, i32 %y) {
 
 define i1 @min6(i32 %x, i32 %y) {
 ; CHECK-LABEL: @min6(
-; CHECK:         ret i1 true
+; CHECK-NEXT:    ret i1 true
 ;
   %c = icmp sge i32 %x, %y
   %m = select i1 %c, i32 %y, i32 %x
@@ -143,7 +209,7 @@ define i1 @min6(i32 %x, i32 %y) {
 
 define i1 @min7(i32 %x, i32 %y) {
 ; CHECK-LABEL: @min7(
-; CHECK:         ret i1 false
+; CHECK-NEXT:    ret i1 false
 ;
   %c = icmp ugt i32 %x, %y
   %m = select i1 %c, i32 %y, i32 %x
@@ -153,7 +219,7 @@ define i1 @min7(i32 %x, i32 %y) {
 
 define i1 @min8(i32 %x, i32 %y) {
 ; CHECK-LABEL: @min8(
-; CHECK:         ret i1 true
+; CHECK-NEXT:    ret i1 true
 ;
   %c = icmp uge i32 %x, %y
   %m = select i1 %c, i32 %y, i32 %x
@@ -163,7 +229,7 @@ define i1 @min8(i32 %x, i32 %y) {
 
 define i1 @maxmin1(i32 %x, i32 %y, i32 %z) {
 ; CHECK-LABEL: @maxmin1(
-; CHECK:         ret i1 true
+; CHECK-NEXT:    ret i1 true
 ;
   %c1 = icmp sge i32 %x, %y
   %max = select i1 %c1, i32 %x, i32 %y
@@ -175,7 +241,7 @@ define i1 @maxmin1(i32 %x, i32 %y, i32 %z) {
 
 define i1 @maxmin2(i32 %x, i32 %y, i32 %z) {
 ; CHECK-LABEL: @maxmin2(
-; CHECK:         ret i1 false
+; CHECK-NEXT:    ret i1 false
 ;
   %c1 = icmp sge i32 %x, %y
   %max = select i1 %c1, i32 %x, i32 %y
@@ -187,7 +253,7 @@ define i1 @maxmin2(i32 %x, i32 %y, i32 %z) {
 
 define i1 @maxmin3(i32 %x, i32 %y, i32 %z) {
 ; CHECK-LABEL: @maxmin3(
-; CHECK:         ret i1 true
+; CHECK-NEXT:    ret i1 true
 ;
   %c1 = icmp sge i32 %x, %y
   %max = select i1 %c1, i32 %x, i32 %y
@@ -199,7 +265,7 @@ define i1 @maxmin3(i32 %x, i32 %y, i32 %z) {
 
 define i1 @maxmin4(i32 %x, i32 %y, i32 %z) {
 ; CHECK-LABEL: @maxmin4(
-; CHECK:         ret i1 false
+; CHECK-NEXT:    ret i1 false
 ;
   %c1 = icmp sge i32 %x, %y
   %max = select i1 %c1, i32 %x, i32 %y
@@ -211,7 +277,7 @@ define i1 @maxmin4(i32 %x, i32 %y, i32 %z) {
 
 define i1 @maxmin5(i32 %x, i32 %y, i32 %z) {
 ; CHECK-LABEL: @maxmin5(
-; CHECK:         ret i1 true
+; CHECK-NEXT:    ret i1 true
 ;
   %c1 = icmp uge i32 %x, %y
   %max = select i1 %c1, i32 %x, i32 %y
@@ -223,7 +289,7 @@ define i1 @maxmin5(i32 %x, i32 %y, i32 %z) {
 
 define i1 @maxmin6(i32 %x, i32 %y, i32 %z) {
 ; CHECK-LABEL: @maxmin6(
-; CHECK:         ret i1 false
+; CHECK-NEXT:    ret i1 false
 ;
   %c1 = icmp uge i32 %x, %y
   %max = select i1 %c1, i32 %x, i32 %y
@@ -235,7 +301,7 @@ define i1 @maxmin6(i32 %x, i32 %y, i32 %z) {
 
 define i1 @maxmin7(i32 %x, i32 %y, i32 %z) {
 ; CHECK-LABEL: @maxmin7(
-; CHECK:         ret i1 true
+; CHECK-NEXT:    ret i1 true
 ;
   %c1 = icmp uge i32 %x, %y
   %max = select i1 %c1, i32 %x, i32 %y
@@ -247,7 +313,7 @@ define i1 @maxmin7(i32 %x, i32 %y, i32 %z) {
 
 define i1 @maxmin8(i32 %x, i32 %y, i32 %z) {
 ; CHECK-LABEL: @maxmin8(
-; CHECK:         ret i1 false
+; CHECK-NEXT:    ret i1 false
 ;
   %c1 = icmp uge i32 %x, %y
   %max = select i1 %c1, i32 %x, i32 %y
@@ -259,7 +325,7 @@ define i1 @maxmin8(i32 %x, i32 %y, i32 %z) {
 
 define i1 @eqcmp1(i32 %x, i32 %y) {
 ; CHECK-LABEL: @eqcmp1(
-; CHECK:         [[C:%.*]] = icmp sge i32 %x, %y
+; CHECK-NEXT:    [[C:%.*]] = icmp sge i32 [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:    ret i1 [[C]]
 ;
   %c = icmp sge i32 %x, %y
@@ -270,7 +336,7 @@ define i1 @eqcmp1(i32 %x, i32 %y) {
 
 define i1 @eqcmp2(i32 %x, i32 %y) {
 ; CHECK-LABEL: @eqcmp2(
-; CHECK:         [[C:%.*]] = icmp sge i32 %x, %y
+; CHECK-NEXT:    [[C:%.*]] = icmp sge i32 [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:    ret i1 [[C]]
 ;
   %c = icmp sge i32 %x, %y
@@ -281,7 +347,7 @@ define i1 @eqcmp2(i32 %x, i32 %y) {
 
 define i1 @eqcmp3(i32 %x, i32 %y) {
 ; CHECK-LABEL: @eqcmp3(
-; CHECK:         [[C:%.*]] = icmp uge i32 %x, %y
+; CHECK-NEXT:    [[C:%.*]] = icmp uge i32 [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:    ret i1 [[C]]
 ;
   %c = icmp uge i32 %x, %y
@@ -292,7 +358,7 @@ define i1 @eqcmp3(i32 %x, i32 %y) {
 
 define i1 @eqcmp4(i32 %x, i32 %y) {
 ; CHECK-LABEL: @eqcmp4(
-; CHECK:         [[C:%.*]] = icmp uge i32 %x, %y
+; CHECK-NEXT:    [[C:%.*]] = icmp uge i32 [[X:%.*]], [[Y:%.*]]
 ; CHECK-NEXT:    ret i1 [[C]]
 ;
   %c = icmp uge i32 %x, %y


        


More information about the llvm-branch-commits mailing list