[PATCH] D101188: [PowerPC] Prevent argument promotion of types with size greater than 128 bits

Nemanja Ivanovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 27 04:56:14 PDT 2021


nemanjai added a comment.

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.



================
Comment at: llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp:1223
 
+bool PPCTTIImpl::areFunctionArgsABICompatible(
+    const Function *Caller, const Function *Callee,
----------------
```
// 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.
```


================
Comment at: llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp:1229-1240
+  const DataLayout &CallerDL = Caller->getParent()->getDataLayout();
+  const DataLayout &CalleeDL = Callee->getParent()->getDataLayout();
+
+  return llvm::none_of(Args, [CallerDL, CalleeDL](Argument *A) {
+    auto *EltTy = cast<PointerType>(A->getType())->getElementType();
+    if (EltTy->isSized()) {
+      unsigned CallerTypeSize = CallerDL.getTypeSizeInBits(EltTy);
----------------
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;
  });
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101188/new/

https://reviews.llvm.org/D101188



More information about the llvm-commits mailing list