299 Commits

Author SHA1 Message Date
Evandro Menezes
c36da86394 [InstCombine] Reorder pow() transformations (NFC)
Move the transformation from `powf(x, itofp(y))` to `powi(x, y)` to the
group of transformations related to the exponent.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365851 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-12 00:33:49 +00:00
David Bolvansky
0f3d79f3e7 [InstCombine] Reorder recently added/improved pow transformations
Changed cases are now faster with exp2.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365758 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-11 10:55:04 +00:00
David Bolvansky
d1678ed7a7 [InstCombine] pow(C,x) -> exp2(log2(C)*x)
Summary:
Transform
pow(C,x) 

To
exp2(log2(C)*x) 

if C > 0, C != inf, C != NaN (and C is not power of 2, since we have some fold for such case already).

log(C) is folded by the compiler and exp2 is much faster to compute than pow.

Reviewers: spatel, efriedma, evandro

Reviewed By: evandro

Subscribers: lebedev.ri, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D64099

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365637 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-10 14:43:27 +00:00
David Bolvansky
469bb59e0b [NFC] Strenghten isInteger condition for rL364940
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364969 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-02 21:16:34 +00:00
David Bolvansky
257696a391 [SimplifyLibCalls] powf(x, sitofp(n)) -> powi(x, n)
Summary:
Partially solves https://bugs.llvm.org/show_bug.cgi?id=42190



Reviewers: spatel, nikic, efriedma

Reviewed By: efriedma

Subscribers: efriedma, nikic, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D63038

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364940 91177308-0d34-0410-b5e6-96231b3b80d8
2019-07-02 15:58:45 +00:00
Sanjay Patel
5a07a49365 [InstCombine] canonicalize fmin/fmax to LLVM intrinsics minnum/maxnum
This transform came up in D62414, but we should deal with it first.
We have LLVM intrinsics that correspond exactly to libm calls (unlike
most libm calls, these libm calls never set errno).
This holds without any fast-math-flags, so we should always canonicalize
to those intrinsics directly for better optimization.
Currently, we convert to fcmp+select only when we have FMF (nnan) because
fcmp+select does not preserve the semantics of the call in the general case.

Differential Revision: https://reviews.llvm.org/D63214

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364714 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-29 14:28:54 +00:00
Erik Pilkington
8964612be0 [SimplifyLibCalls] Fold more fortified functions into non-fortified variants
When the object size argument is -1, no checking can be done, so calling the
_chk variant is unnecessary. We already did this for a bunch of these
functions.

rdar://50797197

Differential revision: https://reviews.llvm.org/D62358

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362272 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-31 22:41:36 +00:00
Erik Pilkington
741ce0d406 NFC: Pull out a function to reduce some duplication
Part of https://reviews.llvm.org/D62358

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362271 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-31 22:41:31 +00:00
Simon Pilgrim
20c6b7a70e Pull out repeated CI->getCalledFunction() calls. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360070 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-06 19:51:54 +00:00
Clement Courbet
137f7dfd51 [SimplifyLibCalls] Simplify bcmp too.
Summary: Fixes PR40699.

Reviewers: gchatelet

Subscribers: hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D61585

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360021 91177308-0d34-0410-b5e6-96231b3b80d8
2019-05-06 09:15:22 +00:00
Evandro Menezes
37c4380fae [SimplifyLibCalls] Clean up code (NFC)
Fix pointer check after dereferencing (PR41665).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359595 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-30 18:35:38 +00:00
Hiroshi Yamauchi
7716d65968 [PGO] Profile guided code size optimization.
Summary:
Enable some of the existing size optimizations for cold code under PGO.

A ~5% code size saving in big internal app under PGO.

The way it gets BFI/PSI is discussed in the RFC thread

http://lists.llvm.org/pipermail/llvm-dev/2019-March/130894.html 

Note it doesn't currently touch loop passes.

Reviewers: davidxl, eraman

Reviewed By: eraman

Subscribers: mgorny, javed.absar, smeenai, mehdi_amini, eraman, zzheng, steven_wu, dexonsmith, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D59514

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358422 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-15 16:49:00 +00:00
Evandro Menezes
d71ea05ab7 [IR] Refactor attribute methods in Function class (NFC)
Rename the functions that query the optimization kind attributes.

Differential revision: https://reviews.llvm.org/D60287

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357731 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-04 22:40:06 +00:00
Alon Zakai
683212b71c [WebAssembly] Add Emscripten OS definition + small_printf
The Emscripten OS provides a definition of __EMSCRIPTEN__, and also that it
supports iprintf optimizations.

