From f569578373bc89dc8e6716e4510433c88c5c0554 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sat, 17 Feb 2018 16:00:42 +0000 Subject: [PATCH] [PatternMatch] enhance m_One() to ignore undef elements in vectors llvm-svn: 325437 --- llvm/include/llvm/IR/PatternMatch.h | 22 ++++++++----------- llvm/test/Transforms/InstCombine/select.ll | 2 +- .../Transforms/InstCombine/vector-urem.ll | 5 +++-- .../InstSimplify/icmp-bool-constant.ll | 9 +++----- 4 files changed, 16 insertions(+), 22 deletions(-) diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 802258466647..70f2d116e537 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -182,17 +182,6 @@ struct match_nan { /// Match an arbitrary NaN constant. This includes quiet and signalling nans. inline match_nan m_NaN() { return match_nan(); } -struct match_one { - template bool match(ITy *V) { - if (const auto *C = dyn_cast(V)) - return C->isOneValue(); - return false; - } -}; - -/// \brief Match an integer 1 or a vector with all elements equal to 1. -inline match_one m_One() { return match_one(); } - struct match_all_ones { template bool match(ITy *V) { if (const auto *C = dyn_cast(V)) @@ -283,8 +272,8 @@ template inline constantint_match m_ConstantInt() { return constantint_match(); } -/// \brief This helper class is used to match scalar and vector constants that -/// satisfy a specified predicate. +/// This helper class is used to match scalar and vector constants that satisfy +/// a specified predicate. For vector constants, undefined elements are ignored. template struct cst_pred_ty : public Predicate { template bool match(ITy *V) { if (const auto *CI = dyn_cast(V)) @@ -339,6 +328,13 @@ template struct api_pred_ty : public Predicate { } }; +struct is_one { + bool isValue(const APInt &C) { return C.isOneValue(); } +}; + +/// Match an integer 1 or a vector with all elements equal to 1. +inline cst_pred_ty m_One() { return cst_pred_ty(); } + struct is_negative { bool isValue(const APInt &C) { return C.isNegative(); } }; diff --git a/llvm/test/Transforms/InstCombine/select.ll b/llvm/test/Transforms/InstCombine/select.ll index 50eb281bdd70..5708f5aea3aa 100644 --- a/llvm/test/Transforms/InstCombine/select.ll +++ b/llvm/test/Transforms/InstCombine/select.ll @@ -74,7 +74,7 @@ define <2 x i1> @trueval_is_true_vec(<2 x i1> %C, <2 x i1> %X) { define <2 x i1> @trueval_is_true_vec_undef_elt(<2 x i1> %C, <2 x i1> %X) { ; CHECK-LABEL: @trueval_is_true_vec_undef_elt( -; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[C:%.*]], <2 x i1> , <2 x i1> [[X:%.*]] +; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[C:%.*]], [[X:%.*]] ; CHECK-NEXT: ret <2 x i1> [[R]] ; %R = select <2 x i1> %C, <2 x i1> , <2 x i1> %X diff --git a/llvm/test/Transforms/InstCombine/vector-urem.ll b/llvm/test/Transforms/InstCombine/vector-urem.ll index 7dad59fde24d..113451f8469c 100644 --- a/llvm/test/Transforms/InstCombine/vector-urem.ll +++ b/llvm/test/Transforms/InstCombine/vector-urem.ll @@ -39,8 +39,9 @@ define <4 x i32> @test_v4i32_one(<4 x i32> %a0) { define <4 x i32> @test_v4i32_one_undef(<4 x i32> %a0) { ; CHECK-LABEL: @test_v4i32_one_undef( -; CHECK-NEXT: [[TMP1:%.*]] = urem <4 x i32> , [[A0:%.*]] -; CHECK-NEXT: ret <4 x i32> [[TMP1]] +; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[A0:%.*]], +; CHECK-NEXT: [[TMP2:%.*]] = zext <4 x i1> [[TMP1]] to <4 x i32> +; CHECK-NEXT: ret <4 x i32> [[TMP2]] ; %1 = urem <4 x i32> , %a0 ret <4 x i32> %1 diff --git a/llvm/test/Transforms/InstSimplify/icmp-bool-constant.ll b/llvm/test/Transforms/InstSimplify/icmp-bool-constant.ll index cf5f6d3f96b9..0b7a8297c682 100644 --- a/llvm/test/Transforms/InstSimplify/icmp-bool-constant.ll +++ b/llvm/test/Transforms/InstSimplify/icmp-bool-constant.ll @@ -14,8 +14,7 @@ define <2 x i1> @eq_t(<2 x i1> %a) { define <2 x i1> @eq_t_undef_elt(<2 x i1> %a) { ; CHECK-LABEL: @eq_t_undef_elt( -; CHECK-NEXT: [[R:%.*]] = icmp eq <2 x i1> [[A:%.*]], -; CHECK-NEXT: ret <2 x i1> [[R]] +; CHECK-NEXT: ret <2 x i1> [[A:%.*]] ; %r = icmp eq <2 x i1> %a, ret <2 x i1> %r @@ -57,8 +56,7 @@ define <2 x i1> @ugt_t(<2 x i1> %a) { define <2 x i1> @ugt_t_undef_elt(<2 x i1> %a) { ; CHECK-LABEL: @ugt_t_undef_elt( -; CHECK-NEXT: [[R:%.*]] = icmp ugt <2 x i1> [[A:%.*]], -; CHECK-NEXT: ret <2 x i1> [[R]] +; CHECK-NEXT: ret <2 x i1> zeroinitializer ; %r = icmp ugt <2 x i1> %a, ret <2 x i1> %r @@ -165,8 +163,7 @@ define <2 x i1> @sge_t(<2 x i1> %a) { define <2 x i1> @sge_t_undef_elt(<2 x i1> %a) { ; CHECK-LABEL: @sge_t_undef_elt( -; CHECK-NEXT: [[R:%.*]] = icmp sge <2 x i1> [[A:%.*]], -; CHECK-NEXT: ret <2 x i1> [[R]] +; CHECK-NEXT: ret <2 x i1> ; %r = icmp sge <2 x i1> %a, ret <2 x i1> %r