This is an archive of the discontinued LLVM Phabricator instance.

Handle part-word LL/SC in atomic expansion pass
ClosedPublic

Authored by kparzysz on Apr 1 2020, 6:15 AM.

Details

Summary

Extend the current LL/SC structure to include part-word extracts and inserts.

Extend PartwordMaskValues struct to provide insert and extract operations that also work (as no-ops) for full-word operations. This allows using a single expansion routine to generate code for both full- and part-word atomic operations.

Diff Detail

Unit TestsFailed

Event Timeline

kparzysz created this revision.Apr 1 2020, 6:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2020, 6:15 AM
Herald added subscribers: jfb, hiraditya. · View Herald Transcript
jyknight added a comment.EditedApr 13 2020, 10:46 AM

My first reaction is to be a bit reticent to extend the IR-level LL/SC expansion code, because generally speaking LL/SC expansion in IR is not sound (per previous discussions over the years). However, I do recall during those discussions, it was also mentioned that the concerns don't apply to Hexagon http://lists.llvm.org/pipermail/llvm-dev/2018-June/124069.html -- that the activity of other simultaneously running threads cannot cause the spurious loss of a reservation. Perhaps that's the case now because there aren't any Hexagon chips that support multiple cores with separate caches.

So, this seems okay in concept, even though I do think it would be preferable if everyone followed the model of doing the expansion late in MI, rather than IR.

llvm/lib/CodeGen/AtomicExpandPass.cpp
1349–1351

What's all this complication about?

I find it hard to imagine putting this kind of simplification code inline here is the best way to go about this.

bcain added a subscriber: bcain.Apr 13 2020, 11:11 AM
kparzysz marked an inline comment as done.Apr 13 2020, 12:04 PM
kparzysz added inline comments.
llvm/lib/CodeGen/AtomicExpandPass.cpp
1349–1351

This complication is about having one or two of the tests pass with minimal changes. It checks all statements, and I'd have to annotate it with the extra PHIs (with single operand, or with multiple identical incoming values). I thought I'd be objectionable, so I added this cleanup code.

If the test alteration is ok, I can remove this.

kparzysz updated this revision to Diff 257129.Apr 13 2020, 3:33 PM

Removed the phi optimization, updated tests to reflect the leftover phis.

Probably in the long term Hexagon should also switch to MI... But since it's done here at the moment, let's just keep it here for now.

bcain added a comment.Apr 15 2020, 8:16 AM

Removed the phi optimization, updated tests to reflect the leftover phis.

LGTM, what do you think @jyknight ?

Functionality seems fine, just some style nits.

Also: please clang-format your patch (e.g. using git-clang-format).

llvm/lib/CodeGen/AtomicExpandPass.cpp
653

These two functions appear to be only used in expandAtomicCmpXchg, maybe better to just make them lambdas in it or static helper functions right above it.

807

I'm not fond of the style where constructing an object is used primarily to side-effect one of its arguments. It seems clearer, generally, to use a separate function-call with a meaningful name, rather than an object constructor. (That is: the way the code was before, with a createMaskInstrs function seems better).

If I apply this patch I am still able to encounter this unreachable during a build. I can share repro details.

llvm/lib/CodeGen/AtomicExpandPass.cpp
572

Is this guard related to the patch? Seems like it should also be changed, right?

bcain added a comment.Apr 25 2020, 6:32 PM

If I apply this patch I am still able to encounter this unreachable during a build. I can share repro details.

Here's a test case that triggers here:

%struct.a = type { i8 }
define void @b()  {
        %d = alloca %struct.a%c = getelementptr %struct.a, %struct.a* %d, i32 0, i32 0   atomicrmw add i8* %c, i8 2 monotonic
ret void
}
kparzysz updated this revision to Diff 260392.Apr 27 2020, 11:40 AM

The main changes are:

  • Changed the PartwordMaskValue member functions to static non-members.
  • Added LL/SC expansion of partword RMW.

Applied clang-format.

bcain added a comment.Apr 27 2020, 2:52 PM

The main changes are:

  • Changed the PartwordMaskValue member functions to static non-members.
  • Added LL/SC expansion of partword RMW.

Applied clang-format.

LGTM thanks

jyknight accepted this revision.Apr 27 2020, 5:55 PM
This revision is now accepted and ready to land.Apr 27 2020, 5:55 PM
This revision was automatically updated to reflect the committed changes.