mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-09 10:31:14 +00:00
don't bother calling ConstantFoldInstruction unless there is a use of the
instruction (which disqualifies stores, unreachable, etc) and at least the first operand is a constant. This filters out a lot of obvious cases that can't be folded. Also, switch the IRBuilder to a TargetFolder, which tries harder. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84170 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
22c031296c
commit
e2cc1ad230
@ -56,6 +56,7 @@
|
|||||||
#include "llvm/Support/IRBuilder.h"
|
#include "llvm/Support/IRBuilder.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
#include "llvm/Support/PatternMatch.h"
|
#include "llvm/Support/PatternMatch.h"
|
||||||
|
#include "llvm/Support/TargetFolder.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
#include "llvm/ADT/SmallVector.h"
|
#include "llvm/ADT/SmallVector.h"
|
||||||
@ -186,7 +187,7 @@ namespace {
|
|||||||
|
|
||||||
/// Builder - This is an IRBuilder that automatically inserts new
|
/// Builder - This is an IRBuilder that automatically inserts new
|
||||||
/// instructions into the worklist when they are created.
|
/// instructions into the worklist when they are created.
|
||||||
typedef IRBuilder<true, ConstantFolder, InstCombineIRInserter> BuilderTy;
|
typedef IRBuilder<true, TargetFolder, InstCombineIRInserter> BuilderTy;
|
||||||
BuilderTy *Builder;
|
BuilderTy *Builder;
|
||||||
|
|
||||||
static char ID; // Pass identification, replacement for typeid
|
static char ID; // Pass identification, replacement for typeid
|
||||||
@ -12704,14 +12705,15 @@ static void AddReachableCodeToWorklist(BasicBlock *BB,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ConstantProp instruction if trivially constant.
|
// ConstantProp instruction if trivially constant.
|
||||||
if (Constant *C = ConstantFoldInstruction(Inst, BB->getContext(), TD)) {
|
if (!Inst->use_empty() && isa<Constant>(Inst->getOperand(0)))
|
||||||
DEBUG(errs() << "IC: ConstFold to: " << *C << " from: "
|
if (Constant *C = ConstantFoldInstruction(Inst, BB->getContext(), TD)) {
|
||||||
<< *Inst << '\n');
|
DEBUG(errs() << "IC: ConstFold to: " << *C << " from: "
|
||||||
Inst->replaceAllUsesWith(C);
|
<< *Inst << '\n');
|
||||||
++NumConstProp;
|
Inst->replaceAllUsesWith(C);
|
||||||
Inst->eraseFromParent();
|
++NumConstProp;
|
||||||
continue;
|
Inst->eraseFromParent();
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
InstrsForInstCombineWorklist.push_back(Inst);
|
InstrsForInstCombineWorklist.push_back(Inst);
|
||||||
}
|
}
|
||||||
@ -12757,7 +12759,6 @@ static void AddReachableCodeToWorklist(BasicBlock *BB,
|
|||||||
|
|
||||||
bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
|
bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
|
||||||
MadeIRChange = false;
|
MadeIRChange = false;
|
||||||
TD = getAnalysisIfAvailable<TargetData>();
|
|
||||||
|
|
||||||
DEBUG(errs() << "\n\nINSTCOMBINE ITERATION #" << Iteration << " on "
|
DEBUG(errs() << "\n\nINSTCOMBINE ITERATION #" << Iteration << " on "
|
||||||
<< F.getNameStr() << "\n");
|
<< F.getNameStr() << "\n");
|
||||||
@ -12810,16 +12811,17 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Instruction isn't dead, see if we can constant propagate it.
|
// Instruction isn't dead, see if we can constant propagate it.
|
||||||
if (Constant *C = ConstantFoldInstruction(I, F.getContext(), TD)) {
|
if (!I->use_empty() && isa<Constant>(I->getOperand(0)))
|
||||||
DEBUG(errs() << "IC: ConstFold to: " << *C << " from: " << *I << '\n');
|
if (Constant *C = ConstantFoldInstruction(I, F.getContext(), TD)) {
|
||||||
|
DEBUG(errs() << "IC: ConstFold to: " << *C << " from: " << *I << '\n');
|
||||||
|
|
||||||
// Add operands to the worklist.
|
// Add operands to the worklist.
|
||||||
ReplaceInstUsesWith(*I, C);
|
ReplaceInstUsesWith(*I, C);
|
||||||
++NumConstProp;
|
++NumConstProp;
|
||||||
EraseInstFromFunction(*I);
|
EraseInstFromFunction(*I);
|
||||||
MadeIRChange = true;
|
MadeIRChange = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TD) {
|
if (TD) {
|
||||||
// See if we can constant fold its operands.
|
// See if we can constant fold its operands.
|
||||||
@ -12927,12 +12929,13 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
|
|||||||
bool InstCombiner::runOnFunction(Function &F) {
|
bool InstCombiner::runOnFunction(Function &F) {
|
||||||
MustPreserveLCSSA = mustPreserveAnalysisID(LCSSAID);
|
MustPreserveLCSSA = mustPreserveAnalysisID(LCSSAID);
|
||||||
Context = &F.getContext();
|
Context = &F.getContext();
|
||||||
|
TD = getAnalysisIfAvailable<TargetData>();
|
||||||
|
|
||||||
|
|
||||||
/// Builder - This is an IRBuilder that automatically inserts new
|
/// Builder - This is an IRBuilder that automatically inserts new
|
||||||
/// instructions into the worklist when they are created.
|
/// instructions into the worklist when they are created.
|
||||||
IRBuilder<true, ConstantFolder, InstCombineIRInserter>
|
IRBuilder<true, TargetFolder, InstCombineIRInserter>
|
||||||
TheBuilder(F.getContext(), ConstantFolder(F.getContext()),
|
TheBuilder(F.getContext(), TargetFolder(TD, F.getContext()),
|
||||||
InstCombineIRInserter(Worklist));
|
InstCombineIRInserter(Worklist));
|
||||||
Builder = &TheBuilder;
|
Builder = &TheBuilder;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user