Commit Graph

75 Commits

Author SHA1 Message Date
Alina Sbirlea
49ae59819e Only passes that preserve MemorySSA must mark it as preserved.
Summary:
The method `getLoopPassPreservedAnalyses` should not mark MemorySSA as
preserved, because it's being called in a lot of passes that do not
preserve MemorySSA.
Instead, mark the MemorySSA analysis as preserved by each pass that does
preserve it.
These changes only affect the new pass mananger.

Reviewers: chandlerc

Subscribers: mehdi_amini, jlebar, Prazek, george.burgess.iv, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363091 91177308-0d34-0410-b5e6-96231b3b80d8
2019-06-11 18:27:49 +00:00
Yevgeny Rouban
e8fab5b74f [LoopSimplifyCFG] Suppress expensive DomTree verification
This patch makes verification level lower for builds with
inexpensive checks.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359446 91177308-0d34-0410-b5e6-96231b3b80d8
2019-04-29 13:29:55 +00:00
Alina Sbirlea
eacfb8541a [LoopSimplifyCFG] Update MemorySSA after r353911.
Summary:
MemorySSA is not properly updated in LoopSimplifyCFG after recent changes. Use SplitBlock utility to resolve that and clear all updates once handleDeadExits is finished.
All updates that follow are removal of edges which are safe to handle via the removeEdge() API.
Also, deleting dead blocks is done correctly as is, i.e. delete from MemorySSA before updating the CFG and DT.

Reviewers: mkazantsev, rtereshin

Subscribers: sanjoy, jlebar, Prazek, george.burgess.iv, llvm-commits

Tags: #llvm

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354613 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-21 19:54:05 +00:00
Max Kazantsev
98a9c14860 [LoopSimplifyCFG] Add missing MSSA edge deletion
When we create fictive switch in preheader, we should take
care about MSSA and delete edge between old preheader and
header.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354547 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-21 05:51:29 +00:00
Max Kazantsev
58b987211a [NFC] API for signaling that the current loop is being deleted
We are planning to be able to delete the current loop in LoopSimplifyCFG
in the future. Add API to notify the loop pass manager that it happened.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354314 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-19 11:14:05 +00:00
Max Kazantsev
394aa56658 [NFC] Store loop header in a local to keep it available after the loop is deleted
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354313 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-19 11:13:58 +00:00
Max Kazantsev
8924ea3d57 [NFC] Teach getInnermostLoopFor walk up the loop trees
This should be NFC in current use case of this method, but it will
help to use it for solving more compex tasks in follow-up patches.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354227 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-17 18:21:51 +00:00
Max Kazantsev
281eb93196 [NFC] Fix name and clarifying comment for factored-out function
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354220 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-17 15:22:48 +00:00
Max Kazantsev
47fab601df [NFC] Factor out a function for future reuse
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354218 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-17 15:04:09 +00:00
Max Kazantsev
45cd157a1e [NFCI] Factor out block removal from stack of nested loops
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354124 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-15 12:18:10 +00:00
Simon Pilgrim
97cf8fa3e7 Fix "field 'DFS' will be initialized after field 'DTU'" warning. NFCI.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354123 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-15 12:13:16 +00:00
Max Kazantsev
e45a4d2855 [NFC] Promote DFS to field for further use
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@354118 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-15 11:39:35 +00:00
Max Kazantsev
9b05819742 [LoopSimplifyCFG] Re-enable const branch folding by default
Known underlying bugs have been fixed, intensive fuzz testing did not
find any new problems. Re-enabling by default. Feel free to revert if
it causes any functional failures.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353911 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-13 06:12:48 +00:00
Max Kazantsev
cfa6c5f00a [LoopSimplifyCFG] Change logic of dead loops removal to avoid hitting asserts
The function `LI.erase` has some invariants that need to be preserved when it
tries to remove a loop which is not the top-level loop. In particular, it
requires loop's preheader to be strictly in loop's parent. Our current logic
of deletion of dead blocks may erase the information about preheader before we
handle the loop, and therefore we may hit this assertion.

