From ed2211d50fec431b40d77f4573434fecf3923660 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 6 Mar 2018 18:19:42 +0000 Subject: [PATCH] [PatternMatch] define m_Not using m_Xor and cst_pred_ty Using cst_pred_ty in the definition allows us to match vectors with undef elements. This is a continuation of an effort to make all pattern matchers allow undef elements in vectors: rL325437 rL325466 D43792 Differential Revision: https://reviews.llvm.org/D44076 llvm-svn: 326823 --- llvm/include/llvm/IR/PatternMatch.h | 32 +++++++------------------- llvm/test/Transforms/InstCombine/sub.ll | 5 +--- llvm/test/Transforms/InstCombine/vector-xor.ll | 16 +++++-------- 3 files changed, 15 insertions(+), 38 deletions(-) diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h index 1c071cb..0023988 100644 --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -1036,34 +1036,11 @@ template struct LoadClass_match { template inline LoadClass_match m_Load(const OpTy &Op) { return LoadClass_match(Op); } + //===----------------------------------------------------------------------===// // Matchers for unary operators // -template struct not_match { - LHS_t L; - - not_match(const LHS_t &LHS) : L(LHS) {} - - template bool match(OpTy *V) { - if (auto *O = dyn_cast(V)) - if (O->getOpcode() == Instruction::Xor) { - if (isAllOnes(O->getOperand(1))) - return L.match(O->getOperand(0)); - if (isAllOnes(O->getOperand(0))) - return L.match(O->getOperand(1)); - } - return false; - } - -private: - bool isAllOnes(Value *V) { - return isa(V) && cast(V)->isAllOnesValue(); - } -}; - -template inline not_match m_Not(const LHS &L) { return L; } - template struct neg_match { LHS_t L; @@ -1590,6 +1567,13 @@ inline BinaryOp_match m_c_Xor(const LHS &L, return BinaryOp_match(L, R); } +/// Matches a 'Not' as 'xor V, -1' or 'xor -1, V'. +template +inline BinaryOp_match, Instruction::Xor, true> +m_Not(const ValTy &V) { + return m_c_Xor(V, m_AllOnes()); +} + /// Matches an SMin with LHS and RHS in either order. template inline MaxMin_match diff --git a/llvm/test/Transforms/InstCombine/sub.ll b/llvm/test/Transforms/InstCombine/sub.ll index 0d4f877..f41832b 100644 --- a/llvm/test/Transforms/InstCombine/sub.ll +++ b/llvm/test/Transforms/InstCombine/sub.ll @@ -73,12 +73,9 @@ define <2 x i8> @notnotsub_vec(<2 x i8> %x, <2 x i8> %y) { ret <2 x i8> %sub } -; FIXME: define <2 x i8> @notnotsub_vec_undef_elts(<2 x i8> %x, <2 x i8> %y) { ; CHECK-LABEL: @notnotsub_vec_undef_elts( -; CHECK-NEXT: [[NX:%.*]] = xor <2 x i8> [[X:%.*]], -; CHECK-NEXT: [[NY:%.*]] = xor <2 x i8> [[Y:%.*]], -; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i8> [[NX]], [[NY]] +; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i8> [[Y:%.*]], [[X:%.*]] ; CHECK-NEXT: ret <2 x i8> [[SUB]] ; %nx = xor <2 x i8> %x, diff --git a/llvm/test/Transforms/InstCombine/vector-xor.ll b/llvm/test/Transforms/InstCombine/vector-xor.ll index 8c7ccc1..80189e6 100644 --- a/llvm/test/Transforms/InstCombine/vector-xor.ll +++ b/llvm/test/Transforms/InstCombine/vector-xor.ll @@ -107,10 +107,8 @@ define <4 x i32> @test_v4i32_not_ashr_not(<4 x i32> %x, <4 x i32> %y) { define <4 x i32> @test_v4i32_not_ashr_not_undef(<4 x i32> %x, <4 x i32> %y) { ; CHECK-LABEL: @test_v4i32_not_ashr_not_undef( -; CHECK-NEXT: [[TMP1:%.*]] = xor <4 x i32> [[X:%.*]], -; CHECK-NEXT: [[TMP2:%.*]] = ashr <4 x i32> [[TMP1]], [[Y:%.*]] -; CHECK-NEXT: [[TMP3:%.*]] = xor <4 x i32> [[TMP2]], -; CHECK-NEXT: ret <4 x i32> [[TMP3]] +; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> [[X:%.*]], [[Y:%.*]] +; CHECK-NEXT: ret <4 x i32> [[TMP1]] ; %1 = xor <4 x i32> , %x %2 = ashr <4 x i32> %1, %y @@ -142,9 +140,8 @@ define <4 x i32> @test_v4i32_not_ashr_negative_const(<4 x i32> %a0) { define <4 x i32> @test_v4i32_not_ashr_negative_const_undef(<4 x i32> %a0) { ; CHECK-LABEL: @test_v4i32_not_ashr_negative_const_undef( -; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> , [[A0:%.*]] -; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], -; CHECK-NEXT: ret <4 x i32> [[TMP2]] +; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> , [[A0:%.*]] +; CHECK-NEXT: ret <4 x i32> [[TMP1]] ; %1 = ashr <4 x i32> , %a0 %2 = xor <4 x i32> , %1 @@ -175,9 +172,8 @@ define <4 x i32> @test_v4i32_not_lshr_nonnegative_const(<4 x i32> %a0) { define <4 x i32> @test_v4i32_not_lshr_nonnegative_const_undef(<4 x i32> %a0) { ; CHECK-LABEL: @test_v4i32_not_lshr_nonnegative_const_undef( -; CHECK-NEXT: [[TMP1:%.*]] = lshr <4 x i32> , [[A0:%.*]] -; CHECK-NEXT: [[TMP2:%.*]] = xor <4 x i32> [[TMP1]], -; CHECK-NEXT: ret <4 x i32> [[TMP2]] +; CHECK-NEXT: [[TMP1:%.*]] = ashr <4 x i32> , [[A0:%.*]] +; CHECK-NEXT: ret <4 x i32> [[TMP1]] ; %1 = lshr <4 x i32> , %a0 %2 = xor <4 x i32> , %1 -- 2.7.4