[llvm] [Attributor] Avoid AS-cast for function pointers (PR #65825)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 8 23:49:12 PDT 2023


================
@@ -12304,11 +12304,31 @@ struct AAIndirectCallInfoCallSite : public AAIndirectCallInfo {
                         UsedAssumedInformation))
       return ChangeStatus::UNCHANGED;
 
+    const auto *TTI =
+        A.getInfoCache().getAnalysisResultForFunction<TargetIRAnalysis>(
+            *CB->getFunction());
+    const DataLayout &DL = A.getDataLayout();
+    LLVMContext &Ctx = CB->getContext();
+
     ChangeStatus Changed = ChangeStatus::UNCHANGED;
     Value *FP = CB->getCalledOperand();
-    if (FP->getType()->getPointerAddressSpace())
-      FP = new AddrSpaceCastInst(FP, PointerType::get(FP->getType(), 0),
-                                 FP->getName() + ".as0", CB);
+    unsigned ProgramAS = A.getDataLayout().getProgramAddressSpace();
----------------
arsenm wrote:

The call has an address space and the underlying function has an address space. You aren't creating a new function so you don't need to query the datalayout

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


More information about the llvm-commits mailing list