[llvm-commits] [PATCH] Instcombine: Don't optimize pow(2.0, x) -> exp2(x) if exp2 is unavailable

Derek Schuff dschuff at google.com
Mon Nov 26 15:25:21 PST 2012


Right, let me give a little bit more background.
I'm building newlib to use as a C library for a platform (Native
Client). In this case the notion of 'the target has exp2' is a little
funny because we are building the target platform. However, just
building the C library with -fno-builtin-foo doesn't quite work
because these functions are also seen again by the optimizer during
LTO (and it appears that clang doesn't support that yet anyway).  I
had in mind to just set exp2 as unavailable for Native Client in TLI
since even though it would be ok to do it for user code, it would
still be a pessimization. Independently of what I want to do for
native client, the patch I sent here seems to fix a legitimate bug
which would trigger on any platform that lacked exp2.
As for testing, adding it to disable-simplify-libcalls.ll isn't quite
sufficient because if you disable all libcall simplification (as that
test does) you get the right result.

So, for this patch I decided to go ahead and add the native client
change as well, because then I can have a test that actually tests
that exp2/exp2f availability is checked. Please take a look.

On Mon, Nov 26, 2012 at 1:02 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Mon, Nov 26, 2012 at 11:17 AM, Derek Schuff <dschuff at google.com> wrote:
>> Hi,
>> Attached is a patch to check that exp2 is available using the usual
>> TLI mechanism before optimizing pow(2.0, x) to exp2(x). This is a
>> problem if compiling a math library that implements exp2(x) as a call
>> to pow(2,x).
>>
>> please review, thanks
>
> Please include a testcase in all patches.  (See
> http://llvm.org/docs/DeveloperPolicy.html .)  Probably the right place
> to put in a test is
> test/Transforms/InstCombine/disable-simplify-libcalls.ll .
>
> The patch is fine, as far as it goes.  There are a bunch of related
> issues here, if you're interested in trying to address them.
>
> -Eli
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Libcalls.diff
Type: application/octet-stream
Size: 2859 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121126/38221e4c/attachment.obj>


More information about the llvm-commits mailing list