[PATCH] D117679: [MemCpyOpt] Fix metadata merging during call slot optimization

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 19 06:59:11 PST 2022


nikic created this revision.
nikic added reviewers: reames, jeroen.dobbelaere, jdoerfert, hans.
Herald added a subscriber: hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


https://reviews.llvm.org/D117679

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


Index: llvm/test/Transforms/MemCpyOpt/callslot_noalias.ll
===================================================================
--- llvm/test/Transforms/MemCpyOpt/callslot_noalias.ll
+++ 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]]
 ;
Index: llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -1022,6 +1022,8 @@
                          LLVMContext::MD_invariant_group,
                          LLVMContext::MD_access_group};
   combineMetadata(C, cpyLoad, KnownIDs, true);
+  if (cpyLoad != cpyStore)
+    combineMetadata(C, cpyStore, KnownIDs, true);
 
   ++NumCallSlot;
   return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D117679.401223.patch
Type: text/x-patch
Size: 1422 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220119/6012070a/attachment.bin>


More information about the llvm-commits mailing list