[llvm] r325623 - [PatternMatch] enhance m_SignMask() to ignore undef elements in vectors

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 13:02:40 PST 2018


Author: spatel
Date: Tue Feb 20 13:02:40 2018
New Revision: 325623

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

Modified:
    llvm/trunk/include/llvm/IR/PatternMatch.h
    llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll

Modified: llvm/trunk/include/llvm/IR/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/PatternMatch.h?rev=325623&r1=325622&r2=325623&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/IR/PatternMatch.h Tue Feb 20 13:02:40 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_sign_mask {
-  template <typename ITy> bool match(ITy *V) {
-    if (const auto *C = dyn_cast<Constant>(V))
-      return C->isMinSignedValue();
-    return false;
-  }
-};
-
-/// Match an integer or vector with only the sign bit(s) set.
-inline match_sign_mask m_SignMask() { return match_sign_mask(); }
-
 struct apint_match {
   const APInt *&Res;
 
@@ -368,6 +357,14 @@ inline api_pred_ty<is_nonnegative> m_Non
   return V;
 }
 
+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_power2 {
   bool isValue(const APInt &C) { return C.isPowerOf2(); }
 };
@@ -390,12 +387,12 @@ inline api_pred_ty<is_power2_or_zero> m_
   return V;
 }
 
-struct is_one {
-  bool isValue(const APInt &C) { return C.isOneValue(); }
+struct is_sign_mask {
+  bool isValue(const APInt &C) { return C.isSignMask(); }
 };
-/// 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>();
+/// Match an integer or vector with only the sign bit(s) set.
+inline cst_pred_ty<is_sign_mask> m_SignMask() {
+  return cst_pred_ty<is_sign_mask>();
 }
 
 ///////////////////////////////////////////////////////////////////////////////

Modified: llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll?rev=325623&r1=325622&r2=325623&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/AndOrXor.ll Tue Feb 20 13:02:40 2018
@@ -16,9 +16,7 @@ define <2 x i32> @add_nsw_signbit(<2 x i
 
 define <2 x i32> @add_nsw_signbit_undef(<2 x i32> %x) {
 ; CHECK-LABEL: @add_nsw_signbit_undef(
-; CHECK-NEXT:    [[Y:%.*]] = xor <2 x i32> [[X:%.*]], <i32 undef, i32 -2147483648>
-; CHECK-NEXT:    [[Z:%.*]] = add nsw <2 x i32> [[Y]], <i32 -2147483648, i32 undef>
-; CHECK-NEXT:    ret <2 x i32> [[Z]]
+; CHECK-NEXT:    ret <2 x i32> [[X:%.*]]
 ;
   %y = xor <2 x i32> %x, <i32 undef, i32 -2147483648>
   %z = add nsw <2 x i32> %y, <i32 -2147483648, i32 undef>
@@ -40,9 +38,7 @@ define <2 x i5> @add_nuw_signbit(<2 x i5
 
 define <2 x i5> @add_nuw_signbit_undef(<2 x i5> %x) {
 ; CHECK-LABEL: @add_nuw_signbit_undef(
-; CHECK-NEXT:    [[Y:%.*]] = xor <2 x i5> [[X:%.*]], <i5 -16, i5 undef>
-; CHECK-NEXT:    [[Z:%.*]] = add nuw <2 x i5> [[Y]], <i5 undef, i5 -16>
-; CHECK-NEXT:    ret <2 x i5> [[Z]]
+; CHECK-NEXT:    ret <2 x i5> [[X:%.*]]
 ;
   %y = xor <2 x i5> %x, <i5 -16, i5 undef>
   %z = add nuw <2 x i5> %y, <i5 undef, i5 -16>




More information about the llvm-commits mailing list