Also define small_printf optimizations, which is a printf with float support
but not long double (which in wasm can be useful since long doubles are 128
bit and force linking of float128 emulation code). This part is based on
sunfish's https://reviews.llvm.org/D57620 (which can't land yet since
the WASI integration isn't ready yet).

Differential Revision: https://reviews.llvm.org/D60167

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357552 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-03 01:08:35 +00:00
Fangrui Song
e499a1a918 [SimplifyLibCalls] Simplify optimizePuts
The code might intend to replace puts("") with putchar('\n') even if the
return value is used. It failed because use_empty() was used to guard
the whole block. While returning '\n' (putchar('\n')) is technically
correct (puts is only required to return a nonnegative number on
success), doing this looks weird and there is really little benefit to
optimize puts whose return value is used. So don't do that.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355921 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-12 14:20:22 +00:00
Fangrui Song
65378bcd14 [SimplifyLibCalls] Fix comments about fputs, memchr, and s[n]printf. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355905 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-12 10:31:52 +00:00
Clement Courbet
154171347b [SelectionDAG] Allow the user to specify a memeq function.
Summary:
Right now, when we encounter a string equality check,
e.g. `if (memcmp(a, b, s) == 0)`, we try to expand to a comparison if `s` is a
small compile-time constant, and fall back on calling `memcmp()` else.

This is sub-optimal because memcmp has to compute much more than
equality.

This patch replaces `memcmp(a, b, s) == 0` by `bcmp(a, b, s) == 0` on platforms
that support `bcmp`.

`bcmp` can be made much more efficient than `memcmp` because equality
compare is trivially parallel while lexicographic ordering has a chain
dependency.

Subscribers: fedor.sergeev, jyknight, ckennelly, gchatelet, llvm-commits

Differential Revision: https://reviews.llvm.org/D56593

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355672 91177308-0d34-0410-b5e6-96231b3b80d8
2019-03-08 09:07:45 +00:00
James Y Knight
3bab951f0f [opaque pointer types] Pass value type to GetElementPtr creation.
This cleans up all GetElementPtr creation in LLVM to explicitly pass a
value type rather than deriving it from the pointer's element-type.

Differential Revision: https://reviews.llvm.org/D57173

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352913 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-01 20:44:47 +00:00
James Y Knight
6c00b3f35f [opaque pointer types] Pass value type to LoadInst creation.
This cleans up all LoadInst creation in LLVM to explicitly pass the
value type rather than deriving it from the pointer's element-type.

Differential Revision: https://reviews.llvm.org/D57172

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352911 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-01 20:44:24 +00:00
James Y Knight
6029aa8149 [opaque pointer types] Pass function types to CallInst creation.
This cleans up all CallInst creation in LLVM to explicitly pass a
function type rather than deriving it from the pointer's element-type.

Differential Revision: https://reviews.llvm.org/D57170

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352909 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-01 20:43:25 +00:00
James Y Knight
9ec60d7d8f [opaque pointer types] Add a FunctionCallee wrapper type, and use it.
Recommit r352791 after tweaking DerivedTypes.h slightly, so that gcc
doesn't choke on it, hopefully.

Original Message:
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.

Then:
- update the CallInst/InvokeInst instruction creation functions to
  take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.

One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.

However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)

Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.

Differential Revision: https://reviews.llvm.org/D57315

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352827 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-01 02:28:03 +00:00
James Y Knight
5be828a949 Revert "[opaque pointer types] Add a FunctionCallee wrapper type, and use it."
This reverts commit f47d6b38c7a61d50db4566b02719de05492dcef1 (r352791).

Seems to run into compilation failures with GCC (but not clang, where
I tested it). Reverting while I investigate.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352800 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-31 21:51:58 +00:00
James Y Knight
8e4d96d7af [opaque pointer types] Add a FunctionCallee wrapper type, and use it.
The FunctionCallee type is effectively a {FunctionType*,Value*} pair,
and is a useful convenience to enable code to continue passing the
result of getOrInsertFunction() through to EmitCall, even once pointer
types lose their pointee-type.

Then:
- update the CallInst/InvokeInst instruction creation functions to
  take a Callee,
- modify getOrInsertFunction to return FunctionCallee, and
- update all callers appropriately.

One area of particular note is the change to the sanitizer
code. Previously, they had been casting the result of
`getOrInsertFunction` to a `Function*` via
`checkSanitizerInterfaceFunction`, and storing that. That would report
an error if someone had already inserted a function declaraction with
a mismatching signature.

However, in general, LLVM allows for such mismatches, as
`getOrInsertFunction` will automatically insert a bitcast if
needed. As part of this cleanup, cause the sanitizer code to do the
same. (It will call its functions using the expected signature,
however they may have been declared.)

