264 Commits

Author SHA1 Message Date
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
Evandro Menezes
00c9045712 [SLC] Refactor simplification of pow() (NFC)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338730 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-02 15:43:57 +00:00
Evandro Menezes
1c247de5ee [SLC] Refactor the simplication of pow() (NFC)
Reword comments and minor code reformatting.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338446 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-31 22:11:02 +00:00
Fangrui Song
af7b1832a0 Remove trailing space
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h}

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338293 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-30 19:41:25 +00:00
Evandro Menezes
fb73e7ba91 [SLC] Refactor the simplication of pow() (NFC)
Use more meaningful variable names.  Mostly NFC.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338266 91177308-0d34-0410-b5e6-96231b3b80d8
2018-07-30 16:20:04 +00:00
David Blaikie
8325fb20d4 Move Analysis/Utils/Local.h back to Transforms
Review feedback from r328165. Split out just the one function from the
file that's used by Analysis. (As chandlerc pointed out, the original
change only moved the header and not the implementation anyway - which
was fine for the one function that was used (since it's a
template/inlined in the header) but not in general)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333954 91177308-0d34-0410-b5e6-96231b3b80d8
2018-06-04 21:23:21 +00:00
David Bolvansky
3b8808fda4 [SimplifyLibcalls] [NFC] Cleanup, improvements
Summary:
* Use "find('%')" instead of loop to find '%' char (we already uses find('%') in optimizePrintFString..)
* Convert getParent() chains to getModule()/getFunction()

Reviewers: lebedev.ri, spatel

Reviewed By: spatel

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333668 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-31 16:39:27 +00:00
Sanjay Patel
c5aff60831 [InstCombine] use nsw negation for abs libcalls
Also, produce the canonical IR abs (s<0) to be more efficient. 

This is the libcall equivalent of the clang builtin change from:
rL333038

Pasting from that commit message:
The stdlib functions are defined in section 7.20.6.1 of the C standard with:
"If the result cannot be represented, the behavior is undefined."

That lets us mark the negation with 'nsw' because "sub i32 0, INT_MIN" would
be UB/poison.




git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333042 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-22 23:29:40 +00:00
David Bolvansky
15b63213e0 [InstCombine] Remove calloc transformations
Summary: Previous patch does not care if a value is changed between calloc and strlen. This needs to be removed from InstCombine and maybe moved to DSE later after some rework.

Reviewers: efriedma

Reviewed By: efriedma

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333022 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-22 20:27:36 +00:00
David Bolvansky
851bb222e8 [InstCombine] Calloc-ed strings optimizations
Summary:
Example cases:
strlen(calloc(...)) -> 0

Reviewers: efriedma, bkramer

Reviewed By: bkramer

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332990 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-22 15:41:23 +00:00
David Bolvansky
cb037efeac [SimplifyLibcalls] Replace locked IO with unlocked IO
Summary: If file stream arg is not captured and source is fopen, we could replace IO calls by unlocked IO ("_unlocked" function variants) to gain better speed,

Reviewers: efriedma, RKSimon, spatel, sanjoy, hfinkel, majnemer, lebedev.ri, rja

Reviewed By: rja

Subscribers: rja, srhines, efriedma, lebedev.ri, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332452 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-16 11:39:52 +00:00
David Bolvansky
5905ca8b1e [InstCombine] snprintf optimizations
Reviewers: spatel, efriedma, majnemer, rja, bkramer

Reviewed By: rja, bkramer

Subscribers: mstorsjo, rja, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332110 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-11 17:50:49 +00:00
Martin Storsjo
c86ac9aca9 Revert "[InstCombine] snprintf optimizations"
This reverts commit SVN r331889, which could trigger failed
assertions for cases where the snprintf function is declared
with a vaguely differing signature (e.g. being defined as
static inline), see PR37408.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332043 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-10 21:23:36 +00:00
David Bolvansky
3b0f8c0f12 [InstCombine] snprintf optimizations
Reviewers: spatel, efriedma, majnemer, rja, bkramer

Reviewed By: rja, bkramer

