diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp index 805bbe40bd7c7..444c412c02b7e 100644 --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -1466,7 +1466,7 @@ bool MemCpyOptPass::performStackMoveOptzn(Instruction *Load, Instruction *Store, // to remove them. SmallVector LifetimeMarkers; - SmallSet NoAliasInstrs; + SmallSet AAMetadataInstrs; bool SrcNotDom = false; // Recursively track the user and check whether modified alias exist. @@ -1521,8 +1521,7 @@ bool MemCpyOptPass::performStackMoveOptzn(Instruction *Load, Instruction *Store, continue; } } - if (UI->hasMetadata(LLVMContext::MD_noalias)) - NoAliasInstrs.insert(UI); + AAMetadataInstrs.insert(UI); if (!ModRefCallback(UI)) return false; } @@ -1630,9 +1629,22 @@ bool MemCpyOptPass::performStackMoveOptzn(Instruction *Load, Instruction *Store, // alias to begin to alias one another, we remove !noalias metadata from any // uses of either alloca. This is conservative, but more precision doesn't // seem worthwhile right now. - for (Instruction *I : NoAliasInstrs) + for (Instruction *I : AAMetadataInstrs) { + + + I->setMetadata(LLVMContext::MD_alias_scope, nullptr); + I->setMetadata(LLVMContext::MD_noalias, nullptr); + + I->setMetadata(LLVMContext::MD_tbaa, nullptr); + + + I->setMetadata(LLVMContext::MD_tbaa_struct, nullptr); + + + } + LLVM_DEBUG(dbgs() << "Stack Move: Performed staack-move optimization\n"); NumStackMove++; return true;