[llvm] [Attributor] Avoid AS-cast for function pointers (PR #65825)
Johannes Doerfert via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 13:28:58 PDT 2024
================
@@ -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();
+ unsigned PtrAS = FP->getType()->getPointerAddressSpace();
+ // TODO: All we really want is a bitcast, see:
+ // https://github.com/llvm/llvm-project/commit/37642714edfc382be90ab8ec091e0261465c1b47#r126273142
+ if (PtrAS != ProgramAS) {
+ if (TTI->isNoopAddrSpaceCast(PtrAS, ProgramAS)) {
+ FP = new AddrSpaceCastInst(FP, PointerType::get(FP->getType(), 0),
+ FP->getName() + ".as0", CB);
+ } else {
+ FP = new IntToPtrInst(
----------------
jdoerfert wrote:
If the AS cast is not a no-op, and this is not legal, we likely want to do nothing. How can I check for non-integral pointers to skip the generation of the if-cascade?
https://github.com/llvm/llvm-project/pull/65825
More information about the llvm-commits
mailing list