[llvm] r285414 - [InstCombine] move/add tests for smin/smax folds
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 28 09:54:03 PDT 2016
Author: spatel
Date: Fri Oct 28 11:54:03 2016
New Revision: 285414
URL: http://llvm.org/viewvc/llvm-project?rev=285414&view=rev
Log:
[InstCombine] move/add tests for smin/smax folds
Modified:
llvm/trunk/test/Transforms/InstCombine/max-of-nots.ll
llvm/trunk/test/Transforms/InstCombine/select.ll
Modified: llvm/trunk/test/Transforms/InstCombine/max-of-nots.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/max-of-nots.ll?rev=285414&r1=285413&r2=285414&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/max-of-nots.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/max-of-nots.ll Fri Oct 28 11:54:03 2016
@@ -124,3 +124,82 @@ define <2 x i37> @max_of_nots_weird_type
ret <2 x i37> %smax96
}
+; max(min(%a, -1), -1) == -1
+define i32 @max_of_min(i32 %a) {
+; CHECK-LABEL: @max_of_min(
+; CHECK-NEXT: ret i32 -1
+;
+ %not_a = xor i32 %a, -1
+ %c0 = icmp sgt i32 %a, 0
+ %s0 = select i1 %c0, i32 %not_a, i32 -1
+ %c1 = icmp sgt i32 %s0, -1
+ %s1 = select i1 %c1, i32 %s0, i32 -1
+ ret i32 %s1
+}
+
+; max(min(%a, -1), -1) == -1 (swap predicate and select ops)
+define i32 @max_of_min_swap(i32 %a) {
+; CHECK-LABEL: @max_of_min_swap(
+; CHECK-NEXT: [[NOT_A:%.*]] = xor i32 %a, -1
+; CHECK-NEXT: [[C0:%.*]] = icmp slt i32 %a, 0
+; CHECK-NEXT: [[S0:%.*]] = select i1 [[C0]], i32 -1, i32 [[NOT_A]]
+; CHECK-NEXT: [[C1:%.*]] = icmp sgt i32 [[S0]], -1
+; CHECK-NEXT: [[S1:%.*]] = select i1 [[C1]], i32 [[S0]], i32 -1
+; CHECK-NEXT: ret i32 [[S1]]
+;
+ %not_a = xor i32 %a, -1
+ %c0 = icmp slt i32 %a, 0
+ %s0 = select i1 %c0, i32 -1, i32 %not_a
+ %c1 = icmp sgt i32 %s0, -1
+ %s1 = select i1 %c1, i32 %s0, i32 -1
+ ret i32 %s1
+}
+
+; min(max(%a, -1), -1) == -1
+define i32 @min_of_max(i32 %a) {
+; CHECK-LABEL: @min_of_max(
+; CHECK-NEXT: [[NOT_A:%.*]] = xor i32 %a, -1
+; CHECK-NEXT: [[C0:%.*]] = icmp slt i32 %a, 0
+; CHECK-NEXT: [[S0:%.*]] = select i1 [[C0]], i32 [[NOT_A]], i32 -1
+; CHECK-NEXT: [[C1:%.*]] = icmp slt i32 [[S0]], -1
+; CHECK-NEXT: [[S1:%.*]] = select i1 [[C1]], i32 [[S0]], i32 -1
+; CHECK-NEXT: ret i32 [[S1]]
+;
+ %not_a = xor i32 %a, -1
+ %c0 = icmp slt i32 %a, 0
+ %s0 = select i1 %c0, i32 %not_a, i32 -1
+ %c1 = icmp slt i32 %s0, -1
+ %s1 = select i1 %c1, i32 %s0, i32 -1
+ ret i32 %s1
+}
+
+; min(max(%a, -1), -1) == -1 (swap predicate and select ops)
+define i32 @min_of_max_swap(i32 %a) {
+; CHECK-LABEL: @min_of_max_swap(
+; CHECK-NEXT: [[NOT_A:%.*]] = xor i32 %a, -1
+; CHECK-NEXT: [[C0:%.*]] = icmp sgt i32 %a, 0
+; CHECK-NEXT: [[S0:%.*]] = select i1 [[C0]], i32 -1, i32 [[NOT_A]]
+; CHECK-NEXT: [[C1:%.*]] = icmp slt i32 [[S0]], -1
+; CHECK-NEXT: [[S1:%.*]] = select i1 [[C1]], i32 [[S0]], i32 -1
+; CHECK-NEXT: ret i32 [[S1]]
+;
+ %not_a = xor i32 %a, -1
+ %c0 = icmp sgt i32 %a, 0
+ %s0 = select i1 %c0, i32 -1, i32 %not_a
+ %c1 = icmp slt i32 %s0, -1
+ %s1 = select i1 %c1, i32 %s0, i32 -1
+ ret i32 %s1
+}
+
+define <2 x i32> @max_of_min_vec(<2 x i32> %a) {
+; CHECK-LABEL: @max_of_min_vec(
+; CHECK-NEXT: ret <2 x i32> <i32 -1, i32 -1>
+;
+ %not_a = xor <2 x i32> %a, <i32 -1, i32 -1>
+ %c0 = icmp sgt <2 x i32> %a, zeroinitializer
+ %s0 = select <2 x i1> %c0, <2 x i32> %not_a, <2 x i32> <i32 -1, i32 -1>
+ %c1 = icmp sgt <2 x i32> %s0, <i32 -1, i32 -1>
+ %s1 = select <2 x i1> %c1, <2 x i32> %s0, <2 x i32> <i32 -1, i32 -1>
+ ret <2 x i32> %s1
+}
+
Modified: llvm/trunk/test/Transforms/InstCombine/select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/select.ll?rev=285414&r1=285413&r2=285414&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/select.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/select.ll Fri Oct 28 11:54:03 2016
@@ -1753,31 +1753,6 @@ define i32 @test_select_select1(i32 %a,
ret i32 %s1
}
-; MAX(MIN(%a, -1), -1) == -1
-define i32 @test_max_of_min(i32 %a) {
-; CHECK-LABEL: @test_max_of_min(
-; CHECK-NEXT: ret i32 -1
-;
- %not_a = xor i32 %a, -1
- %c0 = icmp sgt i32 %a, 0
- %s0 = select i1 %c0, i32 %not_a, i32 -1
- %c1 = icmp sgt i32 %s0, -1
- %s1 = select i1 %c1, i32 %s0, i32 -1
- ret i32 %s1
-}
-
-define <2 x i32> @test_max_of_min_vec(<2 x i32> %a) {
-; CHECK-LABEL: @test_max_of_min_vec(
-; CHECK-NEXT: ret <2 x i32> <i32 -1, i32 -1>
-;
- %not_a = xor <2 x i32> %a, <i32 -1, i32 -1>
- %c0 = icmp sgt <2 x i32> %a, zeroinitializer
- %s0 = select <2 x i1> %c0, <2 x i32> %not_a, <2 x i32> <i32 -1, i32 -1>
- %c1 = icmp sgt <2 x i32> %s0, <i32 -1, i32 -1>
- %s1 = select <2 x i1> %c1, <2 x i32> %s0, <2 x i32> <i32 -1, i32 -1>
- ret <2 x i32> %s1
-}
-
define i32 @PR23757(i32 %x) {
; CHECK-LABEL: @PR23757
; CHECK: %[[cmp:.*]] = icmp eq i32 %x, 2147483647
More information about the llvm-commits
mailing list