Subscribers: rja, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331889 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-09 16:09:31 +00:00
Benjamin Kramer
be423e4d7b Revert "[InstCombine] snprintf optimizations"
This reverts commit r331849. It miscompiles
snprintf(buf, sizeof(buf), "%s", "any constant string); into
memcpy(buf, "%s", sizeof("any constant string"));

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331866 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-09 11:38:57 +00:00
David Bolvansky
8b5d7e6065 [InstCombine] snprintf optimizations
Reviewers: spatel, efriedma, majnemer, rja

Reviewed By: rja

Subscribers: rja, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331849 91177308-0d34-0410-b5e6-96231b3b80d8
2018-05-09 06:34:20 +00:00
Matt Morehouse
d0cb241845 Revert "[SimplifyLibcalls] Replace locked IO with unlocked IO"
This reverts r331002 due to sanitizer bot breakage.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331011 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-27 01:48:09 +00:00
David Bolvansky
c64f4dbfe3 [SimplifyLibcalls] Replace locked IO with unlocked IO
Summary: If file stream arg is not captured and source is fopen, we could replace IO calls by unlocked IO ("_unlocked" function variants) to gain better speed,

Reviewers: efriedma, RKSimon, spatel, sanjoy, hfinkel, majnemer

Subscribers: lebedev.ri, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331002 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-26 22:31:43 +00:00
David Bolvansky
e1300f7ef8 [SimplifyLibcalls] Atoi, strtol replacements
Reviewers: spatel, lebedev.ri, xbolva00, efriedma

Reviewed By: xbolva00, efriedma

Subscribers: efriedma, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330860 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-25 18:58:53 +00:00
Sanjay Patel
aacb846c03 [SimplifyLibcalls] Realloc(null, N) -> Malloc(N)
Patch by Dávid Bolvanský!

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@330259 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-18 14:21:31 +00:00
David Blaikie
283527b390 Fix a couple of layering violations in Transforms
Remove #include of Transforms/Scalar.h from Transform/Utils to fix layering.

Transforms depends on Transforms/Utils, not the other way around. So
remove the header and the "createStripGCRelocatesPass" function
declaration (& definition) that is unused and motivated this dependency.

Move Transforms/Utils/Local.h into Analysis because it's used by
Analysis/MemoryBuiltins.cpp.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328165 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-21 22:34:23 +00:00
Craig Topper
1169a4ba3e [SimplifyLibCalls] Update an obviously copy and pasted header comment to match this file. NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326475 91177308-0d34-0410-b5e6-96231b3b80d8
2018-03-01 20:05:09 +00:00
Daniel Neilson
0ff4ca1d0c [SimplifyLibCalls] Update from deprecated IRBuilder API for creating memory intrinsics (NFC)
Summary:
This change is part of step five in the series of changes to remove alignment argument from
memcpy/memmove/memset in favour of alignment attributes. In particular, this changes the
SimplifyLibCalls pass to cease using the old IRBuilder createMemCpy/createMemMove
single-alignment APIs in favour of the new API that allows setting source and destination
alignments independently.

Steps:
Step 1) Remove alignment parameter and create alignment parameter attributes for
memcpy/memmove/memset. ( rL322965, rC322964, rL322963 )
Step 2) Expand the IRBuilder API to allow creation of memcpy/memmove with differing
source and dest alignments. ( rL323597 )
Step 3) Update Clang to use the new IRBuilder API. ( rC323617 )
Step 4) Update Polly to use the new IRBuilder API. ( rL323618 )
Step 5) Update LLVM passes that create memcpy/memmove calls to use the new IRBuilder API,
and those that use use MemIntrinsicInst::[get|set]Alignment() to use [get|set]DestAlignment()
and [get|set]SourceAlignment() instead. ( rL323886, rL323891, r3L24148 )
Step 6) Remove the single-alignment IRBuilder API for memcpy/memmove, and the
MemIntrinsicInst::[get|set]Alignment() methods.

