15269 Commits

Author SHA1 Message Date
Sanjoy Das
0266d5e92a New pass: guard widening
Summary:
Implement guard widening in LLVM. Description from GuardWidening.cpp:

The semantics of the `@llvm.experimental.guard` intrinsic lets LLVM
transform it so that it fails more often that it did before the
transform.  This optimization is called "widening" and can be used hoist
and common runtime checks in situations like these:

```
%cmp0 = 7 u< Length
call @llvm.experimental.guard(i1 %cmp0) [ "deopt"(...) ]
call @unknown_side_effects()
%cmp1 = 9 u< Length
call @llvm.experimental.guard(i1 %cmp1) [ "deopt"(...) ]
...
```

to

```
%cmp0 = 9 u< Length
call @llvm.experimental.guard(i1 %cmp0) [ "deopt"(...) ]
call @unknown_side_effects()
...
```

If `%cmp0` is false, `@llvm.experimental.guard` will "deoptimize" back
to a generic implementation of the same function, which will have the
correct semantics from that point onward.  It is always _legal_ to
deoptimize (so replacing `%cmp0` with false is "correct"), though it may
not always be profitable to do so.

NB! This pass is a work in progress.  It hasn't been tuned to be
"production ready" yet.  It is known to have quadriatic running time and
will not scale to large numbers of guards

Reviewers: reames, atrick, bogner, apilipenko, nlewycky

Subscribers: mcrosier, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269997 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-18 22:55:34 +00:00
Dehao Chen
8458fdbf49 Follow-up patch of http://reviews.llvm.org/D19948 to handle missing profiles when simplifying CFG.
Summary: Set default branch weight to 1:1 if one of the branch has profile missing when simplifying CFG.

Reviewers: spatel, davidxl

Subscribers: danielcdh, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269995 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-18 22:41:03 +00:00
Michael Zolotukhin
6e6d60d000 [LoopUnrollAnalyzer] Take into account cost of instructions controlling branches, along with their operands.
Previously, we didn't add their and their operands cost, which could've
resulted in unrolling loops for no actual benefit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269985 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-18 21:20:12 +00:00
Dehao Chen
279b28ea43 clang-format SimplifyCFG.cpp.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269974 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-18 19:44:21 +00:00
Davide Italiano
d77d4c07fb [PM] Port per-function SCCP to the new pass manager.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269937 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-18 15:18:25 +00:00
James Molloy
9c1a0c965c [VectorUtils] Fix nasty use-after-free
In truncateToMinimalBitwidths() we were RAUW'ing an instruction then erasing it. However, that intruction could be cached in the map we're iterating over. The first check is "I->use_empty()" which in most cases would return true, as the (deleted) object was RAUW'd first so would have zero use count. However in some cases the object could have been polluted or written over and this wouldn't be the case. Also it makes valgrind, asan and traditionalists who don't like their compiler to crash sad.

No testcase as there are no externally visible symptoms apart from a crash if the stars align.

Fixes PR26509.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269908 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-18 11:57:58 +00:00
Justin Bogner
9c81a3f598 [PM] Port DSE to the new pass manager
Patch by JakeVanAdrighem. Thanks!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269847 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 21:38:13 +00:00
Xinliang David Li
3c661ab452 minor cleanup /NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269839 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 21:06:16 +00:00
Sanjay Patel
e448e72356 [InstCombine] add another test for wrong icmp constant (PR27792)
It doesn't matter if the comparison is unsigned; the inc/dec is always signed.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269831 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 20:20:40 +00:00
Xinliang David Li
5bf7d993fc Simple refactoring /NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269829 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 20:19:03 +00:00
Davide Italiano
809c94de33 [LCSSA] Use llvm::any_of instead of std::size_of.
The API is simpler. Suggested by David Blaikie!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269800 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 19:01:02 +00:00
Sanjay Patel
0353bb1421 [InstCombine] fix constant to be signed for signed comparisons
This bug was introduced in r269728 and is the likely cause of many stage 2 ubsan bot failures.
I'll add a test in a follow-up commit assuming this fixes things properly.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269797 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 18:38:55 +00:00
Sanjoy Das
b4edd72f76 [Guards] Add branch metadata when lowering
Guards are expected to basically never fail.  Reflect this in the branch
probabilities in their lowered form.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269791 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 17:51:19 +00:00
Davide Italiano
9ae1fd1674 [PM/LCSSA] Fix dependency list. Some passes are preserved, not required.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269768 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 14:32:12 +00:00
Davide Italiano
86cadc5625 [LCSSA] Use any_of() to simplify the code. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269767 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 14:24:41 +00:00
Igor Laevsky
af3b6beef3 [RewriteStatepointsForGC] Remove obsolete assertion
This is assertion is no longer necessary since we never record
constants in the live set anyway. (They are never recorded in 
the initial live set, and constant bases are removed near line 2119)

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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269764 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 13:54:10 +00:00
Benjamin Kramer
e5e3c201fd [InstCombine] Don't crash when trying to take an element of a ConstantExpr.
Fixes PR27786.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269757 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 12:08:55 +00:00
Sanjay Patel
7b8e568480 try to avoid unused variable warning in release build; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269729 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 01:12:31 +00:00
Sanjay Patel
91b5ad4eb5 [InstCombine] check vector elements before trying to transform LE/GE vector icmp (PR27756)
Fix a bug introduced with rL269426 :
[InstCombine] canonicalize* LE/GE vector integer comparisons to LT/GT (PR26701, PR26819)

