This is an archive of the discontinued LLVM Phabricator instance.

Force GHashCell to be 8-byte-aligned.
ClosedPublic

Authored by efriedma on Apr 15 2022, 1:09 PM.

Details

Summary

Otherwise, with recent versions of libstdc++, clang can't tell that the atomic operations are properly aligned, and generates calls to libatomic.

Fixes https://github.com/llvm/llvm-project/issues/54790 , at least for that specific case.

Diff Detail

Event Timeline

efriedma created this revision.Apr 15 2022, 1:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2022, 1:09 PM
Herald added a subscriber: StephenFan. · View Herald Transcript
efriedma requested review of this revision.Apr 15 2022, 1:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 15 2022, 1:09 PM
jyknight accepted this revision.Apr 15 2022, 1:22 PM

Sidenote: Oh, yikes! I didn't even notice before that this code is doing reinterpret_cast from a GHashCell* to a std::atomic<GHashCell>*. That's...kinda not great...

This revision is now accepted and ready to land.Apr 15 2022, 1:22 PM
MaskRay accepted this revision.Apr 15 2022, 1:32 PM

Seems worth mentioning auto *cellPtr = reinterpret_cast<std::atomic<GHashCell> *>(&table[idx]);

I know nearly nothing about COFF debugging. I assume there is better way avoiding the reinterpret_cast but this patch as-is is safe for 14.x backport.

rnk accepted this revision.Apr 15 2022, 2:21 PM

lgtm

Sidenote: Oh, yikes! I didn't even notice before that this code is doing reinterpret_cast from a GHashCell* to a std::atomic<GHashCell>*. That's...kinda not great...

Yeah, I think I was excited with the performance results, and shipped some prototype code. The idea is that we only need to do atomic operations during hash table insertion. Afterwards, the table is used as readonly data. I wouldn't be surprised if there are issues lurking here for ISAs with weak memory models.

This revision was automatically updated to reflect the committed changes.