Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 31f80a2

Browse files
author
Michael Zolotukhin
committed
[LoopSimplify] When simplifying phis in loop-simplify, do it only if it preserves LCSSA form.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@282541 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit 835827e)
1 parent 757d062 commit 31f80a2

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

lib/Transforms/Utils/LoopSimplify.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,10 @@ static bool simplifyOneLoop(Loop *L, SmallVectorImpl<Loop *> &Worklist,
622622
(PN = dyn_cast<PHINode>(I++)); )
623623
if (Value *V = SimplifyInstruction(PN, DL, nullptr, DT, AC)) {
624624
if (SE) SE->forgetValue(PN);
625-
PN->replaceAllUsesWith(V);
626-
PN->eraseFromParent();
625+
if (!PreserveLCSSA || LI->replacementPreservesLCSSAForm(PN, V)) {
626+
PN->replaceAllUsesWith(V);
627+
PN->eraseFromParent();
628+
}
627629
}
628630

629631
// If this loop has multiple exits and the exits all go to the same

test/Transforms/LoopUnroll/rebuild_lcssa.ll

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,40 @@ L1_latch:
151151
exit:
152152
ret i8 0
153153
}
154+
155+
; CHECK-LABEL: @foo5
156+
define void @foo5() {
157+
entry:
158+
br label %outer
159+
160+
outer:
161+
br label %inner1
162+
163+
; CHECK: inner1:
164+
; CHECK-NOT: br i1 true
165+
; CHECK: br label %inner2_indirect_exit
166+
inner1:
167+
br i1 true, label %inner2_indirect_exit.preheader, label %inner1
168+
169+
inner2_indirect_exit.preheader:
170+
br label %inner2_indirect_exit
171+
172+
inner2_indirect_exit:
173+
%a = phi i32 [ %b, %inner2_latch ], [ undef, %inner2_indirect_exit.preheader ]
174+
indirectbr i8* undef, [label %inner2_latch, label %inner3, label %outer_latch]
175+
176+
inner2_latch:
177+
%b = load i32, i32* undef, align 8
178+
br label %inner2_indirect_exit
179+
180+
inner3:
181+
%a.lcssa = phi i32 [ %a.lcssa, %inner3 ], [ %a, %inner2_indirect_exit ]
182+
br i1 true, label %outer_latch.loopexit, label %inner3
183+
184+
outer_latch.loopexit:
185+
%a.lcssa.lcssa = phi i32 [ %a.lcssa, %inner3 ]
186+
br label %outer_latch
187+
188+
outer_latch:
189+
br label %outer
190+
}

0 commit comments

Comments
 (0)