We were assuming that a ConstantDataVector / ConstantVector / ConstantAggregateZero operand of
an ICMP was composed of ConstantInt elements, but it might have ConstantExpr or UndefValue 
elements. Handle those appropriately.

Also, refactor this function to join the scalar and vector paths and eliminate the switches.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269728 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-17 00:57:57 +00:00
Vedant Kumar
ce4aff93aa Revert "Retry^2 "[ProfileData] (llvm) Use Error in InstrProf and Coverage, NFC""
This reverts commit r269694. MSVC says:

error C2086: 'char llvm::ProfErrorInfoBase<enum llvm::instrprof_error>::ID' : redefinition

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269700 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-16 21:03:38 +00:00
Vedant Kumar
515ee3e025 Retry^2 "[ProfileData] (llvm) Use Error in InstrProf and Coverage, NFC"
Transition InstrProf and Coverage over to the stricter Error/Expected
interface.

Changes since the initial commit:
- Address undefined-var-template warning.
- Fix error message printing in llvm-profdata.
- Check errors in loadTestingFormat() + annotateAllFunctions().
- Defer error handling in InstrProfIterator to InstrProfReader.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269694 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-16 20:49:39 +00:00
Xinliang David Li
61ce277483 [PM] Port indirect call promotion pass to new pass manager
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269660 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-16 16:31:07 +00:00
Matthew Simpson
20ebcfc5d1 [LV] Ensure safe VF for loops with interleaved accesses
The selection of the vectorization factor currently doesn't consider
interleaved accesses. The vectorization factor is based on the maximum safe
dependence distance computed by LAA. However, for loops with interleaved
groups, we should instead base the vectorization factor on the maximum safe
dependence distance divided by the maximum interleave factor of all the
interleaved groups. Interleaved accesses not in a group will be scalarized.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269659 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-16 15:08:20 +00:00
Davide Italiano
d125b8b5b6 [PM] RewriterStatepointForGC: add missing dependency.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269624 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-16 02:29:53 +00:00
Benjamin Kramer
95ce0c789b Move helper classes into anonymous namespaces. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269591 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-15 15:18:11 +00:00
Davide Italiano
99d340ac17 [PM/SCCP] Fix pass dependencies.
TargetLibraryInfoWrapperPass is a dependency of
SCCP but it's not listed as such. Chandler pointed
out this is an easy mistake to make which only
surfaces in weird crashes with some flag combinations.
This code will go away anyway at some point in the
future, but as long as it's (still) exercised, try
to make it correct.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269589 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-15 08:04:28 +00:00
Xinliang David Li
17b42bdb89 Rename pass name to prepare to new PM porting /NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269586 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-15 01:04:24 +00:00
Davide Italiano
4f31f3a2fd [SCCP] Use range-based for loops. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269578 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-14 20:59:09 +00:00
Chandler Carruth
2e531af53a Revert "Retry "[ProfileData] (llvm) Use Error in InstrProf and Coverage, NFC""
This reverts commit r269491. It triggers warnings with Clang, breaking
builds for -Werror users including several build bots.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269547 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-14 05:26:26 +00:00
Marcin Koscielnicki
133b6ea685 [MSan] [PowerPC] Implement PowerPC64 vararg helper.
Differential Revision: http://reviews.llvm.org/D20000

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269518 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 23:55:33 +00:00
Davide Italiano
743098991d [PM] Port LowerAtomic to the new pass manager.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269511 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 22:52:35 +00:00
Sanjay Patel
73e8102c16 use 'match' for less indenting; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269494 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 21:51:17 +00:00
Vedant Kumar
db1d476217 Retry "[ProfileData] (llvm) Use Error in InstrProf and Coverage, NFC"
Transition InstrProf and Coverage over to the stricter Error/Expected
interface.

