Commit Graph

52 Commits

Author SHA1 Message Date
Daniel Berlin
a0431ff170 NewGVN: Fix PR 31682, an overactive assert.
Part of the assert has been left active for further debugging.
The other part has been turned into a stat for tracking for the
moment.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292583 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-20 06:38:41 +00:00
Davide Italiano
d20f95e583 [NewGVN] We don't use postdom info anymore. Update.
Differential Revision:  https://reviews.llvm.org/D28842

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292421 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-18 18:42:28 +00:00
Daniel Berlin
c110f9b676 NewGVN: Change a bunch of densemap find_or_creates to lookups, since they should not be creating new entries
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292059 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-15 09:18:41 +00:00
Davide Italiano
6fc369afea [NewGVN] Fix a warning from GCC.
Patch by Gonsolo.
Differential Revision:  https://reviews.llvm.org/D28731

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292031 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-14 20:44:08 +00:00
Davide Italiano
ef1d09ade3 [NewGVN] clang-format this file after recent changes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292026 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-14 20:15:04 +00:00
Davide Italiano
a8cc948667 [NewGVN] Try to be consistent wit the style used in this file. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292025 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-14 20:13:18 +00:00
Daniel Berlin
23bf3fe69d NewGVN: Kill unneeded DFSDomMap, cleanup a few comments.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291981 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-14 00:24:23 +00:00
Daniel Berlin
e782760da1 NewGVN: Move leaders around properly to ensure we have a canonical dominating leader. Fixes PR 31613.
Summary:
This is a testcase where phi node cycling happens, and because we do
not order the leaders by domination or anything similar, the leader
keeps changing.

Using std::set for the members is too expensive, and we actually don't
need them sorted all the time, only at leader changes.

We could keep both a set and a vector, and keep them mostly sorted and
resort as necessary, or use a set and a fibheap, but all of this seems
premature.

After running some statistics, we are able to avoid the vast majority
of sorting by keeping a "next leader" field.  Most congruence classes only have
leader changes once or twice during GVN.

Reviewers: davide

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291968 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-13 22:40:01 +00:00
Davide Italiano
c082fcc6ff [NewGVN] Fixup store count for the initial congruency class.
It was always zero. When we move a store from `initial` to its
own congruency class, we end up with a negative store count, which
is obviously wrong.
Also, while here, change StoreCount to be signed so that the assertions
actually fire.

Ack'ed by Daniel Berlin.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291725 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 23:41:24 +00:00
Davide Italiano
c38c1351bc Revert "[NewGVN] Strengthen a couple of assertions."
It's breaking some bots. Will investigate and recommit.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291712 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 22:00:29 +00:00
Davide Italiano
4214b4143a [NewGVN] Parenthesise assertion condition (-Wparenthesis).
Format an assertion message while I'm here.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291710 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 21:58:42 +00:00
Davide Italiano
459fcccb97 [NewGVN] Strengthen a couple of assertions.
StoreCount >= 0 on `unsigned` is always true, otherwise.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291709 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 21:49:00 +00:00
Daniel Berlin
42f1f6e771 NewGVN: Fix PR31594, by tracking the store count of congruence
classes, and updating checking to allow for equivalence through
reachability.

(Sadly, the checking here is not perfect, and can't be made perfect,
so we'll have to disable it after we are satisfied with correctness.
Right now it is just "very unlikely" to happen.)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291698 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 20:22:36 +00:00
Daniel Berlin
06963901ef NewGVN: Refactor performCongruenceFinding and split out congruence class moving
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291697 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-11 20:22:05 +00:00
Daniel Berlin
b393b33bb9 NewGVN: Fix PR 31573, a failure to verify memory congruency due to
not excluding ourselves when checking if any equivalent stores
exist.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291421 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-09 05:34:29 +00:00
Daniel Berlin
66e9c6aac6 NewGVN: Change a std::vector to SmallVector and cleanup naming.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291420 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-09 05:34:19 +00:00
Daniel Berlin
a783424031 NewGVN: Make sure we properly lookup operand leaders while creating
congruence classes for stores, and then keep them up to date.  Add
testcases.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291351 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-07 16:55:14 +00:00
Daniel Berlin
aded1359b6 NewGVN: Reformat and fix a few newlines
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291334 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-07 03:23:47 +00:00
Davide Italiano
d43425f87b [NewGVN] Prefer auto over explicit type. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291328 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-07 02:05:50 +00:00
Daniel Berlin
45b7d44c62 NewGVN: Fix PR 31501.
Summary: LLVM's non-standard notion of phi nodes means we can't both try to substitute for undef in phi nodes *and* use phi nodes as leaders all the time. This changes NewGVN to use the same semantics as SimplifyPHINode to decide which phi nodes are equivalent.

