This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Avoid pointer element type access for masked atomicrmw intrinsics
ClosedPublic

Authored by nikic on Jan 27 2022, 2:23 AM.

Details

Summary

I'm trying to remove this pointer element type access as part of opaque pointer work, but am having a hard time understanding what the RISCV atomicrmw lowering is doing.

Is it correct to always use an i32 MVT for the masked.atomicrmw.*.i32 intrinsics? From my reading of the code, the expansion will access this size, but I'm not very confident in that reading...

Diff Detail

Event Timeline

nikic created this revision.Jan 27 2022, 2:23 AM
nikic requested review of this revision.Jan 27 2022, 2:23 AM

I believe this is true; the "real" width is dealt with as part of the mask argument to the intrinsic, and as part of the IR expansion the input value for the RMW is shifted to the right position in the aligned i32. Looking at an i16 fetch+add the intrinsic gets an i32*.

asb added a comment.Jan 27 2022, 7:42 AM

I think it's always correct as well. The minimum width for atomic memory operations on RISC-V is 32-bits, but of course to do operations on smaller types you can use lr.w/sc.w and manipulate the loaded value or sometimes use one of the amo* operations with appropriately modified parameters for an equivalent result.

jyknight accepted this revision.Jan 28 2022, 11:32 AM

Looks right to me, too.

This revision is now accepted and ready to land.Jan 28 2022, 11:32 AM
jrtc27 accepted this revision.Jan 28 2022, 11:34 AM

I suppose I should formally accept this

This revision was landed with ongoing or failed builds.Jan 31 2022, 12:30 AM
This revision was automatically updated to reflect the committed changes.