aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-10-13 20:29:11 +0000
committerSanjay Patel <spatel@rotateright.com>2017-10-13 20:29:11 +0000
commitf0242de143aa27f794fce1c0dd36698a44590371 (patch)
tree1f810d5d3a0c033c2f612c4ca86765dc9925a9aa /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
parent4d70754e3cf57d76647b62cecaa37fb06815566a (diff)
downloadllvm-f0242de143aa27f794fce1c0dd36698a44590371.zip
llvm-f0242de143aa27f794fce1c0dd36698a44590371.tar.gz
llvm-f0242de143aa27f794fce1c0dd36698a44590371.tar.bz2
[InstCombine] move code to remove repeated constant check; NFCI
Also, consolidate tests for this fold in one place. llvm-svn: 315745
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 22538b4..2962300a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -960,10 +960,15 @@ Instruction *InstCombiner::foldAddWithConstant(BinaryOperator &Add) {
return NV;
Value *X;
- if (match(Op0, m_ZExt(m_Value(X))) && X->getType()->getScalarSizeInBits() == 1)
- // zext(bool) + C -> bool ? C + 1 : C
+ // zext(bool) + C -> bool ? C + 1 : C
+ if (match(Op0, m_ZExt(m_Value(X))) &&
+ X->getType()->getScalarSizeInBits() == 1)
return SelectInst::Create(X, AddOne(Op1C), Op1);
+ // ~X + C --> (C-1) - X
+ if (match(Op0, m_Not(m_Value(X))))
+ return BinaryOperator::CreateSub(SubOne(Op1C), X);
+
const APInt *C;
if (!match(Op1, m_APInt(C)))
return nullptr;
@@ -1117,12 +1122,6 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
if (haveNoCommonBitsSet(LHS, RHS, DL, &AC, &I, &DT))
return BinaryOperator::CreateOr(LHS, RHS);
- if (Constant *CRHS = dyn_cast<Constant>(RHS)) {
- Value *X;
- if (match(LHS, m_Not(m_Value(X)))) // ~X + C --> (C-1) - X
- return BinaryOperator::CreateSub(SubOne(CRHS), X);
- }
-
// FIXME: We already did a check for ConstantInt RHS above this.
// FIXME: Is this pattern covered by another fold? No regression tests fail on
// removal.