diff options
author | Sanjay Patel <spatel@rotateright.com> | 2018-09-03 18:40:56 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2018-09-03 18:40:56 +0000 |
commit | 2fe1f62c88c69a78ba61c0ba0b1d2aa7f50473a6 (patch) | |
tree | 6d30da8bfd8b6fead61851fcc9e71b55a89fed45 /llvm | |
parent | d75064e6d502fb65265289a29468ff5dd7dd4685 (diff) | |
download | bcm5719-llvm-2fe1f62c88c69a78ba61c0ba0b1d2aa7f50473a6.tar.gz bcm5719-llvm-2fe1f62c88c69a78ba61c0ba0b1d2aa7f50473a6.zip |
[InstCombine] simplify xor/not folds; NFCI
llvm-svn: 341336
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 9af5ad05ae5..8fa012d214e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2685,20 +2685,17 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { // the 'not' by inverting the constant and using the opposite shift type. // Canonicalization rules ensure that only a negative constant uses 'ashr', // but we must check that in case that transform has not fired yet. + + // ~(C >>s Y) --> ~C >>u Y (when inverting the replicated sign bits) Constant *C; if (match(NotVal, m_AShr(m_Constant(C), m_Value(Y))) && - match(C, m_Negative())) { - // ~(C >>s Y) --> ~C >>u Y (when inverting the replicated sign bits) - Constant *NotC = ConstantExpr::getNot(C); - return BinaryOperator::CreateLShr(NotC, Y); - } + match(C, m_Negative())) + return BinaryOperator::CreateLShr(ConstantExpr::getNot(C), Y); + // ~(C >>u Y) --> ~C >>s Y (when inverting the replicated sign bits) if (match(NotVal, m_LShr(m_Constant(C), m_Value(Y))) && - match(C, m_NonNegative())) { - // ~(C >>u Y) --> ~C >>s Y (when inverting the replicated sign bits) - Constant *NotC = ConstantExpr::getNot(C); - return BinaryOperator::CreateAShr(NotC, Y); - } + match(C, m_NonNegative())) + return BinaryOperator::CreateAShr(ConstantExpr::getNot(C), Y); // ~(X + C) --> -(C + 1) - X if (match(Op0, m_Add(m_Value(X), m_Constant(C)))) @@ -2717,18 +2714,15 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) { if (match(Op1, m_APInt(RHSC))) { Value *X; const APInt *C; - if (match(Op0, m_Sub(m_APInt(C), m_Value(X)))) { - if (RHSC->isSignMask()) { - // (C - X) ^ signmask -> (C + signmask - X) - Constant *NewC = ConstantInt::get(I.getType(), *C + *RHSC); - return BinaryOperator::CreateSub(NewC, X); - } - } else if (match(Op0, m_Add(m_Value(X), m_APInt(C)))) { - if (RHSC->isSignMask()) { - // (X + C) ^ signmask -> (X + C + signmask) - Constant *NewC = ConstantInt::get(I.getType(), *C + *RHSC); - return BinaryOperator::CreateAdd(X, NewC); - } + if (RHSC->isSignMask() && match(Op0, m_Sub(m_APInt(C), m_Value(X)))) { + // (C - X) ^ signmask -> (C + signmask - X) + Constant *NewC = ConstantInt::get(I.getType(), *C + *RHSC); + return BinaryOperator::CreateSub(NewC, X); + } + if (RHSC->isSignMask() && match(Op0, m_Add(m_Value(X), m_APInt(C)))) { + // (X + C) ^ signmask -> (X + C + signmask) + Constant *NewC = ConstantInt::get(I.getType(), *C + *RHSC); + return BinaryOperator::CreateAdd(X, NewC); } // (X|C1)^C2 -> X^(C1^C2) iff X&~C1 == 0 |