mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-18 22:38:56 +00:00
Implement Reassociate/mul-neg-add.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@21788 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
22d06312a9
commit
44b8c7d5d3
@ -614,6 +614,18 @@ void Reassociate::ReassociateBB(BasicBlock *BB) {
|
|||||||
// sorted form, optimize it globally if possible.
|
// sorted form, optimize it globally if possible.
|
||||||
OptimizeExpression(I->getOpcode(), Ops);
|
OptimizeExpression(I->getOpcode(), Ops);
|
||||||
|
|
||||||
|
// We want to sink immediates as deeply as possible except in the case where
|
||||||
|
// this is a multiply tree used only by an add, and the immediate is a -1.
|
||||||
|
// In this case we reassociate to put the negation on the outside so that we
|
||||||
|
// can fold the negation into the add: (-X)*Y + Z -> Z-X*Y
|
||||||
|
if (I->getOpcode() == Instruction::Mul && I->hasOneUse() &&
|
||||||
|
cast<Instruction>(I->use_back())->getOpcode() == Instruction::Add &&
|
||||||
|
isa<ConstantInt>(Ops.back().Op) &&
|
||||||
|
cast<ConstantInt>(Ops.back().Op)->isAllOnesValue()) {
|
||||||
|
Ops.insert(Ops.begin(), Ops.back());
|
||||||
|
Ops.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
DEBUG(std::cerr << "RAOut:\t"; PrintOps(I->getOpcode(), Ops, BB);
|
DEBUG(std::cerr << "RAOut:\t"; PrintOps(I->getOpcode(), Ops, BB);
|
||||||
std::cerr << "\n");
|
std::cerr << "\n");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user