Reviewers: davide

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291308 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-07 00:01:42 +00:00
Daniel Berlin
76894fb000 NewGVN: Track the maximum number of iterations GVN takes on any function, so we can pinpoint performance issues.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291002 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-04 21:01:02 +00:00
Daniel Berlin
34eb5e17b1 NewGVN: Clean up after removing possibility of null expressions.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290828 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-02 19:49:17 +00:00
Davide Italiano
99835fb9ad [NewGVN] Fold single-use variable inside the assertion.
It placates some bots which complain because they compile the
assertion out and think the variable is unused.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290825 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-02 19:03:16 +00:00
Davide Italiano
ad8be6892b [NewGVN] Restore old code to placate buildbots.
Apparently my suggestion of using ternary doesn't really work
as clang complains about incompatible types on LHS and RHS. Some
GCC versions happen to accept the code but clang behaviour is
correct here.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290822 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-02 18:41:34 +00:00
Daniel Berlin
dcdec3c8b2 NewGVN: Fix some formatting and comment issues
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290820 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-02 18:22:38 +00:00
Daniel Berlin
2c8e9c4003 NewGVN: Add UnknownExpression and create them for things we can't symbolize. Kill fragile machinery for handling null expressions.
Summary:
This avoids the very fragile code for null expressions. We could also use a denseset that tracks which things have null expressions instead, but that seems pretty fragile and premature optimization.

This resolves a number of infinite loop cases, test reductions coming.

Reviewers: davide

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290816 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-02 18:00:53 +00:00
Daniel Berlin
61cf41cb39 NewGVN: Fix PR31480, PR31483, PR31499, by rewriting how memory congruence handling works.
Summary: Previously, we tried to fix up the equivalences during symbolic evaluation.  This does not work. Now, we change the equivalences during congruence finding, where it belongs.  We also initialize the equivalence table to give a maximal answer.

Reviewers: davide

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290815 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-02 18:00:46 +00:00
Davide Italiano
c37efe30b0 [NewGVN] Remove unneeded newline from assertion message.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290755 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-30 15:01:17 +00:00
Daniel Berlin
a250bf162b NewGVN: Fix PR 31491 by ensuring that we touch the right instructions. Change to one based numbering so we can assert we don't cause the same bug again.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290724 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-29 22:15:12 +00:00
Daniel Berlin
20d5949433 NewGVN: Sort Dominator Tree in RPO order, and use that for generating order.
Summary:
The optimal iteration order for this problem is RPO order. We want to
process as many preds of a backedge as we can before we process the
backedge.

At the same time, as we add predicate handling, we want to be able to
touch instructions that are dominated by a given block by
ranges (because a change in value numbering a predicate possibly
affects all users we dominate that are using that predicate).
If we don't do it this way, we can't do value inference over
backedges (the paper covers this in depth).

