This is an archive of the discontinued LLVM Phabricator instance.

[SystemZ] Improve handling of vector alignments
ClosedPublic

Authored by jonpa on Aug 4 2022, 5:11 AM.

Details

Summary

With these first experiments, I see:

  • Clang seems to now emit a padding in the case of no-vx, like
%struct.S = type { i32, [12 x i8], <4 x i32> }

instead of

%struct.S = type { i32, <4 x i32> }

This should be equivalent, in the final output, I would hope, although I have not looked into that handling in detail.

  • As seen in function-attributes-01.ll, if the IR has no alignment specified, it is 8-byte aligned now even with -vector.
  • vec-abi-align.ll needed updating to include the padding in the struct - as now expected from clang - to work...

It seems that SPEC builds identically both for z15 and zEC12, which is promising. I however don't quite know if this is actually correct or not: what if some optimizer want to build a vector and adds the wrong alignment in the no-vx case? Is the alignment as specified by the front end and found in the I/R enough to make this work in all cases? I am a little worried that some optimizer might look up that alignment value in DataLayout and use that instead...

Diff Detail

Event Timeline

jonpa created this revision.Aug 4 2022, 5:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2022, 5:11 AM
jonpa requested review of this revision.Aug 4 2022, 5:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2022, 5:11 AM

It seems that SPEC builds identically both for z15 and zEC12, which is promising.

This is already good news. However, I believe SPEC doesn't really use any attribute((vector_size)) so that might not tell us much. Can you do the same exercise with e.g. the llvm-test-suite? That does at least have a few instances of those types. It might also be good to run the ABI compat test suite (out of the GCC test suite).

I however don't quite know if this is actually correct or not: what if some optimizer want to build a vector and adds the wrong alignment in the no-vx case? Is the alignment as specified by the front end and found in the I/R enough to make this work in all cases? I am a little worried that some optimizer might look up that alignment value in DataLayout and use that instead...

I mean, the front-end *should* create IR that makes the alignment requirement clear (via align attributes, and explicit padding within structs), and the optimizers need to respect that anyway.

llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp
44–45

We should remove the CPU and FS arguments here, to make it obvious that the data layout should depend *only* on the Triple.

llvm/test/CodeGen/SystemZ/vec-abi-align.ll
45

This test case now isn't quite testing any more what it was initially supposed to test :-)

Maybe to fully test the new behavior, we should test all four combinations of S_novx vs. S_vx and -vector vs. +vector? I.e. have both CHECK-VECTOR and CHECK-NOVECTOR lines in both fun1 and fun2.

jonpa updated this revision to Diff 450537.Aug 6 2022, 8:21 AM
jonpa marked 2 inline comments as done.

Patch updated.

This is already good news. However, I believe SPEC doesn't really use any attribute((vector_size)) so that might not tell us much. Can you do the same exercise with e.g. the llvm-test-suite? That does at least have a few instances of those types. It might also be good to run the ABI compat test suite (out of the GCC test suite).

I am quite sure that the llvm test-suite should pass with this patch (I rebuilt all files containing the attribute((vector_size)) and found no diff. For some reason I first got into trouble by merely adding -save-temps: undefined references at the link stage).

I tried running the GCC test suite as well, but sofar I have not been able to run it properly, I think (gcc failed the api check against itself).

uweigand accepted this revision.Sep 8 2022, 7:46 AM

LGTM, thanks!

This revision is now accepted and ready to land.Sep 8 2022, 7:46 AM
This revision was landed with ongoing or failed builds.Sep 8 2022, 8:34 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 8 2022, 8:34 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript