This is an archive of the discontinued LLVM Phabricator instance.

[SROA] Teach SROA to perform no-op pointer conversion.
ClosedPublic

Authored by hliao on Jun 16 2020, 8:54 AM.

Details

Summary
  • When promoting a pointer from memory to register, SROA skips pointers from different address spaces. However, as ptrtoint and inttoptr are defined as no-op casts if that integer type has the same as the pointer value, generate the pair of ptrtoint/inttoptr (no-op cast) sequence to convert pointers from different address spaces if they have the same size.

Diff Detail

Event Timeline

hliao created this revision.Jun 16 2020, 8:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2020, 8:54 AM
arsenm added inline comments.Jun 16 2020, 3:50 PM
llvm/lib/Transforms/Scalar/SROA.cpp
1706–1709

cast<PointerType>->getPointerAddressSpace is redundant. You can drop the pionter in the getter. Also, in this case I would probably prefer dyn_cast and check the pointer since this is immediately after an isPointerTy check

1780

Isn't there a create-noop or create reinterpret cast somewhere?

This also probably needs more comments

hliao updated this revision to Diff 271263.Jun 16 2020, 7:15 PM

remove redundant code.

hliao marked an inline comment as done.Jun 16 2020, 7:16 PM
hliao added inline comments.
llvm/lib/Transforms/Scalar/SROA.cpp
1780

so far, there is no cast creating that pair.

hliao added a comment.Jun 22 2020, 8:41 AM

ping for code review

efriedma added inline comments.Jun 22 2020, 1:58 PM
llvm/lib/Transforms/Scalar/SROA.cpp
1709

Do you need to check isNonIntegralPointerType()?

1782

Probably this comment should be clarified to explain why this isn't an addrspacecast.

hliao updated this revision to Diff 272594.Jun 22 2020, 8:31 PM

Check non-integral pointers.

hliao marked 3 inline comments as done.Jun 22 2020, 8:32 PM
hliao added inline comments.
llvm/lib/Transforms/Scalar/SROA.cpp
1709

good point

hliao updated this revision to Diff 272596.Jun 22 2020, 8:33 PM
hliao marked an inline comment as done.

fix typo!

hliao updated this revision to Diff 272599.Jun 22 2020, 9:19 PM

Add a new test on non-integral pointers.

efriedma accepted this revision.Jun 22 2020, 9:55 PM

LGTM with one minor comment

llvm/lib/Transforms/Scalar/SROA.cpp
1709

I think "different non-integral" is backwards from the code?

This revision is now accepted and ready to land.Jun 22 2020, 9:55 PM
hliao marked an inline comment as done.Jun 22 2020, 10:50 PM
This revision was automatically updated to reflect the committed changes.