From 19ace1d548c0f9663eaec5c16e6b04a576610e86 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Fri, 28 Oct 2016 16:54:03 +0000 Subject: [PATCH] [InstCombine] move/add tests for smin/smax folds llvm-svn: 285414 --- llvm/test/Transforms/InstCombine/max-of-nots.ll | 79 +++++++++++++++++++++++++ llvm/test/Transforms/InstCombine/select.ll | 25 -------- 2 files changed, 79 insertions(+), 25 deletions(-) diff --git a/llvm/test/Transforms/InstCombine/max-of-nots.ll b/llvm/test/Transforms/InstCombine/max-of-nots.ll index d9a13e5..4ef0b83 100644 --- a/llvm/test/Transforms/InstCombine/max-of-nots.ll +++ b/llvm/test/Transforms/InstCombine/max-of-nots.ll @@ -124,3 +124,82 @@ define <2 x i37> @max_of_nots_weird_type_vec(<2 x i37> %x, <2 x i37> %y) { 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> +; + %not_a = xor <2 x i32> %a, + %c0 = icmp sgt <2 x i32> %a, zeroinitializer + %s0 = select <2 x i1> %c0, <2 x i32> %not_a, <2 x i32> + %c1 = icmp sgt <2 x i32> %s0, + %s1 = select <2 x i1> %c1, <2 x i32> %s0, <2 x i32> + ret <2 x i32> %s1 +} + diff --git a/llvm/test/Transforms/InstCombine/select.ll b/llvm/test/Transforms/InstCombine/select.ll index 69b7b57..5838ae8 100644 --- a/llvm/test/Transforms/InstCombine/select.ll +++ b/llvm/test/Transforms/InstCombine/select.ll @@ -1753,31 +1753,6 @@ define i32 @test_select_select1(i32 %a, i32 %r0, i32 %r1, i32 %v1, i32 %v2) { 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> -; - %not_a = xor <2 x i32> %a, - %c0 = icmp sgt <2 x i32> %a, zeroinitializer - %s0 = select <2 x i1> %c0, <2 x i32> %not_a, <2 x i32> - %c1 = icmp sgt <2 x i32> %s0, - %s1 = select <2 x i1> %c1, <2 x i32> %s0, <2 x i32> - ret <2 x i32> %s1 -} - define i32 @PR23757(i32 %x) { ; CHECK-LABEL: @PR23757 ; CHECK: %[[cmp:.*]] = icmp eq i32 %x, 2147483647 -- 2.7.4