[LoopSimplify] When simplifying phis in loop-simplify, do it only if it preserves LCSSA form.

llvm-svn: 282541
This commit is contained in:
Michael Zolotukhin 2016-09-27 21:03:45 +00:00
parent 699fc5b191
commit 1a554be3b6
2 changed files with 41 additions and 2 deletions

View File

@ -622,8 +622,10 @@ ReprocessLoop:
(PN = dyn_cast<PHINode>(I++)); )
if (Value *V = SimplifyInstruction(PN, DL, nullptr, DT, AC)) {
if (SE) SE->forgetValue(PN);
PN->replaceAllUsesWith(V);
PN->eraseFromParent();
if (!PreserveLCSSA || LI->replacementPreservesLCSSAForm(PN, V)) {
PN->replaceAllUsesWith(V);
PN->eraseFromParent();
}
}
// If this loop has multiple exits and the exits all go to the same

View File

@ -151,3 +151,40 @@ L1_latch:
exit:
ret i8 0
}
; CHECK-LABEL: @foo5
define void @foo5() {
entry:
br label %outer
outer:
br label %inner1
; CHECK: inner1:
; CHECK-NOT: br i1 true
; CHECK: br label %inner2_indirect_exit
inner1:
br i1 true, label %inner2_indirect_exit.preheader, label %inner1
inner2_indirect_exit.preheader:
br label %inner2_indirect_exit
inner2_indirect_exit:
%a = phi i32 [ %b, %inner2_latch ], [ undef, %inner2_indirect_exit.preheader ]
indirectbr i8* undef, [label %inner2_latch, label %inner3, label %outer_latch]
inner2_latch:
%b = load i32, i32* undef, align 8
br label %inner2_indirect_exit
inner3:
%a.lcssa = phi i32 [ %a.lcssa, %inner3 ], [ %a, %inner2_indirect_exit ]
br i1 true, label %outer_latch.loopexit, label %inner3
outer_latch.loopexit:
%a.lcssa.lcssa = phi i32 [ %a.lcssa, %inner3 ]
br label %outer_latch
outer_latch:
br label %outer
}