[PATCH] D53370: Add a emitUnaryFloatFnCall version that fetches the function name from TLI

Mikael Holmén via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 17 06:08:07 PDT 2018


uabelho created this revision.
uabelho added a reviewer: eli.friedman.

In several places in the code we use the following pattern:

  if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
    [...]
    Value *Res = emitUnaryFloatFnCall(X, TLI.getName(LibFunc_tan), B, Attrs);
    [...]
  }

In short, we check if there is a lib-function for a certain type, and then
we _always_ fetch the name of the "double" version of the lib function and
construct a call to the appropriate function, that we just checked exists,
using that "double" name as a basis.

This is of course a problem in cases where the target doesn't support the
"double" version, but e.g. only the "float" version.

In that case TLI.getName(LibFunc_tan) returns "", and
emitUnaryFloatFnCall happily appends an "f" to "", and we erroneously end
up with a call to a function called "f".

To solve this, the above pattern is changed to

  if (hasUnaryFloatFn(&TLI, Ty, LibFunc_tan, LibFunc_tanf, LibFunc_tanl)) {
    [...]
    Value *Res = emitUnaryFloatFnCall(X, &TLI, LibFunc_tan, LibFunc_tanf,
                                      LibFunc_tanl, B, Attrs);
    [...]
  }

I.e instead of first fetching the name of the "double" version and then
letting emitUnaryFloatFnCall() add the final "f" or "l", we let
emitUnaryFloatFnCall() fetch the right name from TLI.


Repository:
  rL LLVM

https://reviews.llvm.org/D53370

Files:
  include/llvm/Transforms/Utils/BuildLibCalls.h
  lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
  lib/Transforms/Utils/BuildLibCalls.cpp
  lib/Transforms/Utils/SimplifyLibCalls.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53370.169996.patch
Type: text/x-patch
Size: 8233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181017/a50f7b4a/attachment.bin>


More information about the llvm-commits mailing list