Skip to content

Correctly reverse translate GEP coming from G_PTR_ADD#166

Open
AlexVlx wants to merge 1 commit into
amd-stagingfrom
alexv/fix_pfn_handling
Open

Correctly reverse translate GEP coming from G_PTR_ADD#166
AlexVlx wants to merge 1 commit into
amd-stagingfrom
alexv/fix_pfn_handling

Conversation

@AlexVlx

@AlexVlx AlexVlx commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

When using the BE, ConstantExpr GEPs can get flattened into a G_PTR_ADD, which then gets lowered into an OpPtrAccessChain. When we reverse translate, we have access to the full type, which might not be flat / for which the flat index as computed for a G_PTR_ADD might be incorrect. This patch recomputes the index vector based on type and offset for such cases.

@AlexVlx AlexVlx changed the title Correctly reverse translate GEP coming from G_PTR_ADD Correctly reverse translate GEP coming from G_PTR_ADD Apr 23, 2026
@z1-cciauto

Copy link
Copy Markdown
Contributor

@MrSidims MrSidims left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not exactly following the problem - a test should help.

Source of my non-understanding comes from the fact, that now days clang more often generates ptradd-like GEP (with a byte base). And so far I've seen no issues with translation of such GEPs. And my expectation is that the result of the codegen by the backend should look exactly the same as flattening done by clang. If it's not the case it means either of 2 things: a. corner case which I should learn about (and a test should help with that :) ) or b. bug in the backend.

@maarquitos14

Copy link
Copy Markdown
Contributor

+1 to @MrSidims's comment. A test/example would help me understand the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants