1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00
llvm-mirror/test/Analysis/PostDominators/pr6047_c.ll
Jakub Kuderski e25b7db874 [Dominators] Include infinite loops in PostDominatorTree
Summary:
This patch teaches PostDominatorTree about infinite loops. It is built on top of D29705 by @dberlin which includes a very detailed motivation for this change.

What's new is that the patch also teaches the incremental updater how to deal with reverse-unreachable regions and how to properly maintain and verify tree roots. Before that, the incremental algorithm sometimes ended up preserving reverse-unreachable regions after updates that wouldn't appear in the tree if it was constructed from scratch on the same CFG.

This patch makes the following assumptions:
- A sequence of updates should produce the same tree as a recalculating it.
- Any sequence of the same updates should lead to the same tree.
- Siblings and roots are unordered.

The last two properties are essential to efficiently perform batch updates in the future.
When it comes to the first one, we can decide later that the consistency between freshly built tree and an updated one doesn't matter match, as there are many correct ways to pick roots in infinite loops, and to relax this assumption. That should enable us to recalculate postdominators less frequently.

This patch is pretty conservative when it comes to incremental updates on reverse-unreachable regions and ends up recalculating the whole tree in many cases. It should be possible to improve the performance in many cases, if we decide that it's important enough.
That being said, my experiments showed that reverse-unreachable are very rare in the IR emitted by clang when bootstrapping  clang. Here are the statistics I collected by analyzing IR between passes and after each removePredecessor call:

```
# functions:  52283
# samples:  337609
# reverse unreachable BBs:  216022
# BBs:  247840796
Percent reverse-unreachable:  0.08716159869015269 %
Max(PercRevUnreachable) in a function:  87.58620689655172 %
# > 25 % samples:  471 ( 0.1395104988314885 % samples )
... in 145 ( 0.27733680163724345 % functions )
```

Most of the reverse-unreachable regions come from invalid IR where it wouldn't be possible to construct a PostDomTree anyway.

I would like to commit this patch in the next week in order to be able to complete the work that depends on it before the end of my internship, so please don't wait long to voice your concerns :).

Reviewers: dberlin, sanjoy, grosser, brzycki, davide, chandlerc, hfinkel

Reviewed By: dberlin

Subscribers: nhaehnle, javed.absar, kparzysz, uabelho, jlebar, hiraditya, llvm-commits, dberlin, david2050

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

llvm-svn: 310940
2017-08-15 18:14:57 +00:00

197 lines
3.2 KiB
LLVM

; RUN: opt < %s -postdomtree -analyze | FileCheck %s
define internal void @f() {
entry:
br i1 undef, label %bb35, label %bb3.i
bb3.i:
br label %bb3.i
bb:
br label %bb35
bb.i:
br label %bb35
_float32_unpack.exit:
br label %bb35
bb.i5:
br label %bb35
_float32_unpack.exit8:
br label %bb35
bb32.preheader:
br label %bb35
bb3:
br label %bb35
bb3.split.us:
br label %bb35
bb.i4.us:
br label %bb35
bb7.i.us:
br label %bb35
bb.i4.us.backedge:
br label %bb35
bb1.i.us:
br label %bb35
bb6.i.us:
br label %bb35
bb4.i.us:
br label %bb35
bb8.i.us:
br label %bb35
bb3.i.loopexit.us:
br label %bb35
bb.nph21:
br label %bb35
bb4:
br label %bb35
bb5:
br label %bb35
bb14.preheader:
br label %bb35
bb.nph18:
br label %bb35
bb8.us.preheader:
br label %bb35
bb8.preheader:
br label %bb35
bb8.us:
br label %bb35
bb8:
br label %bb35
bb15.loopexit:
br label %bb35
bb15.loopexit2:
br label %bb35
bb15:
br label %bb35
bb16:
br label %bb35
bb17.loopexit.split:
br label %bb35
bb.nph14:
br label %bb35
bb19:
br label %bb35
bb20:
br label %bb35
bb29.preheader:
br label %bb35
bb.nph:
br label %bb35
bb23.us.preheader:
br label %bb35
bb23.preheader:
br label %bb35
bb23.us:
br label %bb35
bb23:
br label %bb35
bb30.loopexit:
br label %bb35
bb30.loopexit1:
br label %bb35
bb30:
br label %bb35
bb31:
br label %bb35
bb35.loopexit:
br label %bb35
bb35.loopexit3:
br label %bb35
bb35:
ret void
}
; CHECK: Inorder PostDominator Tree:
; CHECK-NEXT: [1] <<exit node>>
; CHECK-NEXT: [2] %bb35
; CHECK-NEXT: [3] %bb
; CHECK-NEXT: [3] %bb.i
; CHECK-NEXT: [3] %_float32_unpack.exit
; CHECK-NEXT: [3] %bb.i5
; CHECK-NEXT: [3] %_float32_unpack.exit8
; CHECK-NEXT: [3] %bb32.preheader
; CHECK-NEXT: [3] %bb3
; CHECK-NEXT: [3] %bb3.split.us
; CHECK-NEXT: [3] %bb.i4.us
; CHECK-NEXT: [3] %bb7.i.us
; CHECK-NEXT: [3] %bb.i4.us.backedge
; CHECK-NEXT: [3] %bb1.i.us
; CHECK-NEXT: [3] %bb6.i.us
; CHECK-NEXT: [3] %bb4.i.us
; CHECK-NEXT: [3] %bb8.i.us
; CHECK-NEXT: [3] %bb3.i.loopexit.us
; CHECK-NEXT: [3] %bb.nph21
; CHECK-NEXT: [3] %bb4
; CHECK-NEXT: [3] %bb5
; CHECK-NEXT: [3] %bb14.preheader
; CHECK-NEXT: [3] %bb.nph18
; CHECK-NEXT: [3] %bb8.us.preheader
; CHECK-NEXT: [3] %bb8.preheader
; CHECK-NEXT: [3] %bb8.us
; CHECK-NEXT: [3] %bb8
; CHECK-NEXT: [3] %bb15.loopexit
; CHECK-NEXT: [3] %bb15.loopexit2
; CHECK-NEXT: [3] %bb15
; CHECK-NEXT: [3] %bb16
; CHECK-NEXT: [3] %bb17.loopexit.split
; CHECK-NEXT: [3] %bb.nph14
; CHECK-NEXT: [3] %bb19
; CHECK-NEXT: [3] %bb20
; CHECK-NEXT: [3] %bb29.preheader
; CHECK-NEXT: [3] %bb.nph
; CHECK-NEXT: [3] %bb23.us.preheader
; CHECK-NEXT: [3] %bb23.preheader
; CHECK-NEXT: [3] %bb23.us
; CHECK-NEXT: [3] %bb23
; CHECK-NEXT: [3] %bb30.loopexit
; CHECK-NEXT: [3] %bb30.loopexit1
; CHECK-NEXT: [3] %bb30
; CHECK-NEXT: [3] %bb31
; CHECK-NEXT: [3] %bb35.loopexit
; CHECK-NEXT: [3] %bb35.loopexit3
; CHECK-NEXT: [2] %entry
; CHECK-NEXT: [2] %bb3.i
; CHECK-NEXT: Roots: %bb35 %bb3.i