Skip to content

[SelectionDAGBuilder] Use address width when lowering ptrtoaddr #139423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: users/arichardson/spr/main.selectiondagbuilder-use-address-width-when-lowering-ptrtoaddr
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3980,8 +3980,16 @@ void SelectionDAGBuilder::visitSIToFP(const User &I) {
}

void SelectionDAGBuilder::visitPtrToAddr(const User &I) {
// FIXME: this is not correct for pointers with addr width != pointer width
visitPtrToInt(I);
const auto &TLI = DAG.getTargetLoweringInfo();
const DataLayout &DL = DAG.getDataLayout();
// ptrtoaddr is equivalent to a truncate of ptrtoint to address/index width
auto Op0 = I.getOperand(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto Op0 = I.getOperand(0);
const Value *Op0 = I.getOperand(0);

No auto

SDValue N = getValue(Op0);
// By definition the type of the ptrtoaddr must be equal to the address type.
assert(I.getType() == DL.getAddressType(Op0->getType()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to assert things enforced by the verifier

EVT AddrVT = TLI.getValueType(DL, I.getType());
N = DAG.getNode(ISD::TRUNCATE, getCurSDLoc(), AddrVT, N);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are the same type, why do you need the truncate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While most targets will have them be the same, the Op0 type can be wider. This is the case e.g. for the AMD GPU buffer pointers.

setValue(&I, N);
}

void SelectionDAGBuilder::visitPtrToInt(const User &I) {
Expand Down
Loading