llvm.org GIT mirror llvm / 92be720
[LoopSimplify] Preserve LCSSA when merging exit blocks. Summary: This fixes PR26682. Also add LCSSA as a preserved pass to LoopSimplify, that looks correct to me and allows to write a test for the issue. Reviewers: chandlerc, bogner, sanjoy Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D21112 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@272224 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Zolotukhin 3 years ago
2 changed file(s) with 53 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
685685 }
686686 DT->eraseNode(ExitingBlock);
687687
688 BI->getSuccessor(0)->removePredecessor(ExitingBlock);
689 BI->getSuccessor(1)->removePredecessor(ExitingBlock);
688 BI->getSuccessor(0)->removePredecessor(
689 ExitingBlock, /* DontDeleteUselessPHIs */ PreserveLCSSA);
690 BI->getSuccessor(1)->removePredecessor(
691 ExitingBlock, /* DontDeleteUselessPHIs */ PreserveLCSSA);
690692 ExitingBlock->eraseFromParent();
691693 }
692694 }
747749 AU.addPreserved();
748750 AU.addPreserved();
749751 AU.addPreserved();
752 AU.addPreservedID(LCSSAID);
750753 AU.addPreserved();
751754 AU.addPreservedID(BreakCriticalEdgesID); // No critical edges added.
752755 }
780783 SE = SEWP ? &SEWP->getSE() : nullptr;
781784 AC = &getAnalysis().getAssumptionCache(F);
782785 bool PreserveLCSSA = mustPreserveAnalysisID(LCSSAID);
786 #ifndef NDEBUG
787 if (PreserveLCSSA) {
788 assert(DT && "DT not available.");
789 assert(LI && "LI not available.");
790 bool InLCSSA =
791 all_of(*LI, [&](Loop *L) { return L->isRecursivelyLCSSAForm(*DT); });
792 assert(InLCSSA && "Requested to preserve LCSSA, but it's already broken.");
793 }
794 #endif
783795
784796 // Simplify each loop nest in the function.
785797 for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I)
786798 Changed |= simplifyLoop(*I, DT, LI, SE, AC, PreserveLCSSA);
787799
800 #ifndef NDEBUG
801 if (PreserveLCSSA) {
802 bool InLCSSA =
803 all_of(*LI, [&](Loop *L) { return L->isRecursivelyLCSSAForm(*DT); });
804 assert(InLCSSA && "LCSSA is broken after loop-simplify.");
805 }
806 #endif
788807 return Changed;
789808 }
790809
0 ; RUN: opt < %s -lcssa -loop-simplify -indvars -S | FileCheck %s
1 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
2 target triple = "x86_64-unknown-unknown"
3
4 @a = external global i32, align 4
5
6 ; Check that loop-simplify merges two loop exits, but preserves LCSSA form.
7 ; CHECK-LABEL: @foo
8 ; CHECK: for:
9 ; CHECK: %or.cond = and i1 %cmp1, %cmp2
10 ; CHECK-NOT: for.cond:
11 ; CHECK: for.end:
12 ; CHECK: %a.lcssa = phi i32 [ %a, %for ]
13 define i32 @foo(i32 %x) {
14 entry:
15 br label %for
16
17 for:
18 %iv = phi i32 [ 0, %entry ], [ %iv.next, %for.cond ]
19 %cmp1 = icmp eq i32 %x, 0
20 %iv.next = add nuw nsw i32 %iv, 1
21 %a = load i32, i32* @a
22 br i1 %cmp1, label %for.cond, label %for.end
23
24 for.cond:
25 %cmp2 = icmp slt i32 %iv.next, 4
26 br i1 %cmp2, label %for, label %for.end
27
28 for.end:
29 %a.lcssa = phi i32 [ %a, %for ], [ %a, %for.cond ]
30 ret i32 %a.lcssa
31 }