Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SystemZ] Test improvements for atomic load/store instructions (NFC). #75630

Merged
merged 3 commits into from
Dec 21, 2023

Conversation

JonPsson1
Copy link
Contributor

Make sure to test atomic load and store instructions with and w/out natural alignment.

@uweigand
Copy link
Member

The IR specs say: "align must be explicitly specified on atomic loads, and the load has undefined behavior if the alignment is not set to a value which is at least the size in bytes of the pointee" -- given that, does it really make sense to add test cases that are undefined IR according to the spec?

@JonPsson1
Copy link
Contributor Author

Ahh.. maybe not. Maybe then AtomicExpand should not even emit libcalls, but rather assert and abort?

It seems that AtomicExpand decides to handle the unaligned cases with libcall:

// Determine if a particular atomic operation has a supported size,
// and is of appropriate alignment, to be passed through for target
// lowering. (Versus turning into a __atomic libcall)
template <typename Inst>
static bool atomicSizeSupported(const TargetLowering *TLI, Inst *I) {
  unsigned Size = getAtomicOpSize(I);
  Align Alignment = I->getAlign();
  return Alignment >= Size &&
         Size <= TLI->getMaxAtomicSizeInBitsSupported() / 8;
}

SelectionDAGBuilder however rejects this:

void SelectionDAGBuilder::visitAtomicLoad(const LoadInst &I) {
  SDLoc dl = getCurSDLoc();
  AtomicOrdering Order = I.getOrdering();
...
  if (!TLI.supportsUnalignedAtomics() &&
      I.getAlign().value() < MemVT.getSizeInBits() / 8)
    report_fatal_error("Cannot generate unaligned atomic load");
...

So with the notion of supporting unaligned atomics, it's a little unclear to me as indeed the spec says " the load has undefined behavior if the alignment is not set to a value which is at least the size in bytes of the pointee."

If there is library support for the unaligned cases, I guess the libcalls should be allowed. If not, the libcalls should not get emitted by AtomicExpand.

@JonPsson1
Copy link
Contributor Author

Per our discussion, I reverted the previous test changes for <=64 bits, but updated the 128-bit tests as they actually should have been changed with c568927, since the default alignment for _Atomic long double is now 16 bytes, right?

@jyknight
Copy link
Member

If there is library support for the unaligned cases, I guess the libcalls should be allowed. If not, the libcalls should not get emitted by AtomicExpand.

Yes; the non-size-specialized __atomic_* libcalls work on any alignment. AtomicExpandPass's behavior here is correctly/intentionally handling that condition. The IR spec wording should be updated to relax the constraint.

@JonPsson1
Copy link
Contributor Author

If there is library support for the unaligned cases, I guess the libcalls should be allowed. If not, the libcalls should not get emitted by AtomicExpand.

Yes; the non-size-specialized __atomic_* libcalls work on any alignment. AtomicExpandPass's behavior here is correctly/intentionally handling that condition. The IR spec wording should be updated to relax the constraint.

I made a suggestion here for the spec: #75871

@uweigand
Copy link
Member

Let's wait until we have agreement whether or not misaligned atomic load/store is supposed to be supported at the IR level. If yes, we should test the relevant cases for us: which would mean both 8-byte and 16-byte aligned 128-bit accesses.

Also, the related test case improvement from #75879 should be pulled in here: missing checks for serialization, test all 128-bit operations on both z10 and z13.

@JonPsson1
Copy link
Contributor Author

Now that the spec was updated (#75871), I have updated the tests here again per previous discussion.

Copy link
Member

@uweigand uweigand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@JonPsson1 JonPsson1 merged commit 74a09bd into llvm:main Dec 21, 2023
4 checks passed
@JonPsson1 JonPsson1 deleted the AtomicTestsNFC branch March 26, 2024 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants