This is an archive of the discontinued LLVM Phabricator instance.

[SystemZ] Make 128 bit integers be aligned to 8 bytes.
ClosedPublic

Authored by jonpa on Aug 1 2022, 7:01 AM.

Details

Summary

The SystemZ ABI says that 128 bit integers should be aligned to only 8 bytes.

Diff Detail

Event Timeline

jonpa created this revision.Aug 1 2022, 7:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 7:01 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
jonpa requested review of this revision.Aug 1 2022, 7:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2022, 7:01 AM
nikic added a subscriber: nikic.Aug 1 2022, 7:07 AM
nikic added inline comments.
clang/lib/Basic/Targets/SystemZ.h
60

Isn't this the default? We should be using the alignment of the largest specified integer type, which is 64.

jonpa updated this revision to Diff 449301.Aug 2 2022, 9:11 AM
jonpa marked an inline comment as done.

Change to DataLayout string removed.

Test added to check that the middle end (and hopefully then the backend as well) will produce the right alignments when unspecified in the IR input.

@uweigand I also added tests for the alignment of a vector depending on the presence of the vector facility. I am not sure if I have run into something weird here, but I left the test and output this way for now so you can see what I mean: If I use -mattr=-vector the alignment becomes 16 for the vector, but not if this is specified in the function attributes only (see @f2).

jonpa added inline comments.Aug 2 2022, 9:12 AM
clang/lib/Basic/Targets/SystemZ.h
60

You are right - removed.

@uweigand I also added tests for the alignment of a vector depending on the presence of the vector facility. I am not sure if I have run into something weird here, but I left the test and output this way for now so you can see what I mean: If I use -mattr=-vector the alignment becomes 16 for the vector, but not if this is specified in the function attributes only (see @f2).

Yes, this is because of the way computeDataLayout in SystemZTargetMachine.cpp currently gives different resuts based on the presence of the vector feature - but this routine is only used once per compilation unit, not once per function. This is actually a long-standing problem, the data layout really ought to depend only on the triple, but right now it doesn't. (If you recall, that's also why we wanted to emit a warning if files with different vector feature setting are linked together ...)

However, given what we just found about i128 (that it had always been set to 64-bit alignment in the data layout - it was just the front end that aligned to 128-bit anyway!), maybe the proper fix to the vector ABI issue would be to also set vector alignment to 64 bits in the data layout / the back end unconditionally, and only make the 128-bit / 64-bit distinction in the clang front-end! But that is a certainly a separate discussion.

Given this, maybe it's best to remove the vector type from this patch after all, and work on that separately.

jonpa updated this revision to Diff 449644.Aug 3 2022, 5:54 AM

Patch (test) updated by removing the vector alignment part.

uweigand accepted this revision.Aug 3 2022, 6:02 AM

LGTM, thanks!

This revision is now accepted and ready to land.Aug 3 2022, 6:02 AM
This revision was landed with ongoing or failed builds.Aug 3 2022, 6:41 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 3 2022, 6:41 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript