mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-26 05:25:47 +00:00
improve DSE when TargetData is not around, based on work by
Hans Wennborg! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86067 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -78,6 +78,21 @@ static RegisterPass<DSE> X("dse", "Dead Store Elimination");
|
|||||||
|
|
||||||
FunctionPass *llvm::createDeadStoreEliminationPass() { return new DSE(); }
|
FunctionPass *llvm::createDeadStoreEliminationPass() { return new DSE(); }
|
||||||
|
|
||||||
|
/// isValueAtLeastAsBigAs - Return true if V1 is greater than or equal to the
|
||||||
|
/// stored size of V2. This returns false if we don't know.
|
||||||
|
///
|
||||||
|
static bool isValueAtLeastAsBigAs(Value *V1, Value *V2, const TargetData *TD) {
|
||||||
|
const Type *V1Ty = V1->getType(), *V2Ty = V2->getType();
|
||||||
|
|
||||||
|
// Exactly the same type, must have exactly the same size.
|
||||||
|
if (V1Ty == V2Ty) return true;
|
||||||
|
|
||||||
|
// If we don't have target data, we don't know.
|
||||||
|
if (TD == 0) return false;
|
||||||
|
|
||||||
|
return TD->getTypeStoreSize(V1Ty) >= TD->getTypeStoreSize(V2Ty);
|
||||||
|
}
|
||||||
|
|
||||||
bool DSE::runOnBasicBlock(BasicBlock &BB) {
|
bool DSE::runOnBasicBlock(BasicBlock &BB) {
|
||||||
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
|
MemoryDependenceAnalysis& MD = getAnalysis<MemoryDependenceAnalysis>();
|
||||||
TD = getAnalysisIfAvailable<TargetData>();
|
TD = getAnalysisIfAvailable<TargetData>();
|
||||||
@@ -118,9 +133,7 @@ bool DSE::runOnBasicBlock(BasicBlock &BB) {
|
|||||||
// If this is a store-store dependence, then the previous store is dead so
|
// If this is a store-store dependence, then the previous store is dead so
|
||||||
// long as this store is at least as big as it.
|
// long as this store is at least as big as it.
|
||||||
if (StoreInst *DepStore = dyn_cast<StoreInst>(InstDep.getInst()))
|
if (StoreInst *DepStore = dyn_cast<StoreInst>(InstDep.getInst()))
|
||||||
if (TD &&
|
if (isValueAtLeastAsBigAs(SI->getOperand(0), DepStore->getOperand(0),TD)){
|
||||||
TD->getTypeStoreSize(DepStore->getOperand(0)->getType()) <=
|
|
||||||
TD->getTypeStoreSize(SI->getOperand(0)->getType())) {
|
|
||||||
// Delete the store and now-dead instructions that feed it.
|
// Delete the store and now-dead instructions that feed it.
|
||||||
DeleteDeadInstruction(DepStore);
|
DeleteDeadInstruction(DepStore);
|
||||||
NumFastStores++;
|
NumFastStores++;
|
||||||
|
@@ -68,9 +68,6 @@ namespace {
|
|||||||
static char ID; // Pass identification
|
static char ID; // Pass identification
|
||||||
JumpThreading() : FunctionPass(&ID) {}
|
JumpThreading() : FunctionPass(&ID) {}
|
||||||
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
|
||||||
}
|
|
||||||
|
|
||||||
bool runOnFunction(Function &F);
|
bool runOnFunction(Function &F);
|
||||||
void FindLoopHeaders(Function &F);
|
void FindLoopHeaders(Function &F);
|
||||||
|
|
||||||
|
15
test/Transforms/DeadStoreElimination/no-targetdata.ll
Normal file
15
test/Transforms/DeadStoreElimination/no-targetdata.ll
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
; RUN: opt %s -dse -S | FileCheck %s
|
||||||
|
|
||||||
|
declare void @test1f()
|
||||||
|
|
||||||
|
define void @test1(i32* noalias %p) {
|
||||||
|
store i32 1, i32* %p;
|
||||||
|
call void @test1f()
|
||||||
|
store i32 2, i32 *%p
|
||||||
|
ret void
|
||||||
|
; CHECK: define void @test1
|
||||||
|
; CHECK-NOT: store
|
||||||
|
; CHECK-NEXT: call void
|
||||||
|
; CHECK-NEXT: store i32 2
|
||||||
|
; CHECK-NEXT: ret void
|
||||||
|
}
|
Reference in New Issue
Block a user