Finally, in a small number of locations, callers of
`getOrInsertFunction` actually were expecting/requiring that a brand
new function was being created. In such cases, I've switched them to
Function::Create instead.

Differential Revision: https://reviews.llvm.org/D57315

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352791 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-31 20:35:56 +00:00
Chandler Carruth
6b547686c5 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351636 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-19 08:50:56 +00:00
Eli Friedman
8b3efeb103 [SimplifyLibCalls] Fix memchr expansion for constant strings.
The C standard says "The memchr function locates the first
occurrence of c (converted to an unsigned char)[...]".  The expansion
was missing the conversion to unsigned char.

Fixes https://bugs.llvm.org/show_bug.cgi?id=39041 .

Differential Revision: https://reviews.llvm.org/D55947



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350775 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-09 23:39:26 +00:00
Evandro Menezes
71c6b614f3 [NFC][InstCombine] Undo stray change
Undo stray change introduced by r344725.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344814 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-19 20:57:45 +00:00
Mikael Holmen
577c9cec20 Add a emitUnaryFloatFnCall version that fetches the function name from TLI
Summary:
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.

Reviewers: eli.friedman, efriedma

Reviewed By: efriedma

Subscribers: efriedma, bjope, llvm-commits

Differential Revision: https://reviews.llvm.org/D53370

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344725 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-18 06:27:53 +00:00
David Bolvansky
2914ea59ea [InstCombine] Cleanup libfunc attribute inferring
Reviewers: efriedma

Reviewed By: efriedma

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D53338

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344645 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-16 21:18:31 +00:00
David Bolvansky
c323e923ae [InstCombine] Fixed crash with aliased functions
Summary: Fixes PR39177

Reviewers: spatel, jbuening

Reviewed By: jbuening

Subscribers: jbuening, llvm-commits

Differential Revision: https://reviews.llvm.org/D53129

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344454 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-13 15:21:55 +00:00
Amara Emerson
4b25d67d1b [InstCombine] Fix SimplifyLibCalls erasing an instruction while IC still had references to it.
InstCombine keeps a worklist and assumes that optimizations don't
eraseFromParent() the instruction, which SimplifyLibCalls violates. This change
adds a new callback to SimplifyLibCalls to let clients specify their own hander
for erasing actions.

Differential Revision: https://reviews.llvm.org/D52729

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@344251 91177308-0d34-0410-b5e6-96231b3b80d8
2018-10-11 14:51:11 +00:00
Matt Morehouse
be08b55fc5 [InstCombine] Disable strcmp->memcmp transform for MSan.
Summary:
The strcmp->memcmp transform can make the resulting memcmp read
uninitialized data, which MSan doesn't like.

Resolves https://github.com/google/sanitizers/issues/993.

Reviewers: eugenis, xbolva00

Reviewed By: eugenis

Subscribers: hiraditya, llvm-commits

Differential Revision: https://reviews.llvm.org/D52272

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@342582 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-19 19:37:24 +00:00
Florian Hahn
5ca8be39d2 [SLC] Support expanding pow(x, n+0.5) to x * x * ... * sqrt(x)
Reviewers: evandro, efriedma, spatel

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D51435


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341330 91177308-0d34-0410-b5e6-96231b3b80d8
2018-09-03 17:37:39 +00:00
Evandro Menezes
8969d63f17 [InstCombine] Expand the simplification of pow() into exp2()
Generalize the simplification of `pow(2.0, y)` to `pow(2.0 ** n, y)` for all
scalar and vector types.

This improvement helps some benchmarks in SPEC CPU2000 and CPU2006, such as
252.eon, 447.dealII, 453.povray.  Otherwise, no significant regressions on
x86-64 or A64.

Differential revision: https://reviews.llvm.org/D49273

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@341095 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-30 19:04:51 +00:00
Reid Kleckner
ff8943d248 Revert r340947 "[InstCombine] Expand the simplification of pow() into exp2()"
It broke the clang-cl self-host.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340991 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-29 22:58:33 +00:00
Evandro Menezes
19ea694df6 [InstCombine] Expand the simplification of pow() with nested exp{,2}()
Expand the simplification of `pow(exp{,2}(x), y)` to all FP types.

This improvement helps some benchmarks in SPEC CPU2000 and CPU2006, such as
252.eon, 447.dealII, 453.povray.  Otherwise, no significant regressions on
x86-64 or A64.

Differential revision: https://reviews.llvm.org/D51195

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340948 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-29 17:59:48 +00:00
Evandro Menezes
02b82d7fb8 [InstCombine] Expand the simplification of pow() into exp2()
Generalize the simplification of `pow(2.0, y)` to `pow(2.0 ** n, y)` for all
scalar and vector types.

