[llvm-branch-commits] [llvm] [Attributor] Use `getAssumedAddrSpace` to get address space for `AllocaInst` (PR #136865)

Shilei Tian via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Apr 23 10:57:32 PDT 2025


================
@@ -12603,6 +12603,18 @@ struct AAAddressSpaceImpl : public AAAddressSpace {
     auto CheckAddressSpace = [&](Value &Obj) {
       if (isa<UndefValue>(&Obj))
         return true;
+      // Some targets relax the requirement for alloca to be in an exact address
+      // space, allowing it in certain other address spaces instead. These
+      // targets later lower alloca to the correct address space in the
+      // pipeline. Therefore, we need to query TTI to determine the appropriate
+      // address space.
+      if (auto *AI = dyn_cast<AllocaInst>(&Obj)) {
+        Function *Fn = AI->getFunction();
+        auto *TTI =
+            A.getInfoCache().getAnalysisResultForFunction<TargetIRAnalysis>(
+                *Fn);
+        return takeAddressSpace(TTI->getAssumedAddrSpace(AI));
----------------
shiltian wrote:

This file is in middle end, so we can't access target machine, same as InferAddressSpacePass.

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


More information about the llvm-branch-commits mailing list