[llvm] r325437 - [PatternMatch] enhance m_One() to ignore undef elements in vectors

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 17 08:00:42 PST 2018


Author: spatel
Date: Sat Feb 17 08:00:42 2018
New Revision: 325437

URL: http://llvm.org/viewvc/llvm-project?rev=325437&view=rev
Log:
[PatternMatch] enhance m_One() to ignore undef elements in vectors

Modified:
    llvm/trunk/include/llvm/IR/PatternMatch.h
    llvm/trunk/test/Transforms/InstCombine/select.ll
    llvm/trunk/test/Transforms/InstCombine/vector-urem.ll
    llvm/trunk/test/Transforms/InstSimplify/icmp-bool-constant.ll

Modified: llvm/trunk/include/llvm/IR/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PatternMatch.h?rev=325437&r1=325436&r2=325437&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/IR/PatternMatch.h Sat Feb 17 08:00:42 2018
@@ -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 <typename ITy> bool match(ITy *V) {
-    if (const auto *C = dyn_cast<Constant>(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 <typename ITy> bool match(ITy *V) {
     if (const auto *C = dyn_cast<Constant>(V))
@@ -283,8 +272,8 @@ template <int64_t Val> inline constantin
   return constantint_match<Val>();
 }
 
-/// \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 <typename Predicate> struct cst_pred_ty : public Predicate {
   template <typename ITy> bool match(ITy *V) {
     if (const auto *CI = dyn_cast<ConstantInt>(V))
@@ -339,6 +328,13 @@ template <typename Predicate> struct api
   }
 };
 
+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<is_one> m_One() { return cst_pred_ty<is_one>(); }
+
 struct is_negative {
   bool isValue(const APInt &C) { return C.isNegative(); }
 };

Modified: llvm/trunk/test/Transforms/InstCombine/select.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/select.ll?rev=325437&r1=325436&r2=325437&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/select.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/select.ll Sat Feb 17 08:00:42 2018
@@ -74,7 +74,7 @@ define <2 x i1> @trueval_is_true_vec(<2
 
 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> <i1 undef, i1 true>, <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> <i1 undef, i1 true>, <2 x i1> %X

Modified: llvm/trunk/test/Transforms/InstCombine/vector-urem.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/vector-urem.ll?rev=325437&r1=325436&r2=325437&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/vector-urem.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/vector-urem.ll Sat Feb 17 08:00:42 2018
@@ -39,8 +39,9 @@ define <4 x i32> @test_v4i32_one(<4 x i3
 
 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> <i32 1, i32 1, i32 1, i32 undef>, [[A0:%.*]]
-; CHECK-NEXT:    ret <4 x i32> [[TMP1]]
+; CHECK-NEXT:    [[TMP1:%.*]] = icmp ne <4 x i32> [[A0:%.*]], <i32 1, i32 1, i32 1, i32 undef>
+; CHECK-NEXT:    [[TMP2:%.*]] = zext <4 x i1> [[TMP1]] to <4 x i32>
+; CHECK-NEXT:    ret <4 x i32> [[TMP2]]
 ;
   %1 = urem <4 x i32> <i32 1, i32 1, i32 1, i32 undef>, %a0
   ret <4 x i32> %1

Modified: llvm/trunk/test/Transforms/InstSimplify/icmp-bool-constant.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/icmp-bool-constant.ll?rev=325437&r1=325436&r2=325437&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/icmp-bool-constant.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/icmp-bool-constant.ll Sat Feb 17 08:00:42 2018
@@ -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:%.*]], <i1 undef, i1 true>
-; CHECK-NEXT:    ret <2 x i1> [[R]]
+; CHECK-NEXT:    ret <2 x i1> [[A:%.*]]
 ;
   %r = icmp eq <2 x i1> %a, <i1 undef, i1 true>
   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:%.*]], <i1 true, i1 undef>
-; CHECK-NEXT:    ret <2 x i1> [[R]]
+; CHECK-NEXT:    ret <2 x i1> zeroinitializer
 ;
   %r = icmp ugt <2 x i1> %a, <i1 true, i1 undef>
   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:%.*]], <i1 true, i1 undef>
-; CHECK-NEXT:    ret <2 x i1> [[R]]
+; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true>
 ;
   %r = icmp sge <2 x i1> %a, <i1 true, i1 undef>
   ret <2 x i1> %r




More information about the llvm-commits mailing list