[llvm] d7bff2e - [MemCpyOpt] Fix metadata merging during call slot optimization

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 20 00:26:24 PST 2022


Author: Nikita Popov
Date: 2022-01-20T09:25:13+01:00
New Revision: d7bff2e9d2e4639ab7f3b5df49c235b9eeebdb51

URL: https://github.com/llvm/llvm-project/commit/d7bff2e9d2e4639ab7f3b5df49c235b9eeebdb51
DIFF: https://github.com/llvm/llvm-project/commit/d7bff2e9d2e4639ab7f3b5df49c235b9eeebdb51.diff

LOG: [MemCpyOpt] Fix metadata merging during call slot optimization

Call slot optimization currently merges the metadata between the
call and the load. However, we also need to merge in the metadata
of the store.

Part of the reason why we might have gotten away with this
previously is that usually the load and the store are the same
instruction (a memcpy), this can only happen if call slot
optimization occurs on an actual load/store pair.

This addresses the issue reported in
https://reviews.llvm.org/D115615#3251386.

Differential Revision: https://reviews.llvm.org/D117679

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
    llvm/test/Transforms/MemCpyOpt/callslot_noalias.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 4a42753fd78bd..8a8dad4a73510 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -1022,6 +1022,8 @@ bool MemCpyOptPass::performCallSlotOptzn(Instruction *cpyLoad,
                          LLVMContext::MD_invariant_group,
                          LLVMContext::MD_access_group};
   combineMetadata(C, cpyLoad, KnownIDs, true);
+  if (cpyLoad != cpyStore)
+    combineMetadata(C, cpyStore, KnownIDs, true);
 
   ++NumCallSlot;
   return true;

diff  --git a/llvm/test/Transforms/MemCpyOpt/callslot_noalias.ll b/llvm/test/Transforms/MemCpyOpt/callslot_noalias.ll
index 0a6008a7119f1..63358055bc3c2 100644
--- a/llvm/test/Transforms/MemCpyOpt/callslot_noalias.ll
+++ b/llvm/test/Transforms/MemCpyOpt/callslot_noalias.ll
@@ -3,11 +3,12 @@
 
 declare void @func(i8* %dst)
 
-; TODO: The noalias metadata on the call is currently incorrect.
+; The noalias metadata from the call, the load and the store should be merged,
+; so that no metadata is left on the call.
 define i8 @test(i8* dereferenceable(1) noalias %dst) {
 ; CHECK-LABEL: @test(
 ; CHECK-NEXT:    [[TMP:%.*]] = alloca i8, align 1
-; CHECK-NEXT:    call void @func(i8* nocapture [[DST:%.*]]) #[[ATTR0:[0-9]+]], !noalias !0
+; CHECK-NEXT:    call void @func(i8* nocapture [[DST:%.*]]) #[[ATTR0:[0-9]+]]{{$}}
 ; CHECK-NEXT:    [[V2:%.*]] = load i8, i8* [[DST]], align 1, !alias.scope !0
 ; CHECK-NEXT:    ret i8 [[V2]]
 ;


        


More information about the llvm-commits mailing list