[PATCH] D99438: [SimplifyLibCalls] Take size of int into consideration when emitting ldexp/ldexpf

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 26 13:08:57 PDT 2021


bjope created this revision.
Herald added a subscriber: hiraditya.
bjope requested review of this revision.
Herald added a project: LLVM.

When rewriting

  powf(2.0, itofp(x)) -> ldexpf(1.0, x)
  exp2(sitofp(x)) -> ldexp(1.0, sext(x))
  exp2(uitofp(x)) -> ldexp(1.0, zext(x))

the wrong type was used for the second argument in the ldexp/ldexpf
libc call, for target architectures with 16 bit "int" type.
The transform incorrectly used a bitcasted function pointer with
a 32-bit argument when emitting the ldexp/ldexpf call for such
targets.

The fault is solved by using the correct function prototype
in the call, by asking TargetLibraryInfo about the size of "int".
TargetLibraryInfo by default derives the size of the int type by
assuming that it is 16 bits for 16-bit architectures, and
32 bits otherwise. If this isn't true for a target it should be
possible to override that default in the TargetLibraryInfo
initializer.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99438

Files:
  llvm/include/llvm/Analysis/TargetLibraryInfo.h
  llvm/lib/Analysis/TargetLibraryInfo.cpp
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/exp2-1.ll
  llvm/test/Transforms/InstCombine/pow_fp_int.ll
  llvm/test/Transforms/InstCombine/simplify-libcalls.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99438.333614.patch
Type: text/x-patch
Size: 21837 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210326/a68254e2/attachment.bin>


More information about the llvm-commits mailing list