Skip to content

Conversation

@artagnon
Copy link
Contributor

This allows us to strip an unnecessary TypeSwitch.

This allows us to strip an unnecessary TypeSwitch.
@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Ramkumar Ramachandra (artagnon)

Changes

This allows us to strip an unnecessary TypeSwitch.


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/VPlanUtils.cpp (+10-13)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
index 2536d61392ed1..cffc40960e47c 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
@@ -397,17 +397,14 @@ bool VPBlockUtils::isLatch(const VPBlockBase *VPB,
 
 std::optional<MemoryLocation>
 vputils::getMemoryLocation(const VPRecipeBase &R) {
-  return TypeSwitch<const VPRecipeBase *, std::optional<MemoryLocation>>(&R)
-      .Case<VPWidenMemoryRecipe, VPInterleaveBase, VPReplicateRecipe>(
-          [](auto *S) {
-            MemoryLocation Loc;
-            // Populate noalias metadata from VPIRMetadata.
-            if (MDNode *NoAliasMD = S->getMetadata(LLVMContext::MD_noalias))
-              Loc.AATags.NoAlias = NoAliasMD;
-            if (MDNode *AliasScopeMD =
-                    S->getMetadata(LLVMContext::MD_alias_scope))
-              Loc.AATags.Scope = AliasScopeMD;
-            return Loc;
-          })
-      .Default([](auto *) { return std::nullopt; });
+  auto *M = dyn_cast<VPIRMetadata>(&R);
+  if (!M)
+    return std::nullopt;
+  MemoryLocation Loc;
+  // Populate noalias metadata from VPIRMetadata.
+  if (MDNode *NoAliasMD = M->getMetadata(LLVMContext::MD_noalias))
+    Loc.AATags.NoAlias = NoAliasMD;
+  if (MDNode *AliasScopeMD = M->getMetadata(LLVMContext::MD_alias_scope))
+    Loc.AATags.Scope = AliasScopeMD;
+  return Loc;
 }

@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2025

@llvm/pr-subscribers-vectorizers

Author: Ramkumar Ramachandra (artagnon)

Changes

This allows us to strip an unnecessary TypeSwitch.


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Vectorize/VPlanUtils.cpp (+10-13)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
index 2536d61392ed1..cffc40960e47c 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanUtils.cpp
@@ -397,17 +397,14 @@ bool VPBlockUtils::isLatch(const VPBlockBase *VPB,
 
 std::optional<MemoryLocation>
 vputils::getMemoryLocation(const VPRecipeBase &R) {
-  return TypeSwitch<const VPRecipeBase *, std::optional<MemoryLocation>>(&R)
-      .Case<VPWidenMemoryRecipe, VPInterleaveBase, VPReplicateRecipe>(
-          [](auto *S) {
-            MemoryLocation Loc;
-            // Populate noalias metadata from VPIRMetadata.
-            if (MDNode *NoAliasMD = S->getMetadata(LLVMContext::MD_noalias))
-              Loc.AATags.NoAlias = NoAliasMD;
-            if (MDNode *AliasScopeMD =
-                    S->getMetadata(LLVMContext::MD_alias_scope))
-              Loc.AATags.Scope = AliasScopeMD;
-            return Loc;
-          })
-      .Default([](auto *) { return std::nullopt; });
+  auto *M = dyn_cast<VPIRMetadata>(&R);
+  if (!M)
+    return std::nullopt;
+  MemoryLocation Loc;
+  // Populate noalias metadata from VPIRMetadata.
+  if (MDNode *NoAliasMD = M->getMetadata(LLVMContext::MD_noalias))
+    Loc.AATags.NoAlias = NoAliasMD;
+  if (MDNode *AliasScopeMD = M->getMetadata(LLVMContext::MD_alias_scope))
+    Loc.AATags.Scope = AliasScopeMD;
+  return Loc;
 }

@github-actions
Copy link

🐧 Linux x64 Test Results

  • 186433 tests passed
  • 4868 tests skipped

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

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

LGTM, thanks.

For the titel, maybe clarify that this use dyn_cast to VPIRMetadata

@artagnon artagnon changed the title [VPlan] Directly retrieve metadata in getMemoryLocation (NFC) [VPlan] Cast to VPIRMetadata in getMemoryLocation (NFC) Nov 21, 2025
@artagnon artagnon merged commit b98f6a5 into llvm:main Nov 21, 2025
13 checks passed
@artagnon artagnon deleted the vplan-getmemloc-md-nfc branch November 21, 2025 14:23
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.

3 participants