This is an archive of the discontinued LLVM Phabricator instance.

[NVPTX] allow address space inference for volatile loads/stores.
ClosedPublic

Authored by tra on Oct 17 2017, 5:25 PM.

Details

Summary

If particular target supports volatile memory access operations, we can
avoid casting to generic AS. Currently it's only enabled in NVPTX for
loads and stores that access global & shared AS.

This improves performance in situations when we need to exchange data via shared memory
and need to preserve memory access order using 'volatile'.

Diff Detail

Repository
rL LLVM

Event Timeline

tra created this revision.Oct 17 2017, 5:25 PM
jlebar added a subscriber: arsenm.Oct 17 2017, 10:18 PM
jlebar added inline comments.
llvm/include/llvm/Analysis/TargetTransformInfo.h
493 ↗(On Diff #119407)

s/particular/the particular/ or perhaps better /the given/

495 ↗(On Diff #119407)

I'm not sure this second sentence helps much -- it feels sort of apropos of nothing to me here.

Maybe we should say something to cover the fact that if this returns false, the instruction may still have a volatile variant -- we might simply not have implemented this TTI function for that target. :)

llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp
712 ↗(On Diff #119407)

Suggest adding a comment, since this is tricky. Maybe "If the memory instruction is volatile, return true only if the target allows the memory instruction to be volatile in the new address space."

llvm/test/CodeGen/NVPTX/ld-st-addrrspace.py
59 ↗(On Diff #119407)

I'm not sure it's clearer, but ftr we could get rid of the three maps by doing

for (llvm_type, ptx_type), (llvm_addrspace, ptx_addrspace), volatile in product(
  [("i8", "u8"), ...], [(0, ""), (1, ".global"), ...], [True, False]):

At least I'd recommend getting rid of get_as_id, since it's inconsistent with how we do the other two maps.

73 ↗(On Diff #119407)

Maybe this would be blearer if we moved it above the params dict?

Also, spaces after the commas. :) There *are* pyformatters out there, e.g. https://github.com/myint/pyformat (first hit when randomly searching), which looks like it's actually just a wrapper around https://pypi.python.org/pypi/autopep8.

76 ↗(On Diff #119407)

This test_params vs. params difference looks left over from the previous python script. Here it seems unnecessary?

tra updated this revision to Diff 119945.Oct 23 2017, 3:17 PM
tra marked 2 inline comments as done.

Addressed Justin's comments.

Added addrspacecast to generic AS in the tests to make sure InferAddressSpace does its job.

tra marked 2 inline comments as done.Oct 23 2017, 3:21 PM
tra added inline comments.
llvm/include/llvm/Analysis/TargetTransformInfo.h
495 ↗(On Diff #119407)

Rephrased. PTAL.

llvm/test/CodeGen/NVPTX/ld-st-addrrspace.py
59 ↗(On Diff #119407)

Fixed as_id.
Folding three maps into a single statement is a bit too much python-fu, IMO.

jlebar accepted this revision.Oct 23 2017, 5:18 PM
jlebar added inline comments.
llvm/include/llvm/Analysis/TargetTransformInfo.h
493 ↗(On Diff #119945)

a volatile variant

This revision is now accepted and ready to land.Oct 23 2017, 5:18 PM
tra updated this revision to Diff 119982.Oct 23 2017, 6:08 PM

Grammar fix.

tra marked an inline comment as done.Oct 23 2017, 6:08 PM
This revision was automatically updated to reflect the committed changes.