Reference
   http://lists.llvm.org/pipermail/llvm-dev/2015-August/089384.html
   http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20151109/312083.html

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324273 91177308-0d34-0410-b5e6-96231b3b80d8
2018-02-05 21:23:22 +00:00
Dmitry Venikov
a4c68ceeeb [InstCombine] Missed optimization in math expression: sin(x) / cos(x) => tan(x)
Summary: This patch enables folding sin(x) / cos(x) -> tan(x), cos(x) / sin(x) -> 1 / tan(x) under -ffast-math flag

Reviewers: hfinkel, spatel

Reviewed By: spatel

Subscribers: andrew.w.kaylor, efriedma, scanon, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322255 91177308-0d34-0410-b5e6-96231b3b80d8
2018-01-11 06:33:00 +00:00
Hal Finkel
1d4f2b0d25 [SimplifyLibCalls] Inline calls to cabs when it's safe to do so
When unsafe algerbra is allowed calls to cabs(r) can be replaced by:

  sqrt(creal(r)*creal(r) + cimag(r)*cimag(r))

Patch by Paul Walker, thanks!

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320901 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-16 01:26:25 +00:00
Sanjay Patel
ac349fb9d8 [SimplifyLibCalls] propagate FMF when folding pow(x, -1.0) call
Follow-up for a bug that's similar to:
https://bugs.llvm.org/show_bug.cgi?id=35601


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320312 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-10 17:25:54 +00:00
Sanjay Patel
80f4596458 [SimplifyLibCalls] propagate FMF when folding pow(x, 2.0) call (PR35601)
This should fix the larger problem with sqrt shown in:
https://bugs.llvm.org/show_bug.cgi?id=35601


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320310 91177308-0d34-0410-b5e6-96231b3b80d8
2017-12-10 16:52:26 +00:00
Sanjay Patel
2dee974397 [LibCallSimplifier] allow splat vectors for pow(x, 0.5) -> sqrt() transforms
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318629 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-19 16:42:27 +00:00
Sanjay Patel
19ab459392 [LibCallSimplifier] partly fix pow(x, 0.5) -> sqrt() transforms
As the first test shows, we could transform an llvm intrinsic which never sets errno 
into a libcall which could set errno (even though it's marked readnone?), so that's 
not ideal.

It's possible that we can also transform a libcall which could set errno to an
intrinsic given the fast-math-flags constraint, but that's deferred to determine
exactly which set of FMF are needed.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318628 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-19 16:13:14 +00:00
Sanjay Patel
00e900afdb [IR] redefine 'UnsafeAlgebra' / 'reassoc' fast-math-flags and add 'trans' fast-math-flag
As discussed on llvm-dev:
http://lists.llvm.org/pipermail/llvm-dev/2016-November/107104.html
and again more recently:
http://lists.llvm.org/pipermail/llvm-dev/2017-October/118118.html

...this is a step in cleaning up our fast-math-flags implementation in IR to better match
the capabilities of both clang's user-visible flags and the backend's flags for SDNode.

As proposed in the above threads, we're replacing the 'UnsafeAlgebra' bit (which had the 
'umbrella' meaning that all flags are set) with a new bit that only applies to algebraic 
reassociation - 'AllowReassoc'.

We're also adding a bit to allow approximations for library functions called 'ApproxFunc' 
(this was initially proposed as 'libm' or similar).

...and we're out of bits. 7 bits ought to be enough for anyone, right? :) FWIW, I did 
look at getting this out of SubclassOptionalData via SubclassData (spacious 16-bits), 
but that's apparently already used for other purposes. Also, I don't think we can just 
add a field to FPMathOperator because Operator is not intended to be instantiated. 
We'll defer movement of FMF to another day.

We keep the 'fast' keyword. I thought about removing that, but seeing IR like this:
%f.fast = fadd reassoc nnan ninf nsz arcp contract afn float %op1, %op2
...made me think we want to keep the shortcut synonym.

