175 Commits

Author SHA1 Message Date
Sjoerd Meijer
69d2b17af4 Addressing post-commit comments for not rewriting fputs:
moved the optimise for size check inside function optimizeFPuts.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274758 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-07 14:31:19 +00:00
Sjoerd Meijer
5ab922ce5c Code size optimisation: don't rewrite fputs to fwrite when optimising for size
because fwrite requires more arguments and thus extra MOVs are required.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274753 91177308-0d34-0410-b5e6-96231b3b80d8
2016-07-07 13:56:23 +00:00
Joerg Sonnenberger
ee2078606f Optimize a printf with a double procent to putchar.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268922 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-09 14:36:16 +00:00
Ahmed Bougacha
8a8efec992 [TLI] Unify LibFunc signature checking. NFCI.
I tried to be as close as possible to the strongest check that
existed before; cleaning these up properly is left for future work.

Differential Revision: http://reviews.llvm.org/D19469

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267758 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-27 19:04:35 +00:00
David Majnemer
de19e3a88c Revert "[SimplifyLibCalls] sprintf doesn't copy null bytes"
The destination buffer that sprintf uses is restrict qualified, we do
not need to worry about derived pointers referenced via format
specifiers.

This reverts commit r267580.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267605 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-26 21:04:47 +00:00
David Majnemer
783db05d7b [SimplifyLibCalls] sprintf doesn't copy null bytes
sprintf doesn't read or copy the terminating null byte from it's string
operands.  sprintf will append it's own after processing all of the
format specifiers.

This fixes PR27526.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267580 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-26 18:16:49 +00:00
Mehdi Amini
f6071e14c5 [NFC] Header cleanup
Removed some unused headers, replaced some headers with forward class declarations.

Found using simple scripts like this one:
clear && ack --cpp -l '#include "llvm/ADT/IndexedMap.h"' | xargs grep -L 'IndexedMap[<]' | xargs grep -n --color=auto 'IndexedMap'

Patch by Eugene Kosov <claprix@yandex.ru>

Differential Revision: http://reviews.llvm.org/D19219

From: Mehdi Amini <mehdi.amini@apple.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266595 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-18 09:17:29 +00:00
David L Kreitzer
3592381ea1 Simplify strlen to a subtraction for certain cases.
Patch by Li Huang (li1.huang@intel.com)

Differential Revision: http://reviews.llvm.org/D18230


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266200 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-13 14:31:06 +00:00
Davide Italiano
4e5a97a04b [SimplifyLibCalls] Garbage collect dead code.
We already skip optimizations if the return value
of printf() is used, so CI->use_empty() is always
true.

Differential Revision:  http://reviews.llvm.org/D18656


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265253 91177308-0d34-0410-b5e6-96231b3b80d8
2016-04-03 01:46:52 +00:00
Davide Italiano
adf9f00eed [SimplifyLibCalls] Transform printf("%s", "a") -> putchar('a').
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264588 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-28 15:54:01 +00:00
David Majnemer
649040b838 [SimplifyLibCalls] Only consider sinpi/cospi functions within the same function
The sinpi/cospi can be replaced with sincospi to remove unnecessary
computations.  However, we need to make sure that the calls are within
the same function!

This fixes PR26993.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263875 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-19 04:53:02 +00:00
Sanjay Patel
569647fbec [LibCallSimplifier] fold memset(malloc(x), 0, x) --> calloc(1, x)
This is a step towards solving PR25892:
https://llvm.org/bugs/show_bug.cgi?id=25892

It won't handle the reported case. As noted by the 'TODO' comments in the patch, 
we need to relax the hasOneUse() constraint and also match patterns that include
memset_chk() and the llvm.memset() intrinsic in addition to memset().

Differential Revision: http://reviews.llvm.org/D16337



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258816 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-26 16:17:24 +00:00
Sanjay Patel
b3bc79d555 move function definitions so we don't need separate declarations ; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258455 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-21 23:38:43 +00:00
Sanjay Patel
fbc73a666e [LibCallSimplifier] refactor FP function signature checks ; NFCI
Use the helper function added in r258428.

The check should really be hoisted to the caller of all of these
optimize* functions, but that's another step.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258446 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-21 22:58:01 +00:00
Sanjay Patel
93b477f563 avoid variable shadowing; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258445 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-21 22:41:16 +00:00
Sanjay Patel
d288063a88 remove unnecessary variable; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258444 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-21 22:31:18 +00:00
Sanjay Patel
faf8f30ad7 [LibCallSimplifier] don't get fooled by a fake fmin()
This is similar to the bug/fix:
https://llvm.org/bugs/show_bug.cgi?id=26211
http://reviews.llvm.org/rL258325

The fmin() test case reveals another bug caused by sloppy
code duplication. It will crash without this patch because
fp128 is a valid floating-point type, but we would think
that we had matched a function that used doubles.

