This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Prevent argument promotion of types with size greater than 128 bits
ClosedPublic

Authored by saghir on Apr 23 2021, 11:17 AM.

Details

Summary

This patch prevents argument promotion of types having
type size greater than 128 bits.

Fixes Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=49952

Diff Detail

Event Timeline

saghir created this revision.Apr 23 2021, 11:17 AM
saghir requested review of this revision.Apr 23 2021, 11:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 23 2021, 11:17 AM
saghir edited the summary of this revision. (Show Details)Apr 23 2021, 11:19 AM
saghir added reviewers: Restricted Project, nemanjai, stefanp.
saghir updated this revision to Diff 340119.Apr 23 2021, 11:20 AM

Fixed typo in commit message.

amyk added a subscriber: amyk.Apr 26 2021, 6:06 PM
amyk added inline comments.
llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
1232

Would it make sense to add some documentation, and perhaps add why we check up to 128 bits?

This will turn off argument promotion for all types wider than 128 bits. An example of a test case that might suffer from worse codegen:

#include <stdio.h>
typedef int __attribute__((vector_size(64))) v8si;
static void __attribute__((noinline)) printWideVec(v8si *ptr) {
  v8si WideVec = *ptr;
  printf("Vector: { ");
  for (int i = 0; i < 7; i++)
    printf("%d, ", WideVec[i]);
  printf("%d }\n", WideVec[7]);
}

void test(vector signed int a, vector signed int b) {
  v8si WideVec = (v8si) { a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3] };
  printWideVec(&WideVec);
}

Since we can actually check that the type is <N x i1> for N > 128, we should do that and ensure we are only disabling arg promotion on the MMA types.

llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp
1223
// We need to ensure that argument promotion does not
// attempt to promote pointers to MMA types (__vector_pair
// and __vector_quad) since these types explicitly cannot be
// passed as arguments. Both of these types are larger than
// the 128-bit Altivec vectors and have a scalar size of 1 bit.
1229–1240

I don't think we need to check the type size in the data layout for this. The primitive type size should be sufficient. This can be simplified to:

return llvm::none_of(Args, [](Argument *A) {
  auto *EltTy = cast<PointerType>(A->getType())->getElementType();
  if (EltTy->isSized())
    return (EltTy->isIntOrIntVectorTy(1)) &&
           EltTy->getPrimitiveSizeInBits() > 128;
  return false;
});
nemanjai requested changes to this revision.Apr 27 2021, 4:57 AM

Also, this is another one we should merge to 12.0.1 so please open the bug, mark it as a blocker and link it here.

This revision now requires changes to proceed.Apr 27 2021, 4:57 AM
saghir updated this revision to Diff 341369.Apr 28 2021, 6:00 PM

Addressed review comments to check for primitive type size.

saghir edited the summary of this revision. (Show Details)Apr 28 2021, 6:01 PM
nemanjai accepted this revision.Apr 29 2021, 6:40 AM

In the previous revision I suggested the following test case:

#include <stdio.h>
typedef int __attribute__((vector_size(64))) v8si;
static void __attribute__((noinline)) printWideVec(v8si *ptr) {
  v8si WideVec = *ptr;
  printf("Vector: { ");
  for (int i = 0; i < 7; i++)
    printf("%d, ", WideVec[i]);
  printf("%d }\n", WideVec[7]);
}

void test(vector signed int a, vector signed int b) {
  v8si WideVec = (v8si) { a[0], a[1], a[2], a[3], b[0], b[1], b[2], b[3] };
  printWideVec(&WideVec);
}

Can you please add it to this new test case to show that argument promotion is still happening for that case?

This revision is now accepted and ready to land.Apr 29 2021, 6:40 AM
saghir marked 3 inline comments as done.Apr 29 2021, 10:28 AM
saghir updated this revision to Diff 342741.May 4 2021, 7:58 AM

Added another test case

saghir updated this revision to Diff 342787.May 4 2021, 10:06 AM

Rebased before committing

This revision was landed with ongoing or failed builds.May 4 2021, 10:09 AM
This revision was automatically updated to reflect the committed changes.