[PATCH] D53927: [AArch64] Enable libm vectorized functions via SLEEF

Stefan Teleman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 6 09:22:29 PST 2019


steleman updated this revision to Diff 185576.
steleman added a comment.
Herald added a project: LLVM.

This is a significant update to the original version of the SLEEF
changeset.

While testing LLVM+SLEEF on AArch64, I discovered that, for programs
such as the following simple test case:

  #include <stdio.h>
  #include <stdlib.h>
  #include <math.h>
  #include <time.h>
  
  int main()
  {
    double D;
    double R;
  
    srand48(time(0));
  
    D = drand48();
    R = tgamma(D);
    (void) fprintf(stderr, "tgamma: D=%lf R=%lf\n", D, R);
  
    D = drand48();
    R = acos(D);
    (void) fprintf(stderr, "acos: D=%lf R=%lf\n", D, R);
  
    D = drand48();
    R = acosh(D);
    (void) fprintf(stderr, "acosh: D=%lf R=%lf\n", D, R);
  
    D = drand48();
    R = asin(D);
    (void) fprintf(stderr, "asin: D=%lf R=%lf\n", D, R);
  
    return 0;
  }

Compile with:

  ./clang -O3 -mcpu=thunderx2t99 -fvectorize -fveclib=SLEEF -ffast-math -ffp-contract=fast -c t.c -o t.o

compilation will fail in LLVM:

  fatal error: error in backend: Cannot select: intrinsic %llvm.asin
  clang-8: error: clang frontend command failed with exit code 70 (use -v to see invocation)
  [ ... etc etc ... ]

This failure is triggered by -ffast-math -ffp-contract=fast. Without
these flags, the fatal error does not occur.

This only happens when the newly-enabled intrinsics (tgamma, acos,
acosh, asin, etc) are called on a scalar -- as in the test program above.

When called on a vector, with or without -ffast-math -ffp-contract=fast,
these new intrinsics always succeed.

This updated version of the patch addresses this problem.

I have also added a second test case for SLEEF AArch64 which tests for

  %call = call fast float @acosf(float %conv)

I realize that this patch has grown in size significantly, and that
it may be a candidate for splitting it into smaller parts.

The problem is, I do not quite see how it can be split into several
smaller parts, simply because without this entire patch, the new
intrinsics will cause a fatal error in the LLVM backend, as shown above.

The patch is based on LLVM ToT from 02/06/2019.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D53927

Files:
  include/llvm/Analysis/TargetLibraryInfo.def
  include/llvm/Analysis/TargetLibraryInfo.h
  include/llvm/CodeGen/ISDOpcodes.h
  include/llvm/IR/Intrinsics.td
  include/llvm/IR/RuntimeLibcalls.def
  lib/Analysis/TargetLibraryInfo.cpp
  lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
  lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
  lib/CodeGen/SelectionDAG/LegalizeTypes.h
  lib/CodeGen/SelectionDAG/LegalizeVectorOps.cpp
  lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
  lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
  test/Transforms/LoopVectorize/AArch64/sleef-calls-aarch64-fast.ll
  test/Transforms/LoopVectorize/AArch64/sleef-calls-aarch64.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53927.185576.patch
Type: text/x-patch
Size: 140194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190206/02a15f10/attachment-0001.bin>


More information about the llvm-commits mailing list