The new helper function can be used to replace similar
checks that are used in several other places in this file.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258428 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-21 20:19:54 +00:00
Sanjay Patel
d0d71cf4bb make helper functions static; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258416 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-21 18:01:57 +00:00
Sanjay Patel
e52954eb4a [LibCallSimplifier] don't get fooled by a fake sqrt()
The test case will crash without this patch because the subsequent call to
hasUnsafeAlgebra() assumes that the call instruction is an FPMathOperator
(ie, returns an FP type).

This part of the function signature check was omitted for the sqrt() case, 
but seems to be in place for all other transforms.

Before:
http://reviews.llvm.org/rL257400
...we would have needlessly continued execution in optimizeSqrt(), but the
bug was harmless because we'd eventually fail some other check and return
without damage.

This should fix:
https://llvm.org/bugs/show_bug.cgi?id=26211

Differential Revision: http://reviews.llvm.org/D16198



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258325 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-20 17:41:14 +00:00
Sanjay Patel
130d7af1cf function names start with a lowercase letter; NFC
Note: There are no uses of these functions outside of
SimplifyLibCalls, so they could be static functions in
that file.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258172 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-19 19:46:10 +00:00
Sanjay Patel
507edcba42 [LibCallSimplifier] use instruction-level fast-math-flags to shrink calls
This is a continuation of adding FMF to call instructions:
http://reviews.llvm.org/rL255555



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258158 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-19 18:38:52 +00:00
Sanjay Patel
a9c8e55a04 [LibCallSimplifier] use instruction-level fast-math-flags to transform pow(x, [small integer]) calls
This is a continuation of adding FMF to call instructions:
http://reviews.llvm.org/rL255555

As with D15937, the intent of the patch is to preserve the current behavior of the transform
except that we use the pow call's 'fast' attribute as a trigger rather than a function-level
attribute.

The TODO comment notes a potential follow-on patch that would propagate FMF to the new
instructions.

Differential Revision: http://reviews.llvm.org/D16122



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@258153 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-19 18:15:12 +00:00
Sanjay Patel
44d6fd556f [LibCallSimplifier] use instruction-level fast-math-flags to transform pow(x, 0.5) calls
Also, propagate the FMF to the newly created sqrt() call.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257503 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-12 19:06:35 +00:00
Sanjay Patel
bd8623ae5c function names start with a lower case letter ; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257496 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-12 18:03:37 +00:00
Sanjay Patel
75660cfed9 [LibCallSimplifier] use instruction-level fast-math-flags to transform pow(exp(x)) calls
See also:
http://reviews.llvm.org/rL255555
http://reviews.llvm.org/rL256871
http://reviews.llvm.org/rL256964
http://reviews.llvm.org/rL257400
http://reviews.llvm.org/rL257404
http://reviews.llvm.org/rL257414



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257491 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-12 17:30:37 +00:00
Sanjay Patel
f8f4df59dc [LibCallSimplifier] use instruction-level fast-math-flags to transform log calls
Also, add tests to verify that we're checking 'fast' on both calls of each transform pair,
tighten the CHECK lines, and give the tests more meaningful names.

This is a continuation of:
http://reviews.llvm.org/rL255555
http://reviews.llvm.org/rL256871
http://reviews.llvm.org/rL256964
http://reviews.llvm.org/rL257400
http://reviews.llvm.org/rL257404



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257414 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-11 23:31:48 +00:00
Sanjay Patel
be014a6bcf [LibCallSimplifier] don't allow sqrt transform unless all ops are unsafe
Fix the FIXME added with:
http://reviews.llvm.org/rL257400



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257404 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-11 22:50:36 +00:00
Sanjay Patel
33ad607b8e more space; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257401 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-11 22:35:39 +00:00
Sanjay Patel
2234dddb07 [LibCallSimplifier] use instruction-level fast-math-flags to transform sqrt calls
This is a continuation of adding FMF to call instructions:
http://reviews.llvm.org/rL255555

The intent of the patch is to preserve the current behavior of the transform except
that we use the sqrt instruction's 'fast' attribute as a trigger rather than the
function-level attribute.

But this raises a bug noted by the new FIXME comment.

In order to do this transform:
sqrt((x * x) * y) ---> fabs(x) * sqrt(y)

...we need all of the sqrt, the first fmul, and the second fmul to be 'fast'. 
If any of those ops is strict, we should bail out.

Differential Revision: http://reviews.llvm.org/D15937



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257400 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-11 22:34:19 +00:00
Sanjay Patel
e7a3d30d80 [LibCallSimplifier] less indenting; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256973 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-06 20:52:21 +00:00
Sanjay Patel
78a42b0707 [LibCallSimplifier] use instruction-level fast-math-flags for tan/atan transform
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256964 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-06 19:23:35 +00:00
David Majnemer
4cb9f9dcb1 [SimplifyLibCalls] Teach SimplifyLibCalls about operand bundles
If we replace one call-site with another, be sure to move over any
operand bundles that lingered on the old call-site.

