[llvm-commits] [llvm] r40809 - /llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
Reid Spencer
rspencer at reidspencer.com
Fri Aug 3 23:21:24 PDT 2007
On Sat, 2007-08-04 at 02:15 +0000, Chris Lattner wrote:
> Author: lattner
> Date: Fri Aug 3 21:15:24 2007
> New Revision: 40809
>
> URL: http://llvm.org/viewvc/llvm-project?rev=40809&view=rev
> Log:
> In mem2reg, when handling the single-store case, make sure to remove
> a using block from the list if we handle it. Not doing this caused us
> to not be able to promote (with the fast path) allocas which have uses (whoops).
>
> This increases the # allocas hitting this fastpath from 4042 to 8935 on the
> testcase in PR1432, speeding up mem2reg by 2.6x
Whoa! Nice!
Reid.
>
>
> Modified:
> llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
>
> Modified: llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp?rev=40809&r1=40808&r2=40809&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Fri Aug 3 21:15:24 2007
> @@ -531,28 +531,29 @@
> /// the value stored.
> void PromoteMem2Reg::RewriteSingleStoreAlloca(AllocaInst *AI,
> AllocaInfo &Info) {
> + StoreInst *OnlyStore = Info.OnlyStore;
> +
> // Be aware of loads before the store.
> std::set<BasicBlock*> ProcessedBlocks;
> for (unsigned i = 0, e = Info.UsingBlocks.size(); i != e; ++i) {
> // If the store dominates the block and if we haven't processed it yet,
> // do so now.
> - if (!dominates(Info.OnlyStore->getParent(), Info.UsingBlocks[i]))
> - continue;
> -
> - if (!ProcessedBlocks.insert(Info.UsingBlocks[i]).second)
> + if (!dominates(OnlyStore->getParent(), Info.UsingBlocks[i]))
> continue;
>
> BasicBlock *UseBlock = Info.UsingBlocks[i];
> + if (!ProcessedBlocks.insert(UseBlock).second)
> + continue;
>
> // If the use and store are in the same block, do a quick scan to
> // verify that there are no uses before the store.
> - if (UseBlock == Info.OnlyStore->getParent()) {
> + if (UseBlock == OnlyStore->getParent()) {
> BasicBlock::iterator I = UseBlock->begin();
> - for (; &*I != Info.OnlyStore; ++I) { // scan block for store.
> + for (; &*I != OnlyStore; ++I) { // scan block for store.
> if (isa<LoadInst>(I) && I->getOperand(0) == AI)
> break;
> }
> - if (&*I != Info.OnlyStore) break; // Do not handle this case.
> + if (&*I != OnlyStore) break; // Do not handle this case.
> }
>
> // Otherwise, if this is a different block or if all uses happen
> @@ -562,7 +563,7 @@
> I != E; ) {
> if (LoadInst *LI = dyn_cast<LoadInst>(I++)) {
> if (LI->getOperand(0) == AI) {
> - LI->replaceAllUsesWith(Info.OnlyStore->getOperand(0));
> + LI->replaceAllUsesWith(OnlyStore->getOperand(0));
> if (AST && isa<PointerType>(LI->getType()))
> AST->deleteValue(LI);
> LI->eraseFromParent();
> @@ -572,6 +573,7 @@
>
> // Finally, remove this block from the UsingBlock set.
> Info.UsingBlocks[i] = Info.UsingBlocks.back();
> + Info.UsingBlocks.pop_back();
> --i; --e;
> }
> }
>
>
> _______________________________________________
> 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