From e121eccc6f6d8207f0d37b422ee44096bd6edb5e Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Thu, 27 Oct 2016 15:02:45 +0000 Subject: [PATCH] [InstCombine] add tests for missing folds of vector abs/nabs/min/max llvm-svn: 285299 --- test/Transforms/InstCombine/abs_abs.ll | 43 +++++++++++++++++++++- test/Transforms/InstCombine/max-of-nots.ll | 20 ++++++++++ test/Transforms/InstCombine/select.ll | 23 ++++++++++-- test/Transforms/InstCombine/select_meta.ll | 20 ++++++++++ 4 files changed, 102 insertions(+), 4 deletions(-) diff --git a/test/Transforms/InstCombine/abs_abs.ll b/test/Transforms/InstCombine/abs_abs.ll index de10fd180a7..10aec3678fb 100644 --- a/test/Transforms/InstCombine/abs_abs.ll +++ b/test/Transforms/InstCombine/abs_abs.ll @@ -1,3 +1,4 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -instcombine -S | FileCheck %s define i32 @abs_abs_x01(i32 %x) { @@ -15,6 +16,26 @@ define i32 @abs_abs_x01(i32 %x) { ; CHECK-NEXT: ret i32 [[SEL]] } +; FIXME - vectors should get the same folds +define <2 x i32> @abs_abs_x01_vec(<2 x i32> %x) { +; CHECK-LABEL: @abs_abs_x01_vec( +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> %x, +; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, %x +; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> %x, <2 x i32> [[SUB]] +; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt <2 x i32> [[COND]], +; CHECK-NEXT: [[SUB16:%.*]] = sub nsw <2 x i32> zeroinitializer, [[COND]] +; CHECK-NEXT: [[COND18:%.*]] = select <2 x i1> [[CMP1]], <2 x i32> [[COND]], <2 x i32> [[SUB16]] +; CHECK-NEXT: ret <2 x i32> [[COND18]] +; + %cmp = icmp sgt <2 x i32> %x, + %sub = sub nsw <2 x i32> zeroinitializer, %x + %cond = select <2 x i1> %cmp, <2 x i32> %x, <2 x i32> %sub + %cmp1 = icmp sgt <2 x i32> %cond, + %sub16 = sub nsw <2 x i32> zeroinitializer, %cond + %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16 + ret <2 x i32> %cond18 +} + define i32 @abs_abs_x02(i32 %x) { %cmp = icmp sgt i32 %x, 0 %sub = sub nsw i32 0, %x @@ -60,6 +81,26 @@ define i32 @abs_abs_x04(i32 %x) { ; CHECK-NEXT: ret i32 [[SEL]] } +; FIXME - vectors should get the same folds +define <2 x i32> @abs_abs_x04_vec(<2 x i32> %x) { +; CHECK-LABEL: @abs_abs_x04_vec( +; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> %x, +; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, %x +; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> %x +; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt <2 x i32> [[COND]], +; CHECK-NEXT: [[SUB16:%.*]] = sub nsw <2 x i32> zeroinitializer, [[COND]] +; CHECK-NEXT: [[COND18:%.*]] = select <2 x i1> [[CMP1]], <2 x i32> [[COND]], <2 x i32> [[SUB16]] +; CHECK-NEXT: ret <2 x i32> [[COND18]] +; + %cmp = icmp slt <2 x i32> %x, + %sub = sub nsw <2 x i32> zeroinitializer, %x + %cond = select <2 x i1> %cmp, <2 x i32> %sub, <2 x i32> %x + %cmp1 = icmp sgt <2 x i32> %cond, + %sub16 = sub nsw <2 x i32> zeroinitializer, %cond + %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16 + ret <2 x i32> %cond18 +} + define i32 @abs_abs_x05(i32 %x) { %cmp = icmp sgt i32 %x, -1 %sub = sub nsw i32 0, %x @@ -958,4 +999,4 @@ define i32 @nabs_abs_x16(i32 %x) { ; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x ; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]] ; CHECK-NEXT: ret i32 [[SEL]] -} \ No newline at end of file +} diff --git a/test/Transforms/InstCombine/max-of-nots.ll b/test/Transforms/InstCombine/max-of-nots.ll index 62ea1245e60..a3291685ed8 100644 --- a/test/Transforms/InstCombine/max-of-nots.ll +++ b/test/Transforms/InstCombine/max-of-nots.ll @@ -88,3 +88,23 @@ define i32 @max_of_nots(i32 %x, i32 %y) { ret i32 %smax96 } +; FIXME - vectors should get the same folds +define <2 x i32> @max_of_nots_vec(<2 x i32> %x, <2 x i32> %y) { +; CHECK-LABEL: @max_of_nots_vec( +; CHECK-NEXT: [[C0:%.*]] = icmp sgt <2 x i32> %y, zeroinitializer +; CHECK-NEXT: [[XOR_Y:%.*]] = xor <2 x i32> %y, +; CHECK-NEXT: [[S0:%.*]] = select <2 x i1> [[C0]], <2 x i32> [[XOR_Y]], <2 x i32> +; CHECK-NEXT: [[XOR_X:%.*]] = xor <2 x i32> %x, +; CHECK-NEXT: [[C1:%.*]] = icmp slt <2 x i32> [[S0]], [[XOR_X]] +; CHECK-NEXT: [[SMAX96:%.*]] = select <2 x i1> [[C1]], <2 x i32> [[XOR_X]], <2 x i32> [[S0]] +; CHECK-NEXT: ret <2 x i32> [[SMAX96]] +; + %c0 = icmp sgt <2 x i32> %y, zeroinitializer + %xor_y = xor <2 x i32> %y, + %s0 = select <2 x i1> %c0, <2 x i32> %xor_y, <2 x i32> + %xor_x = xor <2 x i32> %x, + %c1 = icmp slt <2 x i32> %s0, %xor_x + %smax96 = select <2 x i1> %c1, <2 x i32> %xor_x, <2 x i32> %s0 + ret <2 x i32> %smax96 +} + diff --git a/test/Transforms/InstCombine/select.ll b/test/Transforms/InstCombine/select.ll index 1b753822bb1..c03e03a13b6 100644 --- a/test/Transforms/InstCombine/select.ll +++ b/test/Transforms/InstCombine/select.ll @@ -1711,10 +1711,11 @@ define i32 @test_select_select1(i32 %a, i32 %r0, i32 %r1, i32 %v1, i32 %v2) { ret i32 %s1 } -define i32 @test_max_of_min(i32 %a) { ; MAX(MIN(%a, -1), -1) == -1 +define i32 @test_max_of_min(i32 %a) { ; CHECK-LABEL: @test_max_of_min( -; CHECK: ret i32 -1 +; 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 @@ -1723,6 +1724,23 @@ define i32 @test_max_of_min(i32 %a) { ret i32 %s1 } +; FIXME - vectors should get the same folds +define <2 x i32> @test_max_of_min_vec(<2 x i32> %a) { +; CHECK-LABEL: @test_max_of_min_vec( +; CHECK-NEXT: [[NOT_A:%.*]] = xor <2 x i32> %a, +; CHECK-NEXT: [[C0:%.*]] = icmp sgt <2 x i32> %a, zeroinitializer +; CHECK-NEXT: [[S0:%.*]] = select <2 x i1> [[C0]], <2 x i32> [[NOT_A]], <2 x i32> +; CHECK-NEXT: [[C1:%.*]] = icmp sgt <2 x i32> [[S0]], +; CHECK-NEXT: [[S1:%.*]] = select <2 x i1> [[C1]], <2 x i32> [[S0]], <2 x i32> +; CHECK-NEXT: ret <2 x i32> [[S1]] +; + %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 @@ -1736,7 +1754,6 @@ define i32 @PR23757(i32 %x) { ret i32 %sel } - define i32 @PR27137(i32 %a) { ; CHECK-LABEL: @PR27137( ; CHECK-NEXT: %not_a = xor i32 %a, -1 diff --git a/test/Transforms/InstCombine/select_meta.ll b/test/Transforms/InstCombine/select_meta.ll index 6a2ca43a4cb..26b49f6f952 100644 --- a/test/Transforms/InstCombine/select_meta.ll +++ b/test/Transforms/InstCombine/select_meta.ll @@ -1,3 +1,4 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt < %s -instcombine -S | FileCheck %s define i32 @foo(i32) local_unnamed_addr #0 { @@ -80,6 +81,25 @@ define i32 @abs_nabs_x01(i32 %x) { ; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]], !prof ![[MD1]] } +; FIXME - vectors should get the same folds +define <2 x i32> @abs_nabs_x01_vec(<2 x i32> %x) { +; CHECK-LABEL: @abs_nabs_x01_vec( +; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> %x, +; CHECK-NEXT: [[SUB:%.*]] = sub nsw <2 x i32> zeroinitializer, %x +; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> [[SUB]], <2 x i32> %x, !prof !0 +; CHECK-NEXT: [[CMP1:%.*]] = icmp sgt <2 x i32> [[COND]], +; CHECK-NEXT: [[SUB16:%.*]] = sub nsw <2 x i32> zeroinitializer, [[COND]] +; CHECK-NEXT: [[COND18:%.*]] = select <2 x i1> [[CMP1]], <2 x i32> [[COND]], <2 x i32> [[SUB16]], !prof !2 +; CHECK-NEXT: ret <2 x i32> [[COND18]] +; + %cmp = icmp sgt <2 x i32> %x, + %sub = sub nsw <2 x i32> zeroinitializer, %x + %cond = select <2 x i1> %cmp, <2 x i32> %sub, <2 x i32> %x, !prof !1 + %cmp1 = icmp sgt <2 x i32> %cond, + %sub16 = sub nsw <2 x i32> zeroinitializer, %cond + %cond18 = select <2 x i1> %cmp1, <2 x i32> %cond, <2 x i32> %sub16, !prof !2 + ret <2 x i32> %cond18 +} ; SMAX(SMAX(x, y), x) -> SMAX(x, y) define i32 @test30(i32 %x, i32 %y) {