diff options
| -rw-r--r-- | llvm/include/llvm/IR/PatternMatch.h | 29 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstSimplify/AndOrXor.ll | 8 |
2 files changed, 15 insertions, 22 deletions
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 2c579e4d628..99c6ff2dc91 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_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_NonNegative(const APInt *&V) { 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_Power2OrZero(const APInt *&V) { 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>(); } /////////////////////////////////////////////////////////////////////////////// diff --git a/llvm/test/Transforms/InstSimplify/AndOrXor.ll b/llvm/test/Transforms/InstSimplify/AndOrXor.ll index 55671430c4b..70c766097aa 100644 --- a/llvm/test/Transforms/InstSimplify/AndOrXor.ll +++ b/llvm/test/Transforms/InstSimplify/AndOrXor.ll @@ -16,9 +16,7 @@ define <2 x i32> @add_nsw_signbit(<2 x i32> %x) { 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> %x) { 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> |

