aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2010-01-31 02:30:23 +0000
committerEli Friedman <eli.friedman@gmail.com>2010-01-31 02:30:23 +0000
commit694488f4770468f03b974180631c0fbfa21b28cc (patch)
treeff3af0445dfed3464a6c36bf37a5f8736a12097e /lib/Transforms
parent894c1af05fb3f0d8e2ee6565816fa220b260ed9d (diff)
downloadexternal_llvm-694488f4770468f03b974180631c0fbfa21b28cc.zip
external_llvm-694488f4770468f03b974180631c0fbfa21b28cc.tar.gz
external_llvm-694488f4770468f03b974180631c0fbfa21b28cc.tar.bz2
Add a small transform: transform -(X<<Y) to (-X<<Y) when the shift has a single
use and X is free to negate. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@94941 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/InstCombine/InstCombineAddSub.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 4891ff0..119b1ca 100644
--- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -676,6 +676,13 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
return BinaryOperator::CreateSDiv(Op1I->getOperand(0),
ConstantExpr::getNeg(DivRHS));
+ // 0 - (C << X) -> (-C << X)
+ if (Op1I->getOpcode() == Instruction::Shl)
+ if (ConstantInt *CSI = dyn_cast<ConstantInt>(Op0))
+ if (CSI->isZero())
+ if (Value *ShlLHSNeg = dyn_castNegVal(Op1I->getOperand(0)))
+ return BinaryOperator::CreateShl(ShlLHSNeg, Op1I->getOperand(1));
+
// X - X*C --> X * (1-C)
ConstantInt *C2 = 0;
if (dyn_castFoldableMul(Op1I, C2) == Op0) {