diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-12-24 17:31:38 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-12-24 17:31:38 +0000 |
commit | 010337c8385b919f75d98f6cb383214817c13257 (patch) | |
tree | c23a474c8e335acf01b8411d5935bfda96db0677 /llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | |
parent | 175543ac7817e78cb7f474353ae078f396c34f84 (diff) | |
download | bcm5719-llvm-010337c8385b919f75d98f6cb383214817c13257.tar.gz bcm5719-llvm-010337c8385b919f75d98f6cb383214817c13257.zip |
InstCombine: Canonicalize (2^n)-1 - x into (2^n)-1 ^ x iff x is known to be smaller than 2^n.
This has the obvious advantage of being commutable and is always a win on x86 because
const - x wastes a register there. On less weird architectures this may lead to
a regression because other arithmetic doesn't fuse with it anymore. I'll address that
problem in a followup.
llvm-svn: 147254
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp index d10046c10ba..604d9c8bb44 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp @@ -587,6 +587,9 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) { ConstantInt *C2; if (match(Op1, m_Add(m_Value(X), m_ConstantInt(C2)))) return BinaryOperator::CreateSub(ConstantExpr::getSub(C, C2), X); + + if (SimplifyDemandedInstructionBits(I)) + return &I; } |