Finally, this change is binary incompatible with existing IR as seen in the 
compatibility tests. This statement:
"Newer releases can ignore features from older releases, but they cannot miscompile 
them. For example, if nsw is ever replaced with something else, dropping it would be 
a valid way to upgrade the IR." 
( http://llvm.org/docs/DeveloperPolicy.html#ir-backwards-compatibility )
...provides the flexibility we want to make this change without requiring a new IR 
version. Ie, we're not loosening the FP strictness of existing IR. At worst, we will 
fail to optimize some previously 'fast' code because it's no longer recognized as 
'fast'. This should get fixed as we audit/squash all of the uses of 'isFast()'.

Note: an inter-dependent clang commit to use the new API name should closely follow 
commit.

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317488 91177308-0d34-0410-b5e6-96231b3b80d8
2017-11-06 16:27:15 +00:00
Vivek Pandya
2540c741d5 [NFC] Convert OptimizationRemarkEmitter old emit() calls to new closure
parameterized emit() calls

Summary: This is not functional change to adopt new emit() API added in r313691.

Reviewed By: anemet

Subscribers: llvm-commits

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315476 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-11 17:12:59 +00:00
Adam Nemet
3b8950a6d6 Rename OptimizationDiagnosticInfo.* to OptimizationRemarkEmitter.*
Sync it up with the name of the class actually defined here.  This has been
bothering me for a while...

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315249 91177308-0d34-0410-b5e6-96231b3b80d8
2017-10-09 23:19:02 +00:00
Matthias Braun
77cad59acf TargetLibraryInfo: Stop guessing wchar_t size
Usually the frontend communicates the size of wchar_t via metadata and
we can optimize wcslen (and possibly other calls in the future). In
cases without the wchar_size metadata we would previously try to guess
the correct size based on the target triple; however this is fragile to
keep up to date and may miss users manually changing the size via flags.
Better be safe and stop guessing and optimizing if the frontend didn't
communicate the size.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314185 91177308-0d34-0410-b5e6-96231b3b80d8
2017-09-26 02:36:57 +00:00
Sanjay Patel
5aca549a9a [LibCallSimplifier] try harder to fold memcmp with constant arguments (2nd try)
The 1st try was reverted because it could inf-loop by creating a dead instruction.
Fixed that to not happen and added a test case to verify.

Original commit message:

Try to fold:
memcmp(X, C, ConstantLength) == 0 --> load X == *C

Without this change, we're unnecessarily checking the alignment of the constant data,
so we miss the transform in the first 2 tests in the patch.

I noted this shortcoming of LibCallSimpifier in one of the recent CGP memcmp expansion
patches. This doesn't help the example in:
https://bugs.llvm.org/show_bug.cgi?id=34032#c13
...directly, but it's worth short-circuiting more of these simple cases since we're
already trying to do that.

The benefit of transforming to load+cmp is that existing IR analysis/transforms may
further simplify that code. For example, if the load of the variable is common to
multiple memcmp calls, CSE can remove the duplicate instructions.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311366 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-21 19:13:14 +00:00
Sanjay Patel
544ac6a056 revert r311333: [LibCallSimplifier] try harder to fold memcmp with constant arguments
We're getting lots of compile-timeout bot failures like:
http://lab.llvm.org:8011/builders/clang-native-arm-lnt/builds/7119
http://lab.llvm.org:8011/builders/clang-cmake-x86_64-avx2-linux



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311340 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-21 15:16:25 +00:00
Sanjay Patel
fe0ed9dc7e [LibCallSimplifier] try harder to fold memcmp with constant arguments
Try to fold:
memcmp(X, C, ConstantLength) == 0 --> load X == *C

Without this change, we're unnecessarily checking the alignment of the constant data, 
so we miss the transform in the first 2 tests in the patch.

I noted this shortcoming of LibCallSimpifier in one of the recent CGP memcmp expansion 
patches. This doesn't help the example in:
https://bugs.llvm.org/show_bug.cgi?id=34032#c13
...directly, but it's worth short-circuiting more of these simple cases since we're 
already trying to do that.

The benefit of transforming to load+cmp is that existing IR analysis/transforms may
further simplify that code. For example, if the load of the variable is common to 
multiple memcmp calls, CSE can remove the duplicate instructions.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311333 91177308-0d34-0410-b5e6-96231b3b80d8
2017-08-21 13:55:49 +00:00