This improvement helps some benchmarks in SPEC CPU2000 and CPU2006, such as
252.eon, 447.dealII, 453.povray.  Otherwise, no significant regressions on
x86-64 or A64.

Differential revision: https://reviews.llvm.org/D49273

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340947 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-29 17:59:34 +00:00
Evandro Menezes
f494ccf3dd [PATCH] [InstCombine] Fix issue in the simplification of pow() with nested exp{,2}()
Fix the issue of duplicating the call to `exp{,2}()` when it's nested in
`pow()`, as exposed by rL340462.

Differential revision: https://reviews.llvm.org/D51194

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340784 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-27 22:11:15 +00:00
Evandro Menezes
2898554fda [NFC] Refactor simplification of pow()
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340476 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-22 23:18:02 +00:00
Evandro Menezes
f896970b07 [InstCombine] Refactor the simplification of pow() (NFC)
Refactor all cases dealing with `exp{,2,10}()` into one function in
preparation for D49273.  Otherwise, NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340061 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-17 17:59:53 +00:00
Sanjay Patel
3964940ceb [InstCombine] add reflection fold for tan(-x)
This is a follow-up suggested with rL339604.
For tan(), we don't have a corresponding LLVM 
intrinsic -- unlike sin/cos -- so this is the 
only way/place that we can do this fold currently.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339958 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-16 22:46:20 +00:00
Evandro Menezes
935c1e9f5a [InstCombine] Expand the simplification of pow(x, 0.5) to sqrt(x)
Expand the number of cases when `pow(x, 0.5)` is simplified into `sqrt(x)`
by considering the math semantics with more granularity.

Differential revision: https://reviews.llvm.org/D50036

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339887 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-16 15:58:08 +00:00
Sanjay Patel
9ee8a957cc [SimplifyLibCalls] don't drop fast-math-flags on trig reflection folds (retry r339608)
Even though this code is below a function called optimizeFloatingPointLibCall(),
we apparently can't guarantee that we're dealing with FPMathOperators, so bail
out immediately if that's not true.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339618 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-13 21:49:19 +00:00
Sanjay Patel
6a6b35cd86 revert r339608 - [SimplifyLibCalls] don't drop fast-math-flags on trig reflection folds
Can't set the builder flags without knowing this is an FPMathOperator. I'll add a test
for that and try again.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339609 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-13 20:20:38 +00:00
Sanjay Patel
6c5927533a [SimplifyLibCalls] don't drop fast-math-flags on trig reflection folds
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339608 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-13 20:14:27 +00:00
Sanjay Patel
8b80050699 [SimplifyLibCalls] add reflection fold for -sin(-x) (PR38458)
This is a very partial fix for the reported problem. I suspect
we do not get this fold in most motivating cases because most of
the time, the libcall would have been replaced by an intrinsic,
and that optimization is handled elsewhere...but maybe it should
be handled here?


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339604 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-13 19:24:41 +00:00
Sanjay Patel
3a74b4221a [SimplifyLibCalls] reduce code for optimizeCos; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339588 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-13 17:40:49 +00:00
Evandro Menezes
13b933258d [SLC] Expand simplification of pow() for vector types
Also consider vector constants when simplifying `pow()`.

Differential revision: https://reviews.llvm.org/D50035

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339578 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-13 16:12:37 +00:00
David Bolvansky
af0751b6c0 [InstCombine] Transform str(n)cmp to memcmp
Summary:
Motivation examples:
int strcmp_memcmp() {
    char buf[12];
    return strcmp(buf, "key") == 0;
}

int strcmp_memcmp2() {
    char buf[12];
    return strcmp(buf, "key") != 0;
}

int strncmp_memcmp() {
    char buf[12];
    return strncmp(buf, "key", 3) == 0;
}

can be turned to memcmp.

See test file for more cases.

Reviewers: efriedma

Reviewed By: efriedma

Subscribers: spatel, llvm-commits

Differential Revision: https://reviews.llvm.org/D50233

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339410 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-10 04:32:54 +00:00
Evandro Menezes
f064d04716 [SLC] Fix shrinking of pow()
Properly shrink `pow()` to `powf()` as a binary function and, when no other
simplification applies, do not discard it.

Differential revision: https://reviews.llvm.org/D50113

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@339046 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-06 19:40:17 +00:00
Evandro Menezes
8ef7ef81f7 [SLC] Refactor shrinking of functions (NFC)
Merge the helper functions for shrinking unary and binary functions into a
single one, while keeping all their functionality.  Otherwise, NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338905 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-03 17:50:16 +00:00