[llvm-branch-commits] [llvm] [SelectionDAGBuilder] Use address width when lowering ptrtoaddr (PR #139423)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed May 21 14:10:26 PDT 2025
================
@@ -3878,7 +3878,18 @@ void SelectionDAGBuilder::visitSIToFP(const User &I) {
}
void SelectionDAGBuilder::visitPtrToAddr(const User &I) {
- visitPtrToInt(I);
+ const auto &TLI = DAG.getTargetLoweringInfo();
+ const DataLayout &DL = DAG.getDataLayout();
+ LLVMContext &Ctx = *DAG.getContext();
+ // ptrtoaddr is equivalent to a truncate of ptrtoint to address/index width
+ SDValue N = getValue(I.getOperand(0));
+ Type *PtrTy = I.getOperand(0)->getType();
+ EVT AddrVT = EVT::getIntegerVT(Ctx, DL.getPointerAddressSizeInBits(PtrTy));
+ if (auto *VTy = dyn_cast<VectorType>(PtrTy))
+ AddrVT = EVT::getVectorVT(Ctx, AddrVT, VTy->getElementCount());
+ N = DAG.getPtrExtOrTrunc(N, getCurSDLoc(), AddrVT);
----------------
arsenm wrote:
The LangRef says that it's always zero extend, but DAG.getPtrExtOrTrunc's comment suggests it may decide to be another extension some day?
https://github.com/llvm/llvm-project/pull/139423
More information about the llvm-branch-commits
mailing list