[llvm-commits] [llvm] r39753 - /llvm/trunk/lib/Transforms/Scalar/FastDSE.cpp
Chris Lattner
clattner at apple.com
Wed Jul 11 14:57:31 PDT 2007
On Jul 11, 2007, at 1:38 PM, Owen Anderson wrote:
> Author: resistor
> Date: Wed Jul 11 15:38:34 2007
> New Revision: 39753
>
> URL: http://llvm.org/viewvc/llvm-project?rev=39753&view=rev
> Log:
> Handle eliminating stores that occur right before a free.
Don't forget that "free" deallocates the whole object, not just the
pointer passed in. This store should be nuked:
int *P = ...
P[1] = 0;
free(P);
-Chris
> Modified:
> llvm/trunk/lib/Transforms/Scalar/FastDSE.cpp
>
> Modified: llvm/trunk/lib/Transforms/Scalar/FastDSE.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/
> Scalar/FastDSE.cpp?rev=39753&r1=39752&r2=39753&view=diff
>
> ======================================================================
> ========
> --- llvm/trunk/lib/Transforms/Scalar/FastDSE.cpp (original)
> +++ llvm/trunk/lib/Transforms/Scalar/FastDSE.cpp Wed Jul 11
> 15:38:34 2007
> @@ -74,14 +74,22 @@
> // Do a top-down walk on the BB
> for (BasicBlock::iterator BBI = BB.begin(), BBE = BB.end(); BBI !
> = BBE; ++BBI) {
> // If we find a store...
> - if (StoreInst* S = dyn_cast<StoreInst>(BBI)) {
> - StoreInst*& last = lastStore[S->getPointerOperand()];
> + if (isa<StoreInst>(BBI) || isa<FreeInst>(BBI)) {
> + Value* pointer = 0;
> + if (StoreInst* S = dyn_cast<StoreInst>(BBI))
> + pointer = S->getPointerOperand();
> + else if (FreeInst* F = dyn_cast<FreeInst>(BBI))
> + pointer = F->getPointerOperand();
> + assert(pointer && "Not a free or a store?");
> +
> + StoreInst*& last = lastStore[pointer];
>
> // ... to a pointer that has been stored to before...
> if (last) {
>
> // ... and no other memory dependencies are between them....
> - if (MD.getDependency(S) == last) {
> + if (MD.getDependency(BBI) == last) {
> +
> // Remove it!
> MD.removeInstruction(last);
>
> @@ -96,7 +104,10 @@
> }
>
> // Update our most-recent-store map
> - last = S;
> + if (StoreInst* S = dyn_cast<StoreInst>(BBI))
> + last = S;
> + else
> + last = 0;
> }
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list