This fixes PR26036.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256912 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-06 05:01:34 +00:00
Sanjay Patel
9fcc06d338 A (B + C) = A B + A C ; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256884 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-06 00:32:15 +00:00
Sanjay Patel
d79ef021fe [LibCallSimplfier] use instruction-level fast-math-flags for fmin/fmax transforms
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256871 91177308-0d34-0410-b5e6-96231b3b80d8
2016-01-05 20:46:19 +00:00
Sanjay Patel
e193ff319c [LibCallSimplifier] propagate FMF when shrinking binary calls
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256682 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-31 23:40:59 +00:00
Sanjay Patel
2e3f468f86 [LibCallSimplifier] propagate FMF when shrinking unary calls
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256679 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-31 21:52:31 +00:00
Sanjay Patel
6622d8b812 Variable names start with an upper case letter; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256676 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-31 16:16:58 +00:00
Sanjay Patel
ad8bf7ce34 fix formatting; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256675 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-31 16:10:49 +00:00
Sanjay Patel
59dc7be11d getParent() ^ 3 == getModule() ; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255511 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-14 17:24:23 +00:00
Weiming Zhao
cc87069c31 [SimplifyLibCalls] Optimization for pow(x, n) where n is some constant
Summary:
    In order to avoid calling pow function we generate repeated fmul when n is a
    positive or negative whole number.
    
    For each exponent we pre-compute Addition Chains in order to minimize the no.
    of fmuls.
    Refer: http://wwwhomes.uni-bielefeld.de/achim/addition_chain.html
    
    We pre-compute addition chains for exponents upto 32 (which results in a max of
    7 fmuls).

    For eg:
    4 = 2+2
    5 = 2+3
    6 = 3+3 and so on
    
    Hence,
    pow(x, 4.0) ==> y = fmul x, x
                    x = fmul y, y
                    ret x

    For negative exponents, we simply compute the reciprocal of the final result.
    
    Note: This transformation is only enabled under fast-math.
    
    Patch by Mandeep Singh Grang <mgrang@codeaurora.org>

Reviewers: weimingz, majnemer, escha, davide, scanon, joerg

Subscribers: probinson, escha, llvm-commits

Differential Revision: http://reviews.llvm.org/D13994

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254776 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-04 22:00:47 +00:00
Davide Italiano
24c91af18b [SimplifyLibCalls] Transform log(exp2(y)) to y*log(2) under fast-math.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254317 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-30 19:36:35 +00:00
Davide Italiano
401b67d4eb [SimplifyLibCalls] Don't crash if the function doesn't have a name.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254265 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-29 21:58:56 +00:00
Davide Italiano
276f2af536 [SimplifyLibCalls] Cross out implemented transformations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254264 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-29 21:00:43 +00:00
Davide Italiano
0f019d6283 [SimplifyLibCalls] Tranform log(pow(x, y)) -> y*log(x).
This one is enabled only under -ffast-math. There are cases where the
difference between the value computed and the correct value is huge
even for ffast-math, e.g. as Steven pointed out:

x = -1, y = -4
log(pow(-1), 4) = 0
4*log(-1) = NaN

I checked what GCC does and apparently they do the same optimization
(which result in the dramatic difference). Future work might try to
make this (slightly) less worse.

Differential Revision:	http://reviews.llvm.org/D14400


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254263 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-29 20:58:04 +00:00
Davide Italiano
46cdbe2048 [SimplifyLibCalls] Use any_of(). Suggested by David Blaikie!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254239 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-28 22:27:48 +00:00
Benjamin Kramer
d3af7cc9d9 [SimplifyLibCalls] Fix inverted condition that lead to an uninitialized memory read below.
Found by msan!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254238 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-28 21:43:12 +00:00
Davide Italiano
2748acd415 [SimplifyLibCalls] Use range-based loop. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254193 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-27 08:05:40 +00:00
Benjamin Kramer
7c7d1ee4c2 [SimplifyLibCalls] Don't depend on a called function having a name, it might be an indirect call.
Fixes the crasher in PR25651 and related crashers using the same pattern.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254145 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-26 09:51:17 +00:00
Weiming Zhao
a8a4b7cd81 [Utils] Put includes in correct order. NFC.
Summary:
    Followed the guidelines in:
    http://llvm.org/docs/CodingStandards.html#include-style
    
    However, I noticed that uppercase named headers come before lowercase ones
    throughout the codebase. So kept them as is.
    
    Patch by Mandeep Singh Grang <mgrang@codeaurora.org>

Reviewers: majnemer, davide, jmolloy, atrick

Subscribers: sanjoy

Differential Revision: http://reviews.llvm.org/D14939

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254005 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-24 18:57:06 +00:00
Weiming Zhao
0bf5b5cfb8 [SimplifyLibCalls] Removed some TODOs which are already implemented. NFC.
Summary:
D14302 implements tan(atan(x)) -> x
D14045 implements pow(exp(x), y) -> exp(x*y)

Patch by Mandeep Singh Grang <mgrang@codeaurora.org>

Reviewers: majnemer, davide

Differential Revision: http://reviews.llvm.org/D14882

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@253768 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-21 06:10:20 +00:00