Changes since the initial commit:
- Fix error message printing in llvm-profdata.
- Check errors in loadTestingFormat() + annotateAllFunctions().
- Defer error handling in InstrProfIterator to InstrProfReader.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269491 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 21:50:56 +00:00
Michael Zolotukhin
2463a66c88 Revert "Revert "[Unroll] Implement a conservative and monotonically increasing cost tracking system during the full unroll heuristic analysis that avoids counting any instruction cost until that instruction becomes "live" through a side-effect or use outside the...""
This reverts commit r269395.

Try to reapply with a fix from chapuni.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269486 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 21:23:25 +00:00
Matthew Simpson
d273c95832 Correct spelling in comment (NFC)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269482 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 21:01:07 +00:00
Sanjay Patel
f8ff5802ad use range-loops; NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269471 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 20:24:53 +00:00
Vedant Kumar
8007bdd41f Revert "(HEAD -> master, origin/master, origin/HEAD) [ProfileData] (llvm) Use Error in InstrProf and Coverage, NFC"
This reverts commit r269462. It fails two llvm-profdata tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269466 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 20:09:39 +00:00
Vedant Kumar
5b34ed8191 [ProfileData] (llvm) Use Error in InstrProf and Coverage, NFC
Transition InstrProf and Coverage over to the stricter Error/Expected
interface.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269462 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 20:01:27 +00:00
Jun Bum Lim
1bbd21ba14 Rename getLargestLegalIntTypeSize to getLargestLegalIntTypeSizeInBits(). NFC.
Summary: Rename DataLayout::getLargestLegalIntTypeSize to DataLayout::getLargestLegalIntTypeSizeInBits() to prevent similar mistakes  fixed in r269433.

Reviewers: joker.eph, mcrosier

Subscribers: mcrosier, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269456 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 18:38:35 +00:00
Geoff Berry
5cf889e4f5 [EarlyCSE] Change key type of AvailableCalls to Instruction*. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269445 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 17:54:58 +00:00
Sanjay Patel
4f864166dd [InstCombine] handle zero constant vectors for LE/GE comparisons too
Enhancement to: http://reviews.llvm.org/rL269426
With discussion in: http://reviews.llvm.org/D17859

This should complete the fixes for: PR26701, PR26819:
https://llvm.org/bugs/show_bug.cgi?id=26701
https://llvm.org/bugs/show_bug.cgi?id=26819
 


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269439 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 17:28:12 +00:00
Rong Xu
49af7354c6 [PGO] Add flags to control IRPGO warnings.
Currently there is no reasonable way to control the warnings in the 'use' phase
of the IRPGO pass. This is problematic because the output can be somewhat
spammy. This patch adds some flags which allow us to optionally disable these
warnings. The current upstream behavior will remain the default.

Patch by Jake VanAdrighem (jvanadrighem@gmail.com)

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269437 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 17:26:06 +00:00
Jun Bum Lim
3f9e48ad51 [MemCpyOpt] Use MaxIntSize in byte instead of bit
Summary: This change fix the bug in isProfitableToUseMemset() where MaxIntSize shoule be in byte, not bit.

Reviewers: arsenm, joker.eph, mcrosier

Subscribers: mcrosier, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269433 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 16:52:24 +00:00
Sanjay Patel
81a5b32238 [InstCombine] canonicalize* LE/GE vector integer comparisons to LT/GT (PR26701, PR26819)
*We don't currently handle the  edge case constants (min/max values), so it's not a complete
canonicalization.

