llvm.org GIT mirror llvm / 1cbf1da
[PM/Unswitch] Fix a nasty bug in the new PM's unswitch introduced in r335553 with the non-trivial unswitching of switches. The code correctly updated most aspects of the CFG and analyses, but missed some crucial aspects: 1) When multiple cases have the same successor, we unswitch that a single time and replace the switch with a direct branch. The CFG here is correct, but the target of this direct branch may have had a PHI node with multiple entries in it. 2) When we still have to clone a successor of the switch into an unswitched copy of the loop, we'll delete potentially multiple edges entering this successor, not just one. 3) We also have to delete multiple edges entering the successors in the original loop when they have to be retained. 4) When the "retained successor" *also* occurs as a case successor, we just assert failed everywhere. This doesn't happen very easily because its always valid to simply drop the case -- the retained successor for switches is always the default successor. However, it is likely possible through some contrivance of different loop passes, unrolling, and simplifying for this to occur in practice and certainly there is nothing "invalid" about the IR so this pass needs to handle it. 5) In the case of #4, we also will replace these multiple edges with a direct branch much like in #1 and need to collapse the entries in any PHI nodes to a single enrty. All of this stems from the delightful fact that the same successor can show up in multiple parts of the switch terminator, and each of these are considered a distinct edge for the purpose of PHI nodes (and iterating the successors and predecessors) but not for unswitching itself, the dominator tree, or many other things. For the record, I intensely dislike this "feature" of the IR in large part because of the complexity it causes in passes like this. We already have a ton of logic building sets and handling duplicates, and we just had to add a bunch more. I've added a complex test case that covers all five of the above failure modes. I've also added a variation on it where #4 and #5 occur in loop exit, adding fun where we have an LCSSA PHI node with "multiple entries" despite have dedicated exits. There were no additional issues found by this, but it seems a useful corner case to cover with testing. One thing that working on all of this code has made painfully clear for me as well is how amazingly inefficient our PHI node representation is (in terms of the in-memory data structures and the APIs used to update them). This code has truly marvelous complexity bounds because every time we remove an entry from a PHI node we do a linear scan to find it and then a linear update to the data structure to remove it. We could in theory batch all of the PHI node updates into a single linear walk of the operands making this much more efficient, but the APIs fight hard against this and the fact that we have to handle duplicates in the peculiar manner we do (removing all but one in some cases) makes even implementing that very tedious and annoying. Anyways, none of this is new here or specific to loop unswitching. All code in LLVM that updates PHI node operands suffers from these problems. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@336536 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 1 year, 2 months ago
2 changed file(s) with 501 addition(s) and 94 deletion(s). Raw diff Collapse all Expand all
948948 AC.registerAssumption(II);
949949 }
950950
951 // Remove the cloned parent as a predecessor of the cloned continue successor
952 // if we did in fact clone it.
953 auto *ClonedParentBB = cast(VMap.lookup(ParentBB));
954 if (auto *ClonedContinueSuccBB =
955 cast_or_null(VMap.lookup(ContinueSuccBB)))
956 ClonedContinueSuccBB->removePredecessor(ClonedParentBB,
957 /*DontDeleteUselessPHIs*/ true);
958 // Replace the cloned branch with an unconditional branch to the cloned
959 // unswitched successor.
960 auto *ClonedSuccBB = cast(VMap.lookup(UnswitchedSuccBB));
961 ClonedParentBB->getTerminator()->eraseFromParent();
962 BranchInst::Create(ClonedSuccBB, ClonedParentBB);
963
964951 // Update any PHI nodes in the cloned successors of the skipped blocks to not
965952 // have spurious incoming values.
966953 for (auto *LoopBB : L.blocks())
969956 if (auto *ClonedSuccBB = cast_or_null(VMap.lookup(SuccBB)))
970957 for (PHINode &PN : ClonedSuccBB->phis())
971958 PN.removeIncomingValue(LoopBB, /*DeletePHIIfEmpty*/ false);
959
960 // Remove the cloned parent as a predecessor of any successor we ended up
961 // cloning other than the unswitched one.
962 auto *ClonedParentBB = cast(VMap.lookup(ParentBB));
963 for (auto *SuccBB : successors(ParentBB)) {
964 if (SuccBB == UnswitchedSuccBB)
965 continue;
966
967 auto *ClonedSuccBB = cast_or_null(VMap.lookup(SuccBB));
968 if (!ClonedSuccBB)
969 continue;
970
971 ClonedSuccBB->removePredecessor(ClonedParentBB,
972 /*DontDeleteUselessPHIs*/ true);
973 }
974
975 // Replace the cloned branch with an unconditional branch to the cloned
976 // unswitched successor.
977 auto *ClonedSuccBB = cast(VMap.lookup(UnswitchedSuccBB));
978 ClonedParentBB->getTerminator()->eraseFromParent();
979 BranchInst::Create(ClonedSuccBB, ClonedParentBB);
980
981 // If there are duplicate entries in the PHI nodes because of multiple edges
982 // to the unswitched successor, we need to nuke all but one as we replaced it
983 // with a direct branch.
984 for (PHINode &PN : ClonedSuccBB->phis()) {
985 bool Found = false;
986 // Loop over the incoming operands backwards so we can easily delete as we
987 // go without invalidating the index.
988 for (int i = PN.getNumOperands() - 1; i >= 0; --i) {
989 if (PN.getIncomingBlock(i) != ClonedParentBB)
990 continue;
991 if (!Found) {
992 Found = true;
993 continue;
994 }
995 PN.removeIncomingValue(i, /*DeletePHIIfEmpty*/ false);
996 }
997 }
972998
973999 // Record the domtree updates for the new blocks.
9741000 SmallPtrSet SuccSet;
17781804 UnswitchedSuccBBs.insert(BI->getSuccessor(ClonedSucc));
17791805 else
17801806 for (auto Case : SI->cases())
1781 UnswitchedSuccBBs.insert(Case.getCaseSuccessor());
1807 if (Case.getCaseSuccessor() != RetainedSuccBB)
1808 UnswitchedSuccBBs.insert(Case.getCaseSuccessor());
17821809
17831810 assert(!UnswitchedSuccBBs.count(RetainedSuccBB) &&
17841811 "Should not unswitch the same successor we are retaining!");
18721899 // nuke the initial terminator placed in the split block.
18731900 SplitBB->getTerminator()->eraseFromParent();
18741901 if (FullUnswitch) {
1875 for (BasicBlock *SuccBB : UnswitchedSuccBBs) {
1902 // First we need to unhook the successor relationship as we'll be replacing
1903 // the terminator with a direct branch. This is much simpler for branches
1904 // than switches so we handle those first.
1905 if (BI) {
18761906 // Remove the parent as a predecessor of the unswitched successor.
1877 SuccBB->removePredecessor(ParentBB,
1878 /*DontDeleteUselessPHIs*/ true);
1879 DTUpdates.push_back({DominatorTree::Delete, ParentBB, SuccBB});
1880 }
1881
1882 // Now splice the terminator from the original loop and rewrite its
1883 // successors.
1884 SplitBB->getInstList().splice(SplitBB->end(), ParentBB->getInstList(), TI);
1885 if (BI) {
18861907 assert(UnswitchedSuccBBs.size() == 1 &&
18871908 "Only one possible unswitched block for a branch!");
1909 BasicBlock *UnswitchedSuccBB = *UnswitchedSuccBBs.begin();
1910 UnswitchedSuccBB->removePredecessor(ParentBB,
1911 /*DontDeleteUselessPHIs*/ true);
1912 DTUpdates.push_back({DominatorTree::Delete, ParentBB, UnswitchedSuccBB});
1913 } else {
1914 // Note that we actually want to remove the parent block as a predecessor
1915 // of *every* case successor. The case successor is either unswitched,
1916 // completely eliminating an edge from the parent to that successor, or it
1917 // is a duplicate edge to the retained successor as the retained successor
1918 // is always the default successor and as we'll replace this with a direct
1919 // branch we no longer need the duplicate entries in the PHI nodes.
1920 assert(SI->getDefaultDest() == RetainedSuccBB &&
1921 "Not retaining default successor!");
1922 for (auto &Case : SI->cases())
1923 Case.getCaseSuccessor()->removePredecessor(
1924 ParentBB,
1925 /*DontDeleteUselessPHIs*/ true);
1926
1927 // We need to use the set to populate domtree updates as even when there
1928 // are multiple cases pointing at the same successor we only want to
1929 // remove and insert one edge in the domtree.
1930 for (BasicBlock *SuccBB : UnswitchedSuccBBs)
1931 DTUpdates.push_back({DominatorTree::Delete, ParentBB, SuccBB});
1932 }
1933
1934 // Now that we've unhooked the successor relationship, splice the terminator
1935 // from the original loop to the split.
1936 SplitBB->getInstList().splice(SplitBB->end(), ParentBB->getInstList(), TI);
1937
1938 // Now wire up the terminator to the preheaders.
1939 if (BI) {
18881940 BasicBlock *ClonedPH = ClonedPHs.begin()->second;
18891941 BI->setSuccessor(ClonedSucc, ClonedPH);
18901942 BI->setSuccessor(1 - ClonedSucc, LoopPH);
18931945 assert(SI && "Must either be a branch or switch!");
18941946
18951947 // Walk the cases and directly update their successors.
1948 SI->setDefaultDest(LoopPH);
18961949 for (auto &Case : SI->cases())
1897 Case.setSuccessor(ClonedPHs.find(Case.getCaseSuccessor())->second);
1950 if (Case.getCaseSuccessor() == RetainedSuccBB)
1951 Case.setSuccessor(LoopPH);
1952 else
1953 Case.setSuccessor(ClonedPHs.find(Case.getCaseSuccessor())->second);
1954
18981955 // We need to use the set to populate domtree updates as even when there
18991956 // are multiple cases pointing at the same successor we only want to
1900 // insert one edge in the domtree.
1957 // remove and insert one edge in the domtree.
19011958 for (BasicBlock *SuccBB : UnswitchedSuccBBs)
19021959 DTUpdates.push_back(
19031960 {DominatorTree::Insert, SplitBB, ClonedPHs.find(SuccBB)->second});
1904
1905 SI->setDefaultDest(LoopPH);
19061961 }
19071962
19081963 // Create a new unconditional branch to the continuing block (as opposed to
0 ; RUN: opt -passes='loop(unswitch),verify' -enable-nontrivial-unswitch -S < %s | FileCheck %s
11 ; RUN: opt -simple-loop-unswitch -enable-nontrivial-unswitch -S < %s | FileCheck %s
22
3 declare void @a()
4 declare void @b()
5 declare void @c()
6 declare void @d()
3 declare i32 @a()
4 declare i32 @b()
5 declare i32 @c()
6 declare i32 @d()
77
88 declare void @sink1(i32)
99 declare void @sink2(i32)
2828 ; CHECK-NEXT: br i1 %cond, label %loop_a, label %loop_b
2929
3030 loop_a:
31 call void @a() convergent
31 call i32 @a() convergent
3232 br label %loop_latch
3333
3434 loop_b:
35 call void @b()
35 call i32 @b()
3636 br label %loop_latch
3737
3838 loop_latch:
6060 ; CHECK-NEXT: br i1 %cond, label %loop_a, label %loop_b
6161
6262 loop_a:
63 call void @a() noduplicate
63 call i32 @a() noduplicate
6464 br label %loop_latch
6565
6666 loop_b:
67 call void @b()
67 call i32 @b()
6868 br label %loop_latch
6969
7070 loop_latch:
9595 ; CHECK-NEXT: br i1 %cond, label %loop_a, label %loop_b
9696
9797 loop_a:
98 call void @a()
98 call i32 @a()
9999 br label %loop_cont
100100
101101 loop_b:
102 call void @b()
102 call i32 @b()
103103 br label %loop_cont
104104
105105 loop_cont:
106 invoke void @a()
106 invoke i32 @a()
107107 to label %loop_latch unwind label %loop_catch
108108
109109 loop_latch:
138138 br i1 %cond1, label %loop_a, label %loop_b
139139
140140 loop_a:
141 call void @a()
141 call i32 @a()
142142 br label %latch
143143 ; The 'loop_a' unswitched loop.
144144 ;
149149 ; CHECK-NEXT: br label %loop_a.us
150150 ;
151151 ; CHECK: loop_a.us:
152 ; CHECK-NEXT: call void @a()
152 ; CHECK-NEXT: call i32 @a()
153153 ; CHECK-NEXT: br label %latch.us
154154 ;
155155 ; CHECK: latch.us:
167167 ; CHECK-NEXT: br i1 %cond2, label %entry.split.split.us, label %entry.split.split
168168
169169 loop_b_a:
170 call void @b()
170 call i32 @b()
171171 br label %latch
172172 ; The 'loop_b_a' unswitched loop.
173173 ;
181181 ; CHECK-NEXT: br label %loop_b_a.us
182182 ;
183183 ; CHECK: loop_b_a.us:
184 ; CHECK-NEXT: call void @b()
184 ; CHECK-NEXT: call i32 @b()
185185 ; CHECK-NEXT: br label %latch.us2
186186 ;
187187 ; CHECK: latch.us2:
192192 ; CHECK-NEXT: br label %loop_exit.split
193193
194194 loop_b_b:
195 call void @c()
195 call i32 @c()
196196 br label %latch
197197 ; The 'loop_b_b' unswitched loop.
198198 ;
206206 ; CHECK-NEXT: br label %loop_b_b
207207 ;
208208 ; CHECK: loop_b_b:
209 ; CHECK-NEXT: call void @c()
209 ; CHECK-NEXT: call i32 @c()
210210 ; CHECK-NEXT: br label %latch
211211 ;
212212 ; CHECK: latch:
23062306 ]
23072307
23082308 loop_a:
2309 call void @a()
2309 call i32 @a()
23102310 br label %loop_latch
23112311 ; Unswitched 'a' loop.
23122312 ;
23182318 ; CHECK-NEXT: br label %[[LOOP_A:.*]]
23192319 ;
23202320 ; CHECK: [[LOOP_A]]:
2321 ; CHECK-NEXT: call void @a()
2321 ; CHECK-NEXT: call i32 @a()
23222322 ; CHECK-NEXT: br label %[[LOOP_LATCH_A:.*]]
23232323 ;
23242324 ; CHECK: [[LOOP_LATCH_A]]:
23252325 ; CHECK: br label %[[LOOP_BEGIN_A]]
23262326
23272327 loop_b:
2328 call void @b()
2328 call i32 @b()
23292329 br label %loop_latch
23302330 ; Unswitched 'b' loop.
23312331 ;
23372337 ; CHECK-NEXT: br label %[[LOOP_B:.*]]
23382338 ;
23392339 ; CHECK: [[LOOP_B]]:
2340 ; CHECK-NEXT: call void @b()
2340 ; CHECK-NEXT: call i32 @b()
23412341 ; CHECK-NEXT: br label %[[LOOP_LATCH_B:.*]]
23422342 ;
23432343 ; CHECK: [[LOOP_LATCH_B]]:
23442344 ; CHECK: br label %[[LOOP_BEGIN_B]]
23452345
23462346 loop_c:
2347 call void @c() noreturn nounwind
2347 call i32 @c() noreturn nounwind
23482348 br label %loop_latch
23492349 ; Unswitched 'c' loop.
23502350 ;
23562356 ; CHECK-NEXT: br label %[[LOOP_C:.*]]
23572357 ;
23582358 ; CHECK: [[LOOP_C]]:
2359 ; CHECK-NEXT: call void @c()
2359 ; CHECK-NEXT: call i32 @c()
23602360 ; CHECK-NEXT: br label %[[LOOP_LATCH_C:.*]]
23612361 ;
23622362 ; CHECK: [[LOOP_LATCH_C]]:
26142614 ; CHECK-NEXT: br i1 %cond2, label %entry.split.us.split.us, label %entry.split.us.split
26152615
26162616 loop_a_a:
2617 call void @a()
2617 call i32 @a()
26182618 br label %latch
26192619 ; The 'loop_a_a' unswitched loop.
26202620 ;
26282628 ; CHECK-NEXT: br label %loop_a_a.us.us
26292629 ;
26302630 ; CHECK: loop_a_a.us.us:
2631 ; CHECK-NEXT: call void @a()
2631 ; CHECK-NEXT: call i32 @a()
26322632 ; CHECK-NEXT: br label %latch.us.us
26332633 ;
26342634 ; CHECK: latch.us.us:
26392639 ; CHECK-NEXT: br label %loop_exit.split
26402640
26412641 loop_a_c:
2642 call void @c()
2642 call i32 @c()
26432643 br label %latch
26442644 ; The 'loop_a_c' unswitched loop.
26452645 ;
26532653 ; CHECK-NEXT: br label %loop_a_c.us
26542654 ;
26552655 ; CHECK: loop_a_c.us:
2656 ; CHECK-NEXT: call void @c()
2656 ; CHECK-NEXT: call i32 @c()
26572657 ; CHECK-NEXT: br label %latch
26582658 ;
26592659 ; CHECK: latch.us:
26642664 ; CHECK-NEXT: br label %loop_exit.split
26652665
26662666 loop_b:
2667 call void @b()
2667 call i32 @b()
26682668 br label %latch
26692669 ; The 'loop_b' unswitched loop.
26702670 ;
26752675 ; CHECK-NEXT: br label %loop_b
26762676 ;
26772677 ; CHECK: loop_b:
2678 ; CHECK-NEXT: call void @b()
2678 ; CHECK-NEXT: call i32 @b()
26792679 ; CHECK-NEXT: br label %latch
26802680 ;
26812681 ; CHECK: latch:
27092709 br i1 %cond_or, label %loop_a, label %loop_b
27102710
27112711 loop_a:
2712 call void @a()
2712 call i32 @a()
27132713 br label %latch
27142714 ; The 'loop_a' unswitched loop.
27152715 ;
27222722 ; CHECK-NEXT: br label %loop_a.us
27232723 ;
27242724 ; CHECK: loop_a.us:
2725 ; CHECK-NEXT: call void @a()
2725 ; CHECK-NEXT: call i32 @a()
27262726 ; CHECK-NEXT: br label %latch.us
27272727 ;
27282728 ; CHECK: latch.us:
27332733 ; CHECK-NEXT: br label %loop_exit
27342734
27352735 loop_b:
2736 call void @b()
2736 call i32 @b()
27372737 br label %latch
27382738 ; The original loop.
27392739 ;
27462746 ; CHECK-NEXT: br i1 %[[OR]], label %loop_a, label %loop_b
27472747 ;
27482748 ; CHECK: loop_a:
2749 ; CHECK-NEXT: call void @a()
2749 ; CHECK-NEXT: call i32 @a()
27502750 ; CHECK-NEXT: br label %latch
27512751 ;
27522752 ; CHECK: loop_b:
2753 ; CHECK-NEXT: call void @b()
2753 ; CHECK-NEXT: call i32 @b()
27542754 ; CHECK-NEXT: br label %latch
27552755
27562756 latch:
28022802 ; CHECK-NEXT: br label %loop_b.us
28032803 ;
28042804 ; CHECK: loop_b.us:
2805 ; CHECK-NEXT: call void @b()
2805 ; CHECK-NEXT: call i32 @b()
28062806 ; CHECK-NEXT: br label %latch.us
28072807 ;
28082808 ; CHECK: latch.us:
28272827 ; CHECK-NEXT: br i1 %[[AND3]], label %loop_a, label %loop_b
28282828
28292829 loop_a:
2830 call void @a()
2830 call i32 @a()
28312831 br label %latch
28322832 ; CHECK: loop_a:
2833 ; CHECK-NEXT: call void @a()
2833 ; CHECK-NEXT: call i32 @a()
28342834 ; CHECK-NEXT: br label %latch
28352835
28362836 loop_b:
2837 call void @b()
2837 call i32 @b()
28382838 br label %latch
28392839 ; CHECK: loop_b:
2840 ; CHECK-NEXT: call void @b()
2840 ; CHECK-NEXT: call i32 @b()
28412841 ; CHECK-NEXT: br label %latch
28422842
28432843 latch:
28762876 ]
28772877
28782878 loop_a:
2879 call void @a()
2879 call i32 @a()
28802880 br label %latch
28812881 ; Unswitched 'a' loop.
28822882 ;
28872887 ; CHECK-NEXT: br label %[[LOOP_A:.*]]
28882888 ;
28892889 ; CHECK: [[LOOP_A]]:
2890 ; CHECK-NEXT: call void @a()
2890 ; CHECK-NEXT: call i32 @a()
28912891 ; CHECK-NEXT: br label %[[LOOP_LATCH_A:.*]]
28922892 ;
28932893 ; CHECK: [[LOOP_LATCH_A]]:
28982898 ; CHECK-NEXT: br label %loop_exit
28992899
29002900 loop_b:
2901 call void @b()
2901 call i32 @b()
29022902 br label %latch
29032903 ; Unswitched 'b' loop.
29042904 ;
29092909 ; CHECK-NEXT: br label %[[LOOP_B:.*]]
29102910 ;
29112911 ; CHECK: [[LOOP_B]]:
2912 ; CHECK-NEXT: call void @b()
2912 ; CHECK-NEXT: call i32 @b()
29132913 ; CHECK-NEXT: br label %[[LOOP_LATCH_B:.*]]
29142914 ;
29152915 ; CHECK: [[LOOP_LATCH_B]]:
29202920 ; CHECK-NEXT: br label %loop_exit
29212921
29222922 loop_c:
2923 call void @c()
2923 call i32 @c()
29242924 br label %latch
29252925 ; Unswitched 'c' loop.
29262926 ;
29312931 ; CHECK-NEXT: br label %[[LOOP_C:.*]]
29322932 ;
29332933 ; CHECK: [[LOOP_C]]:
2934 ; CHECK-NEXT: call void @c()
2934 ; CHECK-NEXT: call i32 @c()
29352935 ; CHECK-NEXT: br label %[[LOOP_LATCH_C:.*]]
29362936 ;
29372937 ; CHECK: [[LOOP_LATCH_C]]:
29632963 ret i32 0
29642964 ; CHECK: loop_exit:
29652965 ; CHECK-NEXT: ret i32 0
2966 }
2967
2968 ; A test case designed to exercise unusual properties of switches: they
2969 ; can introduce multiple edges to successors. These need lots of special case
2970 ; handling as they get collapsed in many cases (domtree, the unswitch itself)
2971 ; but not in all cases (the PHI node operands).
2972 define i32 @test28(i32 %arg) {
2973 ; CHECK-LABEL: @test28(
2974 entry:
2975 br label %header
2976 ; CHECK-NEXT: entry:
2977 ; CHECK-NEXT: switch i32 %arg, label %[[ENTRY_SPLIT_C:.*]] [
2978 ; CHECK-NEXT: i32 0, label %[[ENTRY_SPLIT_A:.*]]
2979 ; CHECK-NEXT: i32 1, label %[[ENTRY_SPLIT_A]]
2980 ; CHECK-NEXT: i32 2, label %[[ENTRY_SPLIT_B:.*]]
2981 ; CHECK-NEXT: i32 3, label %[[ENTRY_SPLIT_C]]
2982 ; CHECK-NEXT: ]
2983
2984 header:
2985 %tmp = call i32 @d()
2986 %cmp1 = icmp eq i32 %tmp, 0
2987 ; We set up a chain through all the successors of the switch that doesn't
2988 ; involve the switch so that we can have interesting PHI nodes in them.
2989 br i1 %cmp1, label %body.a, label %dispatch
2990
2991 dispatch:
2992 ; Switch with multiple successors. We arrange the last successor to be the
2993 ; default to make the test case easier to read. This has a duplicate edge
2994 ; both to the default destination (which is completely superfluous but
2995 ; technically valid IR) and to a regular successor.
2996 switch i32 %arg, label %body.c [
2997 i32 0, label %body.a
2998 i32 1, label %body.a
2999 i32 2, label %body.b
3000 i32 3, label %body.c
3001 ]
3002
3003 body.a:
3004 %tmp.a.phi = phi i32 [ 0, %header ], [ %tmp, %dispatch ], [ %tmp, %dispatch ]
3005 %tmp.a = call i32 @a()
3006 %tmp.a.sum = add i32 %tmp.a.phi, %tmp.a
3007 br label %body.b
3008 ; Unswitched 'a' loop.
3009 ;
3010 ; CHECK: [[ENTRY_SPLIT_A]]:
3011 ; CHECK-NEXT: br label %[[HEADER_A:.*]]
3012 ;
3013 ; CHECK: [[HEADER_A]]:
3014 ; CHECK-NEXT: %[[TMP_A:.*]] = call i32 @d()
3015 ; CHECK-NEXT: %[[CMP1_A:.*]] = icmp eq i32 %[[TMP_A]], 0
3016 ; CHECK-NEXT: br i1 %[[CMP1_A]], label %[[BODY_A_A:.*]], label %[[DISPATCH_A:.*]]
3017 ;
3018 ; CHECK: [[DISPATCH_A]]:
3019 ; CHECK-NEXT: br label %[[BODY_A_A]]
3020 ;
3021 ; CHECK: [[BODY_A_A]]:
3022 ; CHECK-NEXT: %[[TMP_A_PHI_A:.*]] = phi i32 [ 0, %[[HEADER_A]] ], [ %[[TMP_A]], %[[DISPATCH_A]] ]
3023 ; CHECK-NEXT: %[[TMP_A_A:.*]] = call i32 @a()
3024 ; CHECK-NEXT: %[[TMP_A_SUM_A:.*]] = add i32 %[[TMP_A_PHI_A]], %[[TMP_A_A]]
3025 ; CHECK-NEXT: br label %[[BODY_B_A:.*]]
3026 ;
3027 ; CHECK: [[BODY_B_A]]:
3028 ; CHECK-NEXT: %[[TMP_B_PHI_A:.*]] = phi i32 [ %[[TMP_A_SUM_A]], %[[BODY_A_A]] ]
3029 ; CHECK-NEXT: %[[TMP_B_A:.*]] = call i32 @b()
3030 ; CHECK-NEXT: %[[TMP_B_SUM_A:.*]] = add i32 %[[TMP_B_PHI_A]], %[[TMP_B_A]]
3031 ; CHECK-NEXT: br label %[[BODY_C_A:.*]]
3032 ;
3033 ; CHECK: [[BODY_C_A]]:
3034 ; CHECK-NEXT: %[[TMP_C_PHI_A:.*]] = phi i32 [ %[[TMP_B_SUM_A]], %[[BODY_B_A]] ]
3035 ; CHECK-NEXT: %[[TMP_C_A:.*]] = call i32 @c()
3036 ; CHECK-NEXT: %[[TMP_C_SUM_A:.*]] = add i32 %[[TMP_C_PHI_A]], %[[TMP_C_A]]
3037 ; CHECK-NEXT: br label %[[LATCH_A:.*]]
3038 ;
3039 ; CHECK: [[LATCH_A]]:
3040 ; CHECK-NEXT: %[[CMP2_A:.*]] = icmp slt i32 %[[TMP_C_SUM_A]], 42
3041 ; CHECK: br i1 %[[CMP2_A]], label %[[HEADER_A]], label %[[LOOP_EXIT_A:.*]]
3042 ;
3043 ; CHECK: [[LOOP_EXIT_A]]:
3044 ; CHECK-NEXT: %[[LCSSA_A:.*]] = phi i32 [ %[[TMP_C_SUM_A]], %[[LATCH_A]] ]
3045 ; CHECK-NEXT: br label %exit
3046
3047 body.b:
3048 %tmp.b.phi = phi i32 [ %tmp, %dispatch ], [ %tmp.a.sum, %body.a ]
3049 %tmp.b = call i32 @b()
3050 %tmp.b.sum = add i32 %tmp.b.phi, %tmp.b
3051 br label %body.c
3052 ; Unswitched 'b' loop.
3053 ;
3054 ; CHECK: [[ENTRY_SPLIT_B]]:
3055 ; CHECK-NEXT: br label %[[HEADER_B:.*]]
3056 ;
3057 ; CHECK: [[HEADER_B]]:
3058 ; CHECK-NEXT: %[[TMP_B:.*]] = call i32 @d()
3059 ; CHECK-NEXT: %[[CMP1_B:.*]] = icmp eq i32 %[[TMP_B]], 0
3060 ; CHECK-NEXT: br i1 %[[CMP1_B]], label %[[BODY_A_B:.*]], label %[[DISPATCH_B:.*]]
3061 ;
3062 ; CHECK: [[DISPATCH_B]]:
3063 ; CHECK-NEXT: br label %[[BODY_B_B:.*]]
3064 ;
3065 ; CHECK: [[BODY_A_B]]:
3066 ; CHECK-NEXT: %[[TMP_A_PHI_B:.*]] = phi i32 [ 0, %[[HEADER_B]] ]
3067 ; CHECK-NEXT: %[[TMP_A_B:.*]] = call i32 @a()
3068 ; CHECK-NEXT: %[[TMP_A_SUM_B:.*]] = add i32 %[[TMP_A_PHI_B]], %[[TMP_A_B]]
3069 ; CHECK-NEXT: br label %[[BODY_B_B:.*]]
3070 ;
3071 ; CHECK: [[BODY_B_B]]:
3072 ; CHECK-NEXT: %[[TMP_B_PHI_B:.*]] = phi i32 [ %[[TMP_B]], %[[DISPATCH_B]] ], [ %[[TMP_A_SUM_B]], %[[BODY_A_B]] ]
3073 ; CHECK-NEXT: %[[TMP_B_B:.*]] = call i32 @b()
3074 ; CHECK-NEXT: %[[TMP_B_SUM_B:.*]] = add i32 %[[TMP_B_PHI_B]], %[[TMP_B_B]]
3075 ; CHECK-NEXT: br label %[[BODY_C_B:.*]]
3076 ;
3077 ; CHECK: [[BODY_C_B]]:
3078 ; CHECK-NEXT: %[[TMP_C_PHI_B:.*]] = phi i32 [ %[[TMP_B_SUM_B]], %[[BODY_B_B]] ]
3079 ; CHECK-NEXT: %[[TMP_C_B:.*]] = call i32 @c()
3080 ; CHECK-NEXT: %[[TMP_C_SUM_B:.*]] = add i32 %[[TMP_C_PHI_B]], %[[TMP_C_B]]
3081 ; CHECK-NEXT: br label %[[LATCH_B:.*]]
3082 ;
3083 ; CHECK: [[LATCH_B]]:
3084 ; CHECK-NEXT: %[[CMP2_B:.*]] = icmp slt i32 %[[TMP_C_SUM_B]], 42
3085 ; CHECK: br i1 %[[CMP2_B]], label %[[HEADER_B]], label %[[LOOP_EXIT_B:.*]]
3086 ;
3087 ; CHECK: [[LOOP_EXIT_B]]:
3088 ; CHECK-NEXT: %[[LCSSA_B:.*]] = phi i32 [ %[[TMP_C_SUM_B]], %[[LATCH_B]] ]
3089 ; CHECK-NEXT: br label %[[EXIT_SPLIT:.*]]
3090
3091 body.c:
3092 %tmp.c.phi = phi i32 [ %tmp, %dispatch ], [ %tmp, %dispatch ], [ %tmp.b.sum, %body.b ]
3093 %tmp.c = call i32 @c()
3094 %tmp.c.sum = add i32 %tmp.c.phi, %tmp.c
3095 br label %latch
3096 ; Unswitched 'c' loop.
3097 ;
3098 ; CHECK: [[ENTRY_SPLIT_C]]:
3099 ; CHECK-NEXT: br label %[[HEADER_C:.*]]
3100 ;
3101 ; CHECK: [[HEADER_C]]:
3102 ; CHECK-NEXT: %[[TMP_C:.*]] = call i32 @d()
3103 ; CHECK-NEXT: %[[CMP1_C:.*]] = icmp eq i32 %[[TMP_C]], 0
3104 ; CHECK-NEXT: br i1 %[[CMP1_C]], label %[[BODY_A_C:.*]], label %[[DISPATCH_C:.*]]
3105 ;
3106 ; CHECK: [[DISPATCH_C]]:
3107 ; CHECK-NEXT: br label %[[BODY_C_C:.*]]
3108 ;
3109 ; CHECK: [[BODY_A_C]]:
3110 ; CHECK-NEXT: %[[TMP_A_PHI_C:.*]] = phi i32 [ 0, %[[HEADER_C]] ]
3111 ; CHECK-NEXT: %[[TMP_A_C:.*]] = call i32 @a()
3112 ; CHECK-NEXT: %[[TMP_A_SUM_C:.*]] = add i32 %[[TMP_A_PHI_C]], %[[TMP_A_C]]
3113 ; CHECK-NEXT: br label %[[BODY_B_C:.*]]
3114 ;
3115 ; CHECK: [[BODY_B_C]]:
3116 ; CHECK-NEXT: %[[TMP_B_PHI_C:.*]] = phi i32 [ %[[TMP_A_SUM_C]], %[[BODY_A_C]] ]
3117 ; CHECK-NEXT: %[[TMP_B_C:.*]] = call i32 @b()
3118 ; CHECK-NEXT: %[[TMP_B_SUM_C:.*]] = add i32 %[[TMP_B_PHI_C]], %[[TMP_B_C]]
3119 ; CHECK-NEXT: br label %[[BODY_C_C:.*]]
3120 ;
3121 ; CHECK: [[BODY_C_C]]:
3122 ; CHECK-NEXT: %[[TMP_C_PHI_C:.*]] = phi i32 [ %[[TMP_C]], %[[DISPATCH_C]] ], [ %[[TMP_B_SUM_C]], %[[BODY_B_C]] ]
3123 ; CHECK-NEXT: %[[TMP_C_C:.*]] = call i32 @c()
3124 ; CHECK-NEXT: %[[TMP_C_SUM_C:.*]] = add i32 %[[TMP_C_PHI_C]], %[[TMP_C_C]]
3125 ; CHECK-NEXT: br label %[[LATCH_C:.*]]
3126 ;
3127 ; CHECK: [[LATCH_C]]:
3128 ; CHECK-NEXT: %[[CMP2_C:.*]] = icmp slt i32 %[[TMP_C_SUM_C]], 42
3129 ; CHECK: br i1 %[[CMP2_C]], label %[[HEADER_C]], label %[[LOOP_EXIT_C:.*]]
3130 ;
3131 ; CHECK: [[LOOP_EXIT_C]]:
3132 ; CHECK-NEXT: %[[LCSSA_C:.*]] = phi i32 [ %[[TMP_C_SUM_C]], %[[LATCH_C]] ]
3133 ; CHECK-NEXT: br label %[[EXIT_SPLIT]]
3134
3135 latch:
3136 %cmp2 = icmp slt i32 %tmp.c.sum, 42
3137 br i1 %cmp2, label %header, label %exit
3138
3139 exit:
3140 %lcssa.phi = phi i32 [ %tmp.c.sum, %latch ]
3141 ret i32 %lcssa.phi
3142 ; CHECK: [[EXIT_SPLIT]]:
3143 ; CHECK-NEXT: %[[EXIT_PHI1:.*]] = phi i32 [ %[[LCSSA_C]], %[[LOOP_EXIT_C]] ], [ %[[LCSSA_B]], %[[LOOP_EXIT_B]] ]
3144 ; CHECK-NEXT: br label %exit
3145
3146 ; CHECK: exit:
3147 ; CHECK-NEXT: %[[EXIT_PHI2:.*]] = phi i32 [ %[[EXIT_PHI1]], %[[EXIT_SPLIT]] ], [ %[[LCSSA_A]], %[[LOOP_EXIT_A]] ]
3148 ; CHECK-NEXT: ret i32 %[[EXIT_PHI2]]
3149 }
3150
3151 ; Similar to @test28 but designed to have one of the duplicate edges be
3152 ; a loop exit edge as those can in some cases be special. Among other things,
3153 ; this includes an LCSSA phi with multiple entries despite being a dedicated
3154 ; exit block.
3155 define i32 @test29(i32 %arg) {
3156 ; CHECK-LABEL: define i32 @test29(
3157 entry:
3158 br label %header
3159 ; CHECK-NEXT: entry:
3160 ; CHECK-NEXT: switch i32 %arg, label %[[ENTRY_SPLIT_EXIT:.*]] [
3161 ; CHECK-NEXT: i32 -1, label %[[ENTRY_SPLIT_EXIT]]
3162 ; CHECK-NEXT: i32 0, label %[[ENTRY_SPLIT_A:.*]]
3163 ; CHECK-NEXT: i32 1, label %[[ENTRY_SPLIT_B:.*]]
3164 ; CHECK-NEXT: i32 2, label %[[ENTRY_SPLIT_B]]
3165 ; CHECK-NEXT: ]
3166
3167 header:
3168 %tmp = call i32 @d()
3169 %cmp1 = icmp eq i32 %tmp, 0
3170 br i1 %cmp1, label %body.a, label %dispatch
3171
3172 dispatch:
3173 switch i32 %arg, label %loop.exit1 [
3174 i32 -1, label %loop.exit1
3175 i32 0, label %body.a
3176 i32 1, label %body.b
3177 i32 2, label %body.b
3178 ]
3179
3180 body.a:
3181 %tmp.a.phi = phi i32 [ 0, %header ], [ %tmp, %dispatch ]
3182 %tmp.a = call i32 @a()
3183 %tmp.a.sum = add i32 %tmp.a.phi, %tmp.a
3184 br label %body.b
3185 ; Unswitched 'a' loop.
3186 ;
3187 ; CHECK: [[ENTRY_SPLIT_A]]:
3188 ; CHECK-NEXT: br label %[[HEADER_A:.*]]
3189 ;
3190 ; CHECK: [[HEADER_A]]:
3191 ; CHECK-NEXT: %[[TMP_A:.*]] = call i32 @d()
3192 ; CHECK-NEXT: %[[CMP1_A:.*]] = icmp eq i32 %[[TMP_A]], 0
3193 ; CHECK-NEXT: br i1 %[[CMP1_A]], label %[[BODY_A_A:.*]], label %[[DISPATCH_A:.*]]
3194 ;
3195 ; CHECK: [[DISPATCH_A]]:
3196 ; CHECK-NEXT: br label %[[BODY_A_A]]
3197 ;
3198 ; CHECK: [[BODY_A_A]]:
3199 ; CHECK-NEXT: %[[TMP_A_PHI_A:.*]] = phi i32 [ 0, %[[HEADER_A]] ], [ %[[TMP_A]], %[[DISPATCH_A]] ]
3200 ; CHECK-NEXT: %[[TMP_A_A:.*]] = call i32 @a()
3201 ; CHECK-NEXT: %[[TMP_A_SUM_A:.*]] = add i32 %[[TMP_A_PHI_A]], %[[TMP_A_A]]
3202 ; CHECK-NEXT: br label %[[BODY_B_A:.*]]
3203 ;
3204 ; CHECK: [[BODY_B_A]]:
3205 ; CHECK-NEXT: %[[TMP_B_PHI_A:.*]] = phi i32 [ %[[TMP_A_SUM_A]], %[[BODY_A_A]] ]
3206 ; CHECK-NEXT: %[[TMP_B_A:.*]] = call i32 @b()
3207 ; CHECK-NEXT: %[[TMP_B_SUM_A:.*]] = add i32 %[[TMP_B_PHI_A]], %[[TMP_B_A]]
3208 ; CHECK-NEXT: br label %[[LATCH_A:.*]]
3209 ;
3210 ; CHECK: [[LATCH_A]]:
3211 ; CHECK-NEXT: %[[CMP2_A:.*]] = icmp slt i32 %[[TMP_B_SUM_A]], 42
3212 ; CHECK: br i1 %[[CMP2_A]], label %[[HEADER_A]], label %[[LOOP_EXIT_A:.*]]
3213 ;
3214 ; CHECK: [[LOOP_EXIT_A]]:
3215 ; CHECK-NEXT: %[[LCSSA_A:.*]] = phi i32 [ %[[TMP_B_SUM_A]], %[[LATCH_A]] ]
3216 ; CHECK-NEXT: br label %loop.exit2
3217
3218 body.b:
3219 %tmp.b.phi = phi i32 [ %tmp, %dispatch ], [ %tmp, %dispatch ], [ %tmp.a.sum, %body.a ]
3220 %tmp.b = call i32 @b()
3221 %tmp.b.sum = add i32 %tmp.b.phi, %tmp.b
3222 br label %latch
3223 ; Unswitched 'b' loop.
3224 ;
3225 ; CHECK: [[ENTRY_SPLIT_B]]:
3226 ; CHECK-NEXT: br label %[[HEADER_B:.*]]
3227 ;
3228 ; CHECK: [[HEADER_B]]:
3229 ; CHECK-NEXT: %[[TMP_B:.*]] = call i32 @d()
3230 ; CHECK-NEXT: %[[CMP1_B:.*]] = icmp eq i32 %[[TMP_B]], 0
3231 ; CHECK-NEXT: br i1 %[[CMP1_B]], label %[[BODY_A_B:.*]], label %[[DISPATCH_B:.*]]
3232 ;
3233 ; CHECK: [[DISPATCH_B]]:
3234 ; CHECK-NEXT: br label %[[BODY_B_B]]
3235 ;
3236 ; CHECK: [[BODY_A_B]]:
3237 ; CHECK-NEXT: %[[TMP_A_PHI_B:.*]] = phi i32 [ 0, %[[HEADER_B]] ]
3238 ; CHECK-NEXT: %[[TMP_A_B:.*]] = call i32 @a()
3239 ; CHECK-NEXT: %[[TMP_A_SUM_B:.*]] = add i32 %[[TMP_A_PHI_B]], %[[TMP_A_B]]
3240 ; CHECK-NEXT: br label %[[BODY_B_B:.*]]
3241 ;
3242 ; CHECK: [[BODY_B_B]]:
3243 ; CHECK-NEXT: %[[TMP_B_PHI_B:.*]] = phi i32 [ %[[TMP_B]], %[[DISPATCH_B]] ], [ %[[TMP_A_SUM_B]], %[[BODY_A_B]] ]
3244 ; CHECK-NEXT: %[[TMP_B_B:.*]] = call i32 @b()
3245 ; CHECK-NEXT: %[[TMP_B_SUM_B:.*]] = add i32 %[[TMP_B_PHI_B]], %[[TMP_B_B]]
3246 ; CHECK-NEXT: br label %[[LATCH_B:.*]]
3247 ;
3248 ; CHECK: [[LATCH_B]]:
3249 ; CHECK-NEXT: %[[CMP2_B:.*]] = icmp slt i32 %[[TMP_B_SUM_B]], 42
3250 ; CHECK: br i1 %[[CMP2_B]], label %[[HEADER_B]], label %[[LOOP_EXIT_B:.*]]
3251 ;
3252 ; CHECK: [[LOOP_EXIT_B]]:
3253 ; CHECK-NEXT: %[[LCSSA_B:.*]] = phi i32 [ %[[TMP_B_SUM_B]], %[[LATCH_B]] ]
3254 ; CHECK-NEXT: br label %[[LOOP_EXIT2_SPLIT:.*]]
3255
3256 latch:
3257 %cmp2 = icmp slt i32 %tmp.b.sum, 42
3258 br i1 %cmp2, label %header, label %loop.exit2
3259
3260 loop.exit1:
3261 %l1.phi = phi i32 [ %tmp, %dispatch ], [ %tmp, %dispatch ]
3262 br label %exit
3263 ; Unswitched 'exit' loop.
3264 ;
3265 ; CHECK: [[ENTRY_SPLIT_EXIT]]:
3266 ; CHECK-NEXT: br label %[[HEADER_EXIT:.*]]
3267 ;
3268 ; CHECK: [[HEADER_EXIT]]:
3269 ; CHECK-NEXT: %[[TMP_EXIT:.*]] = call i32 @d()
3270 ; CHECK-NEXT: %[[CMP1_EXIT:.*]] = icmp eq i32 %[[TMP_EXIT]], 0
3271 ; CHECK-NEXT: br i1 %[[CMP1_EXIT]], label %[[BODY_A_EXIT:.*]], label %[[DISPATCH_EXIT:.*]]
3272 ;
3273 ; CHECK: [[DISPATCH_EXIT]]:
3274 ; CHECK-NEXT: %[[TMP_LCSSA:.*]] = phi i32 [ %[[TMP_EXIT]], %[[HEADER_EXIT]] ]
3275 ; CHECK-NEXT: br label %loop.exit1
3276 ;
3277 ; CHECK: [[BODY_A_EXIT]]:
3278 ; CHECK-NEXT: %[[TMP_A_PHI_EXIT:.*]] = phi i32 [ 0, %[[HEADER_EXIT]] ]
3279 ; CHECK-NEXT: %[[TMP_A_EXIT:.*]] = call i32 @a()
3280 ; CHECK-NEXT: %[[TMP_A_SUM_EXIT:.*]] = add i32 %[[TMP_A_PHI_EXIT]], %[[TMP_A_EXIT]]
3281 ; CHECK-NEXT: br label %[[BODY_B_EXIT:.*]]
3282 ;
3283 ; CHECK: [[BODY_B_EXIT]]:
3284 ; CHECK-NEXT: %[[TMP_B_PHI_EXIT:.*]] = phi i32 [ %[[TMP_A_SUM_EXIT]], %[[BODY_A_EXIT]] ]
3285 ; CHECK-NEXT: %[[TMP_B_EXIT:.*]] = call i32 @b()
3286 ; CHECK-NEXT: %[[TMP_B_SUM_EXIT:.*]] = add i32 %[[TMP_B_PHI_EXIT]], %[[TMP_B_EXIT]]
3287 ; CHECK-NEXT: br label %[[LATCH_EXIT:.*]]
3288 ;
3289 ; CHECK: [[LATCH_EXIT]]:
3290 ; CHECK-NEXT: %[[CMP2_EXIT:.*]] = icmp slt i32 %[[TMP_B_SUM_EXIT]], 42
3291 ; CHECK: br i1 %[[CMP2_EXIT]], label %[[HEADER_EXIT]], label %[[LOOP_EXIT_EXIT:.*]]
3292 ;
3293 ; CHECK: loop.exit1:
3294 ; CHECK-NEXT: %[[L1_PHI:.*]] = phi i32 [ %[[TMP_LCSSA]], %[[DISPATCH_EXIT]] ]
3295 ; CHECK-NEXT: br label %exit
3296 ;
3297 ; CHECK: [[LOOP_EXIT_EXIT]]:
3298 ; CHECK-NEXT: %[[L2_PHI:.*]] = phi i32 [ %[[TMP_B_SUM_EXIT]], %[[LATCH_EXIT]] ]
3299 ; CHECK-NEXT: br label %[[LOOP_EXIT2_SPLIT]]
3300
3301 loop.exit2:
3302 %l2.phi = phi i32 [ %tmp.b.sum, %latch ]
3303 br label %exit
3304 ; CHECK: [[LOOP_EXIT2_SPLIT]]:
3305 ; CHECK-NEXT: %[[LOOP_EXIT_PHI1:.*]] = phi i32 [ %[[L2_PHI]], %[[LOOP_EXIT_EXIT]] ], [ %[[LCSSA_B]], %[[LOOP_EXIT_B]] ]
3306 ; CHECK-NEXT: br label %loop.exit2
3307 ;
3308 ; CHECK: loop.exit2:
3309 ; CHECK-NEXT: %[[LOOP_EXIT_PHI2:.*]] = phi i32 [ %[[LOOP_EXIT_PHI1]], %[[LOOP_EXIT2_SPLIT]] ], [ %[[LCSSA_A]], %[[LOOP_EXIT_A]] ]
3310 ; CHECK-NEXT: br label %exit
3311
3312 exit:
3313 %l.phi = phi i32 [ %l1.phi, %loop.exit1 ], [ %l2.phi, %loop.exit2 ]
3314 ret i32 %l.phi
3315 ; CHECK: exit:
3316 ; CHECK-NEXT: %[[EXIT_PHI:.*]] = phi i32 [ %[[L1_PHI]], %loop.exit1 ], [ %[[LOOP_EXIT_PHI2]], %loop.exit2 ]
3317 ; CHECK-NEXT: ret i32 %[[EXIT_PHI]]
29663318 }
29673319
29683320 ; Unswitch will not actually change the loop nest from:
29903342 ; CHECK-NEXT: br label %[[C_HEADER_US:.*]]
29913343 ;
29923344 ; CHECK: [[C_HEADER_US]]:
2993 ; CHECK-NEXT: call void @c()
3345 ; CHECK-NEXT: call i32 @c()
29943346 ; CHECK-NEXT: br label %[[B_LATCH_SPLIT_US:.*]]
29953347 ;
29963348 ; CHECK: [[B_LATCH_SPLIT_US]]:
30003352 ; CHECK-NEXT: br label %c.header
30013353
30023354 c.header:
3003 call void @c()
3355 call i32 @c()
30043356 br i1 %v1, label %b.latch, label %c.latch
30053357 ; CHECK: c.header:
3006 ; CHECK-NEXT: call void @c()
3358 ; CHECK-NEXT: call i32 @c()
30073359 ; CHECK-NEXT: br label %c.latch
30083360
30093361 c.latch:
30653417 ; CHECK-NEXT: br label %[[C_HEADER_US:.*]]
30663418 ;
30673419 ; CHECK: [[C_HEADER_US]]:
3068 ; CHECK-NEXT: call void @c()
3420 ; CHECK-NEXT: call i32 @c()
30693421 ; CHECK-NEXT: br label %[[B_LATCH_US:.*]]
30703422 ;
30713423 ; CHECK: [[B_LATCH_US]]:
30763428 ; CHECK-NEXT: br label %c.header
30773429
30783430 c.header:
3079 call void @c()
3431 call i32 @c()
30803432 br i1 %v1, label %b.latch, label %c.latch
30813433 ; CHECK: c.header:
3082 ; CHECK-NEXT: call void @c()
3434 ; CHECK-NEXT: call i32 @c()
30833435 ; CHECK-NEXT: br label %c.latch
30843436
30853437 c.latch:
31533505 ; CHECK-NEXT: br label %[[C_HEADER_US:.*]]
31543506 ;
31553507 ; CHECK: [[C_HEADER_US]]:
3156 ; CHECK-NEXT: call void @c()
3508 ; CHECK-NEXT: call i32 @c()
31573509 ; CHECK-NEXT: br label %[[B_LATCH_US:.*]]
31583510 ;
31593511 ; CHECK: [[B_LATCH_US]]:
31653517 ; CHECK-NEXT: br label %c.header
31663518
31673519 c.header:
3168 call void @c()
3520 call i32 @c()
31693521 br i1 %v1, label %b.latch, label %c.latch
31703522 ; CHECK: c.header:
3171 ; CHECK-NEXT: call void @c()
3523 ; CHECK-NEXT: call i32 @c()
31723524 ; CHECK-NEXT: br label %c.latch
31733525
31743526 c.latch:
32333585 ; CHECK-NEXT: br label %[[C_HEADER_US:.*]]
32343586 ;
32353587 ; CHECK: [[C_HEADER_US]]:
3236 ; CHECK-NEXT: call void @c()
3588 ; CHECK-NEXT: call i32 @c()
32373589 ; CHECK-NEXT: br label %[[B_LATCH_US:.*]]
32383590 ;
32393591 ; CHECK: [[B_LATCH_US]]:
32453597 ; CHECK-NEXT: br label %c.header
32463598
32473599 c.header:
3248 call void @c()
3600 call i32 @c()
32493601 br i1 %v1, label %b.latch, label %c.body
32503602 ; CHECK: c.header:
3251 ; CHECK-NEXT: call void @c()
3603 ; CHECK-NEXT: call i32 @c()
32523604 ; CHECK-NEXT: br label %c.body
32533605
32543606 c.body:
33313683 ; CHECK-NEXT: br label %[[D_HEADER_US:.*]]
33323684 ;
33333685 ; CHECK: [[D_HEADER_US]]:
3334 ; CHECK-NEXT: call void @d()
3686 ; CHECK-NEXT: call i32 @d()
33353687 ; CHECK-NEXT: br label %[[C_LATCH_US:.*]]
33363688 ;
33373689 ; CHECK: [[C_LATCH_US]]:
33413693 ; CHECK-NEXT: br label %d.header
33423694
33433695 d.header:
3344 call void @d()
3696 call i32 @d()
33453697 br i1 %v1, label %c.latch, label %d.exiting1
33463698 ; CHECK: d.header:
3347 ; CHECK-NEXT: call void @d()
3699 ; CHECK-NEXT: call i32 @d()
33483700 ; CHECK-NEXT: br label %d.exiting1
33493701
33503702 d.exiting1:
34443796 ; CHECK-NEXT: br label %[[D_HEADER_US:.*]]
34453797 ;
34463798 ; CHECK: [[D_HEADER_US]]:
3447 ; CHECK-NEXT: call void @d()
3799 ; CHECK-NEXT: call i32 @d()
34483800 ; CHECK-NEXT: br label %[[C_LATCH_US:.*]]
34493801 ;
34503802 ; CHECK: [[C_LATCH_US]]:
34563808 ; CHECK-NEXT: br label %d.header
34573809
34583810 d.header:
3459 call void @d()
3811 call i32 @d()
34603812 br i1 %v1, label %c.latch, label %d.latch
34613813 ; CHECK: d.header:
3462 ; CHECK-NEXT: call void @d()
3814 ; CHECK-NEXT: call i32 @d()
34633815 ; CHECK-NEXT: br label %d.latch
34643816
34653817 d.latch:
35303882 ; CHECK-NEXT: br label %[[C_HEADER_US:.*]]
35313883 ;
35323884 ; CHECK: [[C_HEADER_US]]:
3533 ; CHECK-NEXT: call void @c()
3885 ; CHECK-NEXT: call i32 @c()
35343886 ; CHECK-NEXT: br label %[[B_LATCH_US:.*]]
35353887 ;
35363888 ; CHECK: [[B_LATCH_US]]:
35423894 ; CHECK-NEXT: br label %c.header
35433895
35443896 c.header:
3545 call void @c()
3897 call i32 @c()
35463898 switch i32 %v1, label %c.latch [
35473899 i32 1, label %b.latch
35483900 i32 2, label %b.latch
35493901 i32 3, label %b.latch
35503902 ]
35513903 ; CHECK: c.header:
3552 ; CHECK-NEXT: call void @c()
3904 ; CHECK-NEXT: call i32 @c()
35533905 ; CHECK-NEXT: br label %c.latch
35543906
35553907 c.latch: