Skip to content
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

[GVNHoist] Replace combineKnownMetadata with combineMetadataForCSE #92197

Merged
merged 1 commit into from
May 15, 2024

Conversation

hiraditya
Copy link
Collaborator

There is no reason to call combineMetadata directly with a list of MD_ nodes. The combineMetadataForCSE function handles all the metadata correctly

Partially fixes: #30866

There is no reason to call combineMetadata directly with a list of
MD_ nodes. The combineMetadataForCSE function handles all the metadata
correctly

Partially fixes: llvm#30866
@llvmbot
Copy link
Collaborator

llvmbot commented May 15, 2024

@llvm/pr-subscribers-llvm-transforms

Author: AdityaK (hiraditya)

Changes

There is no reason to call combineMetadata directly with a list of MD_ nodes. The combineMetadataForCSE function handles all the metadata correctly

Partially fixes: #30866


Full diff: https://github.com/llvm/llvm-project/pull/92197.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Scalar/GVNHoist.cpp (+1-13)
diff --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp b/llvm/lib/Transforms/Scalar/GVNHoist.cpp
index 261c1259c9c96..b5333c532280c 100644
--- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp
+++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp
@@ -238,18 +238,6 @@ class CallInfo {
   const VNtoInsns &getStoreVNTable() const { return VNtoCallsStores; }
 };
 
-static void combineKnownMetadata(Instruction *ReplInst, Instruction *I) {
-  static const unsigned KnownIDs[] = {LLVMContext::MD_tbaa,
-                                      LLVMContext::MD_alias_scope,
-                                      LLVMContext::MD_noalias,
-                                      LLVMContext::MD_range,
-                                      LLVMContext::MD_fpmath,
-                                      LLVMContext::MD_invariant_load,
-                                      LLVMContext::MD_invariant_group,
-                                      LLVMContext::MD_access_group};
-  combineMetadata(ReplInst, I, KnownIDs, true);
-}
-
 // This pass hoists common computations across branches sharing common
 // dominator. The primary goal is to reduce the code size, and in some
 // cases reduce critical path (by exposing more ILP).
@@ -996,8 +984,8 @@ unsigned GVNHoist::rauw(const SmallVecInsn &Candidates, Instruction *Repl,
         MSSAUpdater->removeMemoryAccess(OldMA);
       }
 
+      combineMetadataForCSE(Repl, I, true);
       Repl->andIRFlags(I);
-      combineKnownMetadata(Repl, I);
       I->replaceAllUsesWith(Repl);
       // Also invalidate the Alias Analysis cache.
       MD->removeInstruction(I);

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

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

LGTM

@nikic nikic changed the title Replace combineKnownMetadata with combineMetadataForCSE [GVNSink] Replace combineKnownMetadata with combineMetadataForCSE May 15, 2024
@@ -996,8 +984,8 @@ unsigned GVNHoist::rauw(const SmallVecInsn &Candidates, Instruction *Repl,
MSSAUpdater->removeMemoryAccess(OldMA);
}

combineMetadataForCSE(Repl, I, true);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moving combineMetadataForCSE above andIRFlags is intentional for two reasons.

  1. In future if andIRFlags does something to manipulate metadata(unlikely), calling it later makes this pass more resilient to change.
  2. GVNSink takes a similar approach. https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Scalar/GVNSink.cpp#L920

@nikic nikic changed the title [GVNSink] Replace combineKnownMetadata with combineMetadataForCSE [GVNHoist] Replace combineKnownMetadata with combineMetadataForCSE May 15, 2024
@hiraditya hiraditya merged commit b42d245 into llvm:main May 15, 2024
6 checks passed
@hiraditya hiraditya deleted the gvnhoist_metadata branch May 15, 2024 14:44
mub-at-arm pushed a commit to mub-at-arm/llvm-project that referenced this pull request May 16, 2024
…lvm#92197)

There is no reason to call combineMetadata directly with a list of MD_
nodes. The combineMetadataForCSE function handles all the metadata
correctly

Partially fixes: llvm#30866
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

refactor metadata propagation for consistency and completeness
3 participants