From 103d62e1313d80f4a9f4285ad1280b793dfd9f9b Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 2 Jul 2020 15:09:52 +0100 Subject: [PATCH] [InstCombine] Add some (vXi1 trunc(lshr(x,c))) -> icmp_eq(and(x,c')) tests for vectors with undef elements Suggested on D83035 --- llvm/test/Transforms/InstCombine/apint-shift.ll | 12 ++++++++++ llvm/test/Transforms/InstCombine/icmp.ll | 30 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/apint-shift.ll b/llvm/test/Transforms/InstCombine/apint-shift.ll index d6dd529..ca6f97d 100644 --- a/llvm/test/Transforms/InstCombine/apint-shift.ll +++ b/llvm/test/Transforms/InstCombine/apint-shift.ll @@ -341,6 +341,18 @@ define <2 x i1> @test16vec_nonuniform(<2 x i84> %X) { ret <2 x i1> %cmp } +define <2 x i1> @test16vec_undef(<2 x i84> %X) { +; CHECK-LABEL: @test16vec_undef( +; CHECK-NEXT: [[SHR1:%.*]] = lshr <2 x i84> [[X:%.*]], +; CHECK-NEXT: [[CMP:%.*]] = trunc <2 x i84> [[SHR1]] to <2 x i1> +; CHECK-NEXT: ret <2 x i1> [[CMP]] +; + %shr = ashr <2 x i84> %X, + %and = and <2 x i84> %shr, + %cmp = icmp ne <2 x i84> %and, zeroinitializer + ret <2 x i1> %cmp +} + define i1 @test17(i106 %A) { ; CHECK-LABEL: @test17( ; CHECK-NEXT: [[B_MASK:%.*]] = and i106 [[A:%.*]], -8 diff --git a/llvm/test/Transforms/InstCombine/icmp.ll b/llvm/test/Transforms/InstCombine/icmp.ll index eb214f0..a81e004 100644 --- a/llvm/test/Transforms/InstCombine/icmp.ll +++ b/llvm/test/Transforms/InstCombine/icmp.ll @@ -2700,6 +2700,20 @@ define <2 x i1> @icmp_and_or_lshr_cst_vec_nonuniform(<2 x i32> %x) { ret <2 x i1> %ret } +define <2 x i1> @icmp_and_or_lshr_cst_vec_undef(<2 x i32> %x) { +; CHECK-LABEL: @icmp_and_or_lshr_cst_vec_undef( +; CHECK-NEXT: [[SHF:%.*]] = lshr <2 x i32> [[X:%.*]], +; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[SHF]], [[X]] +; CHECK-NEXT: [[RET:%.*]] = trunc <2 x i32> [[OR]] to <2 x i1> +; CHECK-NEXT: ret <2 x i1> [[RET]] +; + %shf = lshr <2 x i32> %x, + %or = or <2 x i32> %shf, %x + %and = and <2 x i32> %or, + %ret = icmp ne <2 x i32> %and, zeroinitializer + ret <2 x i1> %ret +} + define <2 x i1> @icmp_and_or_lshr_cst_vec_commute(<2 x i32> %xp) { ; CHECK-LABEL: @icmp_and_or_lshr_cst_vec_commute( ; CHECK-NEXT: [[X:%.*]] = srem <2 x i32> [[XP:%.*]], @@ -2731,6 +2745,22 @@ define <2 x i1> @icmp_and_or_lshr_cst_vec_nonuniform_commute(<2 x i32> %xp) { ret <2 x i1> %ret } +define <2 x i1> @icmp_and_or_lshr_cst_vec_undef_commute(<2 x i32> %xp) { +; CHECK-LABEL: @icmp_and_or_lshr_cst_vec_undef_commute( +; CHECK-NEXT: [[X:%.*]] = srem <2 x i32> [[XP:%.*]], +; CHECK-NEXT: [[SHF:%.*]] = lshr <2 x i32> [[X]], +; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[X]], [[SHF]] +; CHECK-NEXT: [[RET:%.*]] = trunc <2 x i32> [[OR]] to <2 x i1> +; CHECK-NEXT: ret <2 x i1> [[RET]] +; + %x = srem <2 x i32> %xp, ; prevent complexity-based canonicalization + %shf = lshr <2 x i32> %x, + %or = or <2 x i32> %x, %shf + %and = and <2 x i32> %or, + %ret = icmp ne <2 x i32> %and, zeroinitializer + ret <2 x i1> %ret +} + define i1 @shl_ap1_zero_ap2_non_zero_2(i32 %a) { ; CHECK-LABEL: @shl_ap1_zero_ap2_non_zero_2( ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[A:%.*]], 29 -- 2.7.4