This is an archive of the discontinued LLVM Phabricator instance.

[AMDGPU] Add IPO pass to infer pointer argument address spaces.
Needs RevisionPublic

Authored by rampitec on Jul 14 2022, 3:46 PM.

Details

Summary

The pass currently relyes on the regular InferAddressSpaces to run
after it to actually rewrite instructions. In the future it shall
be possible to add such rewriting into this pass itself as well
as to change function signatures.

The pass itself is not AMDGPU specific, but it needs to run after
the InferAddressSpaces so that pointers are promoted in the callees
and then it needs yet another run of the InferAddressSpaces after.
Hence the pass placement in the backend, otherwise other targets
would need to run extra InferAddressSpaces instance. When/if
InferAddressSpaces is not needed after argument coercion it can be
placed into a regular opt pipeline.

Diff Detail

Event Timeline

rampitec created this revision.Jul 14 2022, 3:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2022, 3:46 PM
rampitec requested review of this revision.Jul 14 2022, 3:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2022, 3:46 PM
Herald added a subscriber: wdng. · View Herald Transcript

@jdoerfert was telling me someone is already working on this

llvm/lib/Transforms/IPO/InferArgumentAddressSpaces.cpp
140

It would be better to replace the actual argument list with the new type too, and update all the users

rampitec added inline comments.Jul 14 2022, 4:23 PM
llvm/lib/Transforms/IPO/InferArgumentAddressSpaces.cpp
140

This would be a lot of code, at least copy most of the stuff from InferAddressSpaces itself, cloning function, updating calls, updating SCC...

Is it worth it? I.e. what do your think it would make better?

In any way, if needed it is better to go in a separate change.

rampitec added inline comments.Jul 14 2022, 11:40 PM
llvm/lib/Transforms/IPO/InferArgumentAddressSpaces.cpp
140

Actually I see how it can be beneficial by avoiding an actual cast of a pointer before the call and inside the function, and also giving a freedom to move this pass in the pipeline untieing it from the InferAddressSpaces.

Though I would really like to separate such changes simply because actual signature changing is massive by itself. I think it will need a big portion of the InferAddressSpaces to be extracted into a separate utility, the stuff which actually rewrite instructions.

We have https://reviews.llvm.org/D120586 in the pipeline which I was hoping would solve this properly. I think I dropped the ball reviewing that one. WDYT?

We have https://reviews.llvm.org/D120586 in the pipeline which I was hoping would solve this properly. I think I dropped the ball reviewing that one. WDYT?

The plan with that one I recall was to have the Attributor handle the inter-procedural aspect of address space propagation and let the existing patch handle the propagation to all the instructions in the function. I never got around to updating it as I've been a little busy with other stuff. Anyone is free to commandeer it if they want to. Otherwise I may be able to revisit it in awhile.

rampitec updated this revision to Diff 449373.Aug 2 2022, 12:08 PM
rampitec retitled this revision from [AMDGPU] Add IPO pass to infer pointer argument address spaces. WIP. to [AMDGPU] Add IPO pass to infer pointer argument address spaces..
rampitec edited the summary of this revision. (Show Details)

The pass is functional and test is updated.

I am not sure about D120586 timeline and capabilities, but since this was practically done I have finished the patch to a working state.

I am not sure about D120586 timeline and capabilities, but since this was practically done I have finished the patch to a working state.

Like I said, the plan for that one was to just use the Attributor's getAssumedUnderlyingObjects to interproceduraly identify pointers with a common address space. We would then let the existing pass handle intraprocedural propagation. I'm not sure if that's an explicit replacement for the functionality proposed here. I think @jdoerfert wants to have address space deduction available inside the Attributor regardless, so we'll probably get that working eventually anyway. I don't have a definite timeline on this, but I could try to implement it sooner if this is important.

arsenm requested changes to this revision.Nov 16 2022, 4:40 PM

This comes up often enough that I'd like to see it pushed to a useful place

llvm/lib/Transforms/IPO/InferArgumentAddressSpaces.cpp
72

This is going to end up repeating all of InferAddressSpacesImpl::collectFlatAddressExpressions

This revision now requires changes to proceed.Nov 16 2022, 4:40 PM