To fully solve the motivating bugs, we need to enhance this to recognize a zero vector
too because that's a ConstantAggregateZero which is a ConstantData, not a ConstantVector
or a ConstantDataVector.

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




git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269426 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 15:10:46 +00:00
Michael Zolotukhin
a934d5cb93 Revert "[Unroll] Implement a conservative and monotonically increasing cost tracking system during the full unroll heuristic analysis that avoids counting any instruction cost until that instruction becomes "live" through a side-effect or use outside the..."
This reverts commit r269388.

It caused some bots to fail, I'm reverting it until I investigate the
issue.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269395 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 06:32:25 +00:00
Adam Nemet
3d7e253445 [LoopDist] Only run LAA for loops with the pragma
This should fix some compile-time regressions after r267672.  Thanks to
Chris Matthews for bisecting it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269392 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 04:20:31 +00:00
Michael Zolotukhin
a538be3ab1 [Unroll] Implement a conservative and monotonically increasing cost tracking system during the full unroll heuristic analysis that avoids counting any instruction cost until that instruction becomes "live" through a side-effect or use outside the...
Summary:
...loop after the last iteration.

This is really hard to do correctly. The core problem is that we need to
model liveness through the induction PHIs from iteration to iteration in
order to get the correct results, and we need to correctly de-duplicate
the common subgraphs of instructions feeding some subset of the
induction PHIs. All of this can be driven either from a side effect at
some iteration or from the loop values used after the loop finishes.

This patch implements this by storing the forward-propagating analysis
of each instruction in a cache to recall whether it was free and whether
it has become live and thus counted toward the total unroll cost. Then,
at each sink for a value in the loop, we recursively walk back through
every value that feeds the sink, including looping back through the
iterations as needed, until we have marked the entire input graph as
live. Because we cache this, we never visit instructions more than twice
-- once when we analyze them and put them into the cache, and once when
we count their cost towards the unrolled loop. Also, because the cache
is only two bits and because we are dealing with relatively small
iteration counts, we can store all of this very densely in memory to
avoid this from becoming an excessively slow analysis.

The code here is still pretty gross. I would appreciate suggestions
about better ways to factor or split this up, I've stared too long at
the algorithmic side to really have a good sense of what the design
should probably look at.

Also, it might seem like we should do all of this bottom-up, but I think
that is a red herring. Specifically, the simplification power is *much*
greater working top-down. We can forward propagate very effectively,
even across strange and interesting recurrances around the backedge.
Because we use data to propagate, this doesn't cause a state space
explosion. Doing this level of constant folding, etc, would be very
expensive to do bottom-up because it wouldn't be until the last moment
that you could collapse everything. The current solution is essentially
a top-down simplification with a bottom-up cost accounting which seems
to get the best of both worlds. It makes the simplification incremental
and powerful while leaving everything dead until we *know* it is needed.

Finally, a core property of this approach is its *monotonicity*. At all
times, the current UnrolledCost is a conservatively low estimate. This
ensures that we will never early-exit from the analysis due to exceeding
a threshold when if we had continued, the cost would have gone back
below the threshold. These kinds of bugs can cause incredibly hard to
track down random changes to behavior.

We could use a techinque similar (but much simpler) within the inliner
as well to avoid considering speculated code in the inline cost.

Reviewers: chandlerc

Subscribers: sanjoy, mzolotukhin, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269388 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-13 01:42:39 +00:00
Chandler Carruth
b6b8f76650 [PM] Port of the DepndenceAnalysis to the new PM.
Ported DA to the new PM by splitting the former DependenceAnalysis Pass
into a DependenceInfo result type and DependenceAnalysisWrapperPass type
and adding a new PM-style DependenceAnalysis analysis pass returning the
DependenceInfo.

Patch by Philip Pfaffe, most of the review by Justin.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269370 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-12 22:19:39 +00:00
Simon Pilgrim
85cda82472 Tidied up switch cases. NFCI.
Split FCMP//ICMP/SEL from the basic arithmetic cost functions. They were not sharing any notable code path (just the return) and were repeatedly testing the opcode.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269348 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-12 21:01:20 +00:00
Davide Italiano
d3e47ace50 [PM] Make LowerAtomic a FunctionPass.
Differential Revision: http://reviews.llvm.org/D20025

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269322 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-12 18:49:32 +00:00