[PATCH] D47553: Add TargetLowering::shouldExpandAtomicToLibCall and query it from AtomicExpandPass

Alex Bradbury via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 31 08:25:49 PDT 2018


asb added a comment.

In https://reviews.llvm.org/D47553#1117753, @efriedma wrote:

> On other architectures which have 32-bit atomics, but not 8 and 16-bit atomics, it's generally possible to lower smaller operations using a 32-bit cmpxchg loop.  Does that not work on RISCV for some reason?


We can absolutely lower to ll+sc, which is what the 8 and 16-bit libatomic implementations do for rv32ia. My thought was simply:

1. Simply generating the libcall is easy and correct. This gives a stepping stone allowing the straight-forward implementation of initial support than can then be improved by lowering in-line instruction sequences
2. If we are happy that the 8 and 16bit __atomic_* libcalls are lock-free, it is safe to choose between inline instruction sequences and libcalls freely. In that case, a hook such as this would allow you to call the atomic when optimising for code size.

I could understand an argument that use-case 1) isn't compelling enough to add this new hook, and determining whether use-case 2) makes sense is dependent on the conclusion of the GCC bug 86005 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86005> discussion. Thanks @jyknight for sharing your thoughts in that GCC thread - much appreciated.


https://reviews.llvm.org/D47553





More information about the llvm-commits mailing list