This patch changes the logic of loop deletion: we make them top-level loops
before we actually erase them. This allows us to trigger the simple branch of
`erase` logic which just detatches blocks from the loop and does not try to do
some complex stuff that need this invariant.

Thanks to @uabelho for reporting this!

Differential Revision: https://reviews.llvm.org/D57221
Reviewed By: fedor.sergeev


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353813 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-12 09:37:00 +00:00
Max Kazantsev
2841bd0ff5 Delete blocks from DTU to avoid dangling pointers
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353804 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-12 08:10:29 +00:00
Max Kazantsev
ce2d739dc1 [LoopSimplifyCFG] Pay respect to LCSSA when removing dead blocks
Utility function that we use for blocks deletion always unconditionally removes
one-input Phis. In LoopSimplifyCFG, it can lead to breach of LCSSA form.
This patch alters this function to keep them if needed.

Differential Revision: https://reviews.llvm.org/D57231
Reviewed By: fedor.sergeev


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353803 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-12 07:48:07 +00:00
Max Kazantsev
2c57c1ebcc [LoopSimplifyCFG] Use DTU.applyUpdates instead of insert/deleteEdge
`insert/deleteEdge` methods in DTU can make updates incorrectly in some cases
(see https://bugs.llvm.org/show_bug.cgi?id=40528), and it is recommended to
use `applyUpdates` methods instead when it is needed to make a mass update in CFG.

Differential Revision: https://reviews.llvm.org/D57316
Reviewed By: kuhar


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353502 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-08 08:12:41 +00:00
Max Kazantsev
acbe716cd7 [LoopSimplifyCFG] Do not count dead exit blocks twice, make CFG simpler
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353276 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-06 07:49:17 +00:00
Richard Trieu
1c34480b50 Move DomTreeUpdater from IR to Analysis
DomTreeUpdater depends on headers from Analysis, but is in IR.  This is a
layering violation since Analysis depends on IR.  Relocate this code from IR
to Analysis to fix the layering violation.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@353265 91177308-0d34-0410-b5e6-96231b3b80d8
2019-02-06 02:52:52 +00:00
Max Kazantsev
511f143e38 Properly use DT.verify in LoopSimplifyCFG
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352621 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-30 12:32:19 +00:00
Max Kazantsev
0e56479684 [LoopSimplifyCFG] Fix inconsistency in blocks in loop markup
2nd part of D57095 with the same reason, just in another place. We never
fold branches that are not immediately in the current loop, but this check
is missing in `IsEdgeLive` As result, it may think that the edge in subloop is
dead while it's live. It's a pessimization in the current stance.

Differential Revision: https://reviews.llvm.org/D57147
Reviewed By: rupprecht	


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352170 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-25 05:05:02 +00:00
Max Kazantsev
7a48151988 [LoopSimplifyCFG] Fix inconsistency in live blocks markup
When we choose whether or not we should mark block as dead, we have an
inconsistent logic in markup of live blocks.
- We take candidate IF its terminator branches on constant AND it is immediately
  in current loop;
- We mark successor live IF its terminator doesn't branch by constant OR it branches
  by constant and the successor is its always taken block.

What we are missing here is that when the terminator branches on a constant but is
not taken as a candidate because is it not immediately in the current loop, we will
mark only one (always taken) successor as live. Therefore, we do NOT do the actual
folding but may NOT mark one of the successors as live. So the result of markup is
wrong in this case, and we may then hit various asserts.

Thanks Jordan Rupprech for reporting this!

Differential Revision: https://reviews.llvm.org/D57095
Reviewed By: rupprecht


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352024 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-24 05:20:29 +00:00
Jordan Rupprecht
27047c8f82 Revert r351520, "Re-enable terminator folding in LoopSimplifyCFG"
This is still causing compilation crashes in some targets. Will follow up shortly with a repro.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351845 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-22 17:39:02 +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
Max Kazantsev
ab5ed89478 Re-enable terminator folding in LoopSimplifyCFG: underlying bugs fixed
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351520 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-18 04:57:32 +00:00
Max Kazantsev
a3ca8ce0e5 [LoopSimplifyCFG] Form LCSSA when a parent loop becomes a sibling
During the transforms in LoopSimplifyCFG, when we remove a dead exiting edge, the
parent loop may stop being reachable from the child loop, and therefore they become
siblings. If the former child loop had uses of some values from its former parent loop,
now such uses will require LCSSA Phis, even if they weren't needed before. So we must
form LCSSA for all loops that stopped being ancestors of the current loop in this case.

Differential Revision: https://reviews.llvm.org/D56144
Reviewed By: fedor.sergeev


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351434 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-17 12:51:10 +00:00
Max Kazantsev
5865df5baa [LoopSimplifyCFG] Fix order of deletion of complex dead subloops
Function `DeleteDeadBlock` requires that all predecessors of a block
being deleted have already been deleted, with the exception of a
single-block loop. When we use it for removal of dead subloops that
contain more than one block, we may not fulfull this requirement and
fail an assertion.

This patch replaces invocation of `DeleteDeadBlock` with a generalized
version `DeleteDeadBlocks` that is able to deal with multiple dead blocks,
even if they contain some cycles.

Differential Revision: https://reviews.llvm.org/D56121
Reviewed By: fedor.sergeev


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351433 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-17 12:25:40 +00:00
Benjamin Kramer
114f017218 Give helper classes/functions local linkage. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351016 91177308-0d34-0410-b5e6-96231b3b80d8
2019-01-12 18:36:22 +00:00
Max Kazantsev
67c6c6aed8 Drop SE cache early because loop parent can change in LoopSimplifyCFG
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350145 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-29 04:26:22 +00:00
Max Kazantsev
c489b656e8 Temporarily disable term folding in LoopSimplifyCFG, add tests
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350117 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-28 06:22:39 +00:00
Max Kazantsev
9800ccf353 [LoopSimplifyCFG] Delete dead blocks in RPO
Deletion of dead blocks in arbitrary order may lead to failure
of assertion in `DeleteDeadBlock` that requires that we have
deleted all predecessors before we can delete the current block.
We should instead delete them in RPO order.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350116 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-28 06:08:51 +00:00
Max Kazantsev
998b0e20dd [LoopSimplifyCFG] Delete dead exiting edges
This patch teaches LoopSimplifyCFG to remove dead exiting edges
from loops.

Differential Revision: https://reviews.llvm.org/D54025
Reviewed By: fedor.sergeev


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350049 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-24 07:41:33 +00:00
Max Kazantsev
7b3352e554 Return "[LoopSimplifyCFG] Delete dead in-loop blocks"
The underlying bug that caused the revert should be fixed by rL348567.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@350045 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-24 06:06:17 +00:00
Max Kazantsev
df9c0d05bd [LoopSimplifyCFG] Do not deal with loops with irreducible CFG inside
The current algorithm that collects live/dead/inloop blocks relies on some invariants
related to RPO and PO traversals. In particular, the important fact it requires is that
the only loop's latch is the first block in PO traversal. It also relies on fact that during
RPO we visit all prececessors of a block before we visit this block (backedges ignored).

If a loop has irreducible non-loop cycle inside, both these assumptions may break.
This patch adds detection for this situation and prohibits the terminator folding
for loops with irreducible CFG.

We can in theory support this later, for this some algorithmic changes are needed.
Besides, irreducible CFG is not a frequent situation and we can just don't bother.

Thanks @uabelho for finding this!

Differential Revision: https://reviews.llvm.org/D55357
Reviewed By: skatkov


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348567 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-07 05:44:45 +00:00
Ilya Biryukov
d42bdb79a1 Revert "[LoopSimplifyCFG] Delete dead in-loop blocks"
This reverts commit r348457.
The original commit causes clang to crash when doing an instrumented
build with a new pass manager. Reverting to unbreak our integrate.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348484 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-06 13:21:01 +00:00
Max Kazantsev
feb7e4fb0a [LoopSimplifyCFG] Delete dead in-loop blocks
This patch teaches LoopSimplifyCFG to delete loop blocks that have
become unreachable after terminator folding has been done.

Differential Revision: https://reviews.llvm.org/D54023
Reviewed By: anna


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348457 91177308-0d34-0410-b5e6-96231b3b80d8
2018-12-06 05:45:02 +00:00
Max Kazantsev
24b8fd959e [LoopSimplifyCFG] Update MemorySSA in terminator folding. PR39783
Terminator folding transform lacks MemorySSA update for memory Phis,
while they exist within MemorySSA analysis. They need exactly the same
type of updates as regular Phis. Failing to update them properly ends up
with inconsistent MemorySSA and manifests in various assertion failures.

This patch adds Memory Phi updates to this transform.

Thanks to @jonpa for finding this!

Differential Revision: https://reviews.llvm.org/D55050
Reviewed By: asbirlea


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347979 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-30 10:06:23 +00:00
Max Kazantsev
912d9b829e Disable TermFolding in LoopSimplifyCFG until PR39783 is fixed
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347844 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-29 09:00:19 +00:00
Max Kazantsev
052164630a [LoopSimplifyCFG] Turn on term folding after underlying bug fixed
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347641 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-27 06:19:42 +00:00
Max Kazantsev
e53078a5a4 [LoopSimplifyCFG] Fix corner case with duplicating successors
It fixes a bug that doesn't update Phi inputs of the only live successor that
is in the list of block's successors more than once.

Thanks @uabelho for finding this.

Differential Revision: https://reviews.llvm.org/D54849
Reviewed By: anna


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347640 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-27 06:17:21 +00:00
Max Kazantsev
f56b13f3e4 Disable LoopSimplifyCFG terminator folding by default
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347486 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-23 09:14:53 +00:00
Max Kazantsev
f2ac09bb54 [LoopSimplifyCFG] Don't delete LCSSA Phis
When removing edges, we also update Phi inputs and may end up removing
a Phi if it has only one input. We should not do it for edges that leave the current
loop because these Phis are LCSSA Phis and need to be preserved.

Thanks @dmgreen	for finding this!

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347484 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-23 07:56:47 +00:00
Max Kazantsev
b479b73525 [NFC] Assert that all blocks staying in loop are live
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347458 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-22 12:43:27 +00:00
Max Kazantsev
ee189cb45b [NFC] Ensure deterministic order of dead exit blocks
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347457 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-22 12:33:41 +00:00
Max Kazantsev
67af3175a8 [NFC] Simplify code by using standard exit blocks collection
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347454 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-22 10:48:30 +00:00
Max Kazantsev
7640c67cbf Recommit "[LoopSimplifyCFG] Teach LoopSimplifyCFG to constant-fold branches and switches"
The initial version of patch lacked Phi nodes updates in destinations of removed
edges. This version contains this update and tests on this situation.

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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347289 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-20 05:43:32 +00:00
Benjamin Kramer
c77c7e9e51 Revert "[LoopSimplifyCFG] Teach LoopSimplifyCFG to constant-fold branches and switches"
This reverts commits r347183 & r347184. Crashes while building libxml.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347260 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-19 20:01:20 +00:00
Max Kazantsev
508052c1d6 [LoopSimplifyCFG] Teach LoopSimplifyCFG to constant-fold branches and switches
This patch introduces infrastructure and the simplest case for constant-folding
of branch and switch instructions within loop into unconditional branches.
It is useful as a cleanup for such passes as loop unswitching that sometimes
produce such branches.

Only the simplest case supported in this patch: after the folding, no block
should become dead or stop being part of the loop. Support for more
sophisticated cases will go separately in follow-up patches.

Differential Revision: https://reviews.llvm.org/D54021
Reviewed By: anna


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@347183 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-19 05:54:38 +00:00
Max Kazantsev
1edc3c60f3 [NFC] Reorganize code to prepare it for more transforms
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@345820 91177308-0d34-0410-b5e6-96231b3b80d8
2018-11-01 09:42:50 +00:00
Alina Sbirlea
2e8575cb46 Update MemorySSA in LoopSimplifyCFG.
Summary:
Add MemorySSA as a dependency to LoopSimplifyCFG and preserve it.
Disabled by default until all passes preserve MemorySSA.

Reviewers: bogner, chandlerc

Subscribers: sanjoy, jlebar, Prazek, george.burgess.iv, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@340445 91177308-0d34-0410-b5e6-96231b3b80d8
2018-08-22 20:10:21 +00:00