[MemCpyOpt] Avoid double invalidation (NFCI)
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 2 Oct 2020 19:47:03 +0000 (21:47 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 2 Oct 2020 19:50:46 +0000 (21:50 +0200)
The removal of the cpy instruction is left to the caller of
performCallSlotOptzn(), including the invalidation of MD. Both
call-sites already do this.

Also handle incrementation of NumMemCpyInstr consistently at the
call-site. One of the call-site was already doing this, which
ended up incrementing the statistic twice.

This fix was part of D26739.

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

index 01f3c32..4d30804 100644 (file)
@@ -953,10 +953,6 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpy, Value *cpyDest,
                          LLVMContext::MD_access_group};
   combineMetadata(C, cpy, KnownIDs, true);
 
-  // Remove the memcpy.
-  MD->removeInstruction(cpy);
-  ++NumMemCpyInstr;
-
   return true;
 }
 
@@ -1272,6 +1268,7 @@ bool MemCpyOptPass::processMemCpy(MemCpyInst *M, BasicBlock::iterator &BBI) {
 
         MD->removeInstruction(M);
         M->eraseFromParent();
+        ++NumMemCpyInstr;
         return true;
       }
     }