-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
When sinking a store, preserve common metadata present on stores on both sides of the diamond.
for (const auto &[Kind, MD] : MDs) | ||
if (S1->getMetadata(Kind) == MD) | ||
CommonMDs.push_back(Kind); | ||
S0->dropUnknownNonDebugMetadata(CommonMDs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we be using combineMetadataForCSE here with DoesKMove=true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah updated. Originally thought this might not be completely right, but should be fine after a second thought, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -19,7 +19,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]+]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove FIXME above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thanks!
@llvm/pr-subscribers-llvm-transforms Author: Florian Hahn (fhahn) ChangesWhen sinking a store, preserve common metadata present on stores on both sides of the diamond. Full diff: https://github.com/llvm/llvm-project/pull/116382.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp b/llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp
index 299239fb70200b..cc67a455672be4 100644
--- a/llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp
+++ b/llvm/lib/Transforms/Scalar/MergedLoadStoreMotion.cpp
@@ -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;
@@ -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);
diff --git a/llvm/test/Transforms/MergedLoadStoreMotion/preserve-store-metadata.ll b/llvm/test/Transforms/MergedLoadStoreMotion/preserve-store-metadata.ll
index f733003e90729b..33e37c97b7a0ef 100644
--- a/llvm/test/Transforms/MergedLoadStoreMotion/preserve-store-metadata.ll
+++ b/llvm/test/Transforms/MergedLoadStoreMotion/preserve-store-metadata.ll
@@ -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:%.*]]) {
@@ -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]+]]
; CHECK-NEXT: ret void
;
entry:
@@ -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
@@ -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}
;.
|
…#116382) When sinking a store, preserve common metadata present on stores on both sides of the diamond. PR: llvm#116382 (cherry picked from commit 3734e4c)
When sinking a store, preserve common metadata present on stores on both sides of the diamond.