[Mlir-commits] [mlir] [mlir][analysis] Add interprocedural analysis to LocalAliasAnalysis (PR #177994)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon Jan 26 08:58:41 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: lonely eagle (linuxlonelyeagle)

<details>
<summary>Changes</summary>



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


1 Files Affected:

- (modified) mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp (+38) 


``````````diff
diff --git a/mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp b/mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp
index 5a4679ef31422..acec7ed144929 100644
--- a/mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp
+++ b/mlir/lib/Analysis/AliasAnalysis/LocalAliasAnalysis.cpp
@@ -339,6 +339,44 @@ AliasResult LocalAliasAnalysis::aliasImpl(Value lhs, Value rhs) {
     return AliasResult::MustAlias;
   }
 
+  // If both the lhs and rhs are function arguments, we perform interprocedural
+  // analysis.
+  if (isa<BlockArgument>(lhs) && isa<BlockArgument>(rhs) &&
+      lhs.getParentRegion() && lhs.getParentRegion() == rhs.getParentRegion() &&
+      isa<FunctionOpInterface>(lhs.getParentRegion()->getParentOp())) {
+    BlockArgument lhsArg = dyn_cast<BlockArgument>(lhs);
+    BlockArgument rhsArg = dyn_cast<BlockArgument>(rhs);
+    FunctionOpInterface function =
+        cast<FunctionOpInterface>(lhs.getParentRegion()->getParentOp());
+    // There are unknown function calls, so we cannot perform the analysis, we
+    // assume the result is MayAlias.
+    if (!function.isPrivate())
+      return AliasResult::MayAlias;
+
+    size_t mustAlias = 0, mayAlias = 0, noAlias = 0;
+    if (std::optional<SymbolTable::UseRange> uses =
+            function.getSymbolUses(function->getParentOfType<ModuleOp>())) {
+      for (auto use : *uses) {
+        Operation *user = use.getUser();
+        AliasResult userResult =
+            aliasImpl(user->getOperand(lhsArg.getArgNumber()),
+                      user->getOperand(rhsArg.getArgNumber()));
+        if (userResult.isNo())
+          ++noAlias;
+        else if (userResult.isMay())
+          ++mayAlias;
+        else if (userResult.isMust())
+          ++mustAlias;
+      }
+    }
+    if (mayAlias || (noAlias && mustAlias))
+      return AliasResult::MayAlias;
+    else if (noAlias)
+      return AliasResult::NoAlias;
+    else if (mustAlias)
+      return AliasResult::MustAlias;
+  }
+
   Operation *lhsAllocScope = nullptr, *rhsAllocScope = nullptr;
   std::optional<MemoryEffects::EffectInstance> lhsAlloc, rhsAlloc;
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/177994


More information about the Mlir-commits mailing list