From: Chris Lattner Date: Mon, 31 Jan 2005 05:36:43 +0000 (+0000) Subject: Implement the trivial cases in InstCombine/store.ll X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=2f503e6c27fa2a24209047cffcaf0af3199dde3a;p=oota-llvm.git Implement the trivial cases in InstCombine/store.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19950 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 956bb1e0139..885355dc0b8 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -130,6 +130,7 @@ namespace { Instruction *visitAllocationInst(AllocationInst &AI); Instruction *visitFreeInst(FreeInst &FI); Instruction *visitLoadInst(LoadInst &LI); + Instruction *visitStoreInst(StoreInst &SI); Instruction *visitBranchInst(BranchInst &BI); Instruction *visitSwitchInst(SwitchInst &SI); @@ -4804,6 +4805,42 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) { return 0; } +Instruction *InstCombiner::visitStoreInst(StoreInst &SI) { + Value *Val = SI.getOperand(0); + Value *Ptr = SI.getOperand(1); + + if (isa(Ptr)) { // store X, undef -> noop (even if volatile) + removeFromWorkList(&SI); + SI.eraseFromParent(); + ++NumCombined; + return 0; + } + + if (SI.isVolatile()) return 0; // Don't hack volatile loads. + + // store X, null -> turns into 'unreachable' in SimplifyCFG + if (isa(Ptr)) { + if (!isa(Val)) { + SI.setOperand(0, UndefValue::get(Val->getType())); + if (Instruction *U = dyn_cast(Val)) + WorkList.push_back(U); // Dropped a use. + ++NumCombined; + } + return 0; // Do not modify these! + } + + // store undef, Ptr -> noop + if (isa(Val)) { + removeFromWorkList(&SI); + SI.eraseFromParent(); + ++NumCombined; + return 0; + } + + return 0; +} + + Instruction *InstCombiner::visitBranchInst(BranchInst &BI) { // Change br (not X), label True, label False to: br X, label False, True Value *X; @@ -5039,7 +5076,7 @@ bool InstCombiner::runOnFunction(Function &F) { // Instructions may end up in the worklist more than once. Erase all // occurrances of this instruction. removeFromWorkList(I); - I->getParent()->getInstList().erase(I); + I->eraseFromParent(); } else { WorkList.push_back(Result); AddUsersToWorkList(*Result);