Skip to content

[MergedLoadStore] Preserve common metadata when sinking stores. #116382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"

using namespace llvm;

Expand Down Expand Up @@ -255,7 +256,8 @@ void MergedLoadStoreMotion::sinkStoresAndGEPs(BasicBlock *BB, StoreInst *S0,
BasicBlock::iterator InsertPt = BB->getFirstInsertionPt();
// Intersect optional metadata.
S0->andIRFlags(S1);
S0->dropUnknownNonDebugMetadata();

combineMetadataForCSE(S0, S1, true);
S0->applyMergedLocation(S0->getDebugLoc(), S1->getDebugLoc());
S0->mergeDIAssignID(S1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32"

; FIXME: Can preserve common metadata on the sunk store.
define void @perserve_common_metadata(i1 %c, ptr %dst, ptr %min) {
; CHECK-LABEL: define void @perserve_common_metadata(
; CHECK-SAME: i1 [[C:%.*]], ptr [[DST:%.*]], ptr [[MIN:%.*]]) {
Expand All @@ -19,7 +18,7 @@ define void @perserve_common_metadata(i1 %c, ptr %dst, ptr %min) {
; CHECK-NEXT: br label %[[RETURN]]
; CHECK: [[RETURN]]:
; CHECK-NEXT: [[DOTSINK:%.*]] = phi ptr [ [[DST]], %[[THEN]] ], [ null, %[[ELSE]] ]
; CHECK-NEXT: store ptr [[DOTSINK]], ptr [[GEP_DST_16]], align 8
; CHECK-NEXT: store ptr [[DOTSINK]], ptr [[GEP_DST_16]], align 8, !tbaa [[TBAA4:![0-9]+]], !alias.scope [[META6:![0-9]+]], !noalias [[META6]], !llvm.access.group [[ACC_GRP9:![0-9]+]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove FIXME above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks!

; CHECK-NEXT: ret void
;
entry:
Expand Down Expand Up @@ -48,7 +47,7 @@ define void @clear_different_metadata(i1 %c, ptr %dst, ptr %min) {
; CHECK-NEXT: [[GEP_DST_16:%.*]] = getelementptr inbounds nuw i8, ptr [[DST]], i64 16
; CHECK-NEXT: br i1 [[C]], label %[[THEN:.*]], label %[[ELSE:.*]]
; CHECK: [[THEN]]:
; CHECK-NEXT: store ptr [[DST]], ptr [[MIN]], align 8, !tbaa [[TBAA4:![0-9]+]]
; CHECK-NEXT: store ptr [[DST]], ptr [[MIN]], align 8, !tbaa [[TBAA10:![0-9]+]]
; CHECK-NEXT: br label %[[RETURN:.*]]
; CHECK: [[ELSE]]:
; CHECK-NEXT: [[GEP_DST_24:%.*]] = getelementptr inbounds nuw i8, ptr [[DST]], i64 24
Expand Down Expand Up @@ -99,6 +98,12 @@ return:
; CHECK: [[META2]] = !{!"omnipotent char", [[META3:![0-9]+]], i64 0}
; CHECK: [[META3]] = !{!"Simple C++ TBAA"}
; CHECK: [[TBAA4]] = !{[[META5:![0-9]+]], [[META5]], i64 0, i64 0}
; CHECK: [[META5]] = !{!"p2 _Foo", [[META6:![0-9]+]]}
; CHECK: [[META6]] = !{!"any pointer", [[META2]], i64 0}
; CHECK: [[META5]] = !{!"long", [[META2]]}
; CHECK: [[META6]] = !{[[META7:![0-9]+]]}
; CHECK: [[META7]] = distinct !{[[META7]], [[META8:![0-9]+]]}
; CHECK: [[META8]] = distinct !{[[META8]]}
; CHECK: [[ACC_GRP9]] = distinct !{}
; CHECK: [[TBAA10]] = !{[[META11:![0-9]+]], [[META11]], i64 0, i64 0}
; CHECK: [[META11]] = !{!"p2 _Foo", [[META12:![0-9]+]]}
; CHECK: [[META12]] = !{!"any pointer", [[META2]], i64 0}
;.
Loading