The newgvn branch currently overshoots the last part, and guarantees
that it will touch *at least* the right set of instructions, but it
does touch more.  This is because the bitvector instruction ranges are
currently generated in RPO order (so we take the max and the min of
the ranges of dominated blocks, which means there are some in the
middle we didn't have to touch that we did).

We can do better by sorting the dominator tree, and then just using
dominator tree order.

As a preliminary, the dominator tree has some RPO guarantees, but not
enough. It guarantees that for a given node, your idom must come
before you in the RPO ordering. It guarantees no relative RPO ordering
for siblings.  We add siblings in whatever order they appear in the module.

So that is what we fix.

We sort the children array of the domtree into RPO order, and then use
the dominator tree for ordering, instead of RPO, since the dominator
tree is now a valid RPO ordering.

Note: This would help any other pass that iterates a forward problem
in dominator tree order.  Most of them are single pass.  It will still
maximize whatever result they compute.  We could also build the
dominator tree in this order, but our incremental updates would still
put it out of sort order, and recomputing the sort order is almost as
hard as general incremental updates of the domtree.

Also note that the sorting does not affect any tests, etc. Nothing
depends on domtree order, including the verifier, the equals
functions for domtree nodes, etc.

How much could this matter, you ask?
Here are the current numbers.
This is generated by running NewGVN over all files in LLVM.

Note that once we propagate equalities, the differences go up by an
order of magnitude or two (IE instead of 29, the max ends up in the
thousands, since the worst case we add a factor of N, where N is the
number of branch predicates).  So while it doesn't look that stark for
the default ordering, it gets *much much* worse.  There are also
programs in the wild where the difference is already pretty stark
(2 iterations vs hundreds).

RPO ordering:
759040 Number of iterations is 1
112908 Number of iterations is 2

Default dominator tree ordering:
755081 Number of iterations is 1
116234 Number of iterations is 2
   603 Number of iterations is 3
    27 Number of iterations is 4
     2 Number of iterations is 5
     1 Number of iterations is 7

Dominator tree sorted:
759040 Number of iterations is 1
112908 Number of iterations is 2
<yay!>

Really bad ordering (sort domtree siblings in postorder. not quite the
worst possible, but yeah):
754008 Number of iterations is 1
    21 Number of iterations is 10
     8 Number of iterations is 11
     6 Number of iterations is 12
     5 Number of iterations is 13
     2 Number of iterations is 14
     2 Number of iterations is 15
     3 Number of iterations is 16
     1 Number of iterations is 17
     2 Number of iterations is 18
 96642 Number of iterations is 2
     1 Number of iterations is 20
     2 Number of iterations is 21
     1 Number of iterations is 22
     1 Number of iterations is 29
 17266 Number of iterations is 3
  2598 Number of iterations is 4
   798 Number of iterations is 5
   273 Number of iterations is 6
   186 Number of iterations is 7
    80 Number of iterations is 8
    42 Number of iterations is 9

Reviewers: chandlerc, davide

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290699 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-29 01:12:36 +00:00
Daniel Berlin
7102a297b1 Update equalsStoreHelper for the fact that only one branch can be true
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290697 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-29 00:49:32 +00:00
Piotr Padlewski
90bcc71ffb Revert "[NewGVN] replace emplace_back with push_back"
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290692 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-28 23:24:02 +00:00
Piotr Padlewski
6c8d9bce03 [NewGVN] replace emplace_back with push_back
emplace_back is not faster if it is equivalent to push_back. In this cases emplaced value had the
same type that the one stored in container. It is ugly and it might be even slower (see
Scott Meyers presentation about emplacement).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290685 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-28 20:36:08 +00:00
Piotr Padlewski
25a09f14f3 [NewGVN] Simplyfy loop NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290683 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-28 19:42:49 +00:00
Piotr Padlewski
f5420d0d0e [NewGVN] replace typedefs with usings
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290680 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-28 19:29:26 +00:00
Piotr Padlewski
79a32fd8a1 [NewGVN] NFC fixes
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290679 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-28 19:17:17 +00:00
Davide Italiano
569712b080 [NewGVN] Global sweep replacing NULL with nullptr. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290670 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-28 14:00:11 +00:00
Davide Italiano
1ed1f3f977 [NewGVN] Remove redundant code. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290669 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-28 13:54:16 +00:00
Davide Italiano
0a019f1735 [NewGVN] equals() for loads/stores is the same. Unify.
Differential Revision:  https://reviews.llvm.org/D28116

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290667 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-28 13:37:17 +00:00
Davide Italiano
447ea1706a [NewGVN] Simplify a bit removing else after return. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290615 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-27 18:15:39 +00:00
Daniel Berlin
215f38196b Change a std::vector to SmallVector in NewGVN
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290596 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-27 09:20:36 +00:00
Daniel Berlin
7870484ec8 clang-format NewGVN files
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290551 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-26 20:06:58 +00:00
Daniel Berlin
4650a04e6e Misc cleanups and simplifications for NewGVN.
Mostly use a bit more idiomatic C++ where we can,
so we can combine some things later.

Reviewers: davide

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290550 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-26 19:57:25 +00:00
Daniel Berlin
7784ce32b4 Don't use our own incorrect version of isTriviallyDeadInstruction in NewGVN. Fixes PR/31472
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290549 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-26 18:44:36 +00:00
Davide Italiano
1597cd40ac [NewGVN] Fold lookupOperandLeader() when there's only one use. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290543 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-26 16:19:34 +00:00
Daniel Berlin
21fb5a7f8d Value number stores and memory states so we can detect when memory states are equivalent (IE store of same value to memory).
Reviewers: davide

Subscribers: llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290525 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-25 22:23:49 +00:00
Daniel Berlin
c6e5fa688a Rename GVNExpression *ops_ members to *op_* to match conventions in the rest of LLVM
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290524 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-25 22:10:37 +00:00
Davide Italiano
b9072a62d0 [NewGVN] Prefer auto to explicit type when the latter is obvious.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290499 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-24 17:17:21 +00:00
Daniel Berlin
d49f798558 Mark isOnlyReachableViaThisEdge as const
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290468 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-24 00:04:07 +00:00
Davide Italiano
fa641c2b8d [NewGVN] Remove (for now) unused code. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290420 91177308-0d34-0410-b5e6-96231b3b80d8
2016-12-23 10:28:30 +00:00