[LoopSimplifyCFG] Pay respect to LCSSA when removing dead blocks

Utility function that we use for blocks deletion always unconditionally removes
one-input Phis. In LoopSimplifyCFG, it can lead to breach of LCSSA form.
This patch alters this function to keep them if needed.

Differential Revision: https://reviews.llvm.org/D57231
Reviewed By: fedor.sergeev

llvm-svn: 353803
This commit is contained in:
Max Kazantsev 2019-02-12 07:48:07 +00:00
parent 4390c721cb
commit 6bf861597c
2 changed files with 30 additions and 9 deletions

View File

@ -418,7 +418,7 @@ private:
LI.removeBlock(BB); LI.removeBlock(BB);
} }
DetatchDeadBlocks(DeadLoopBlocks, &DTUpdates); DetatchDeadBlocks(DeadLoopBlocks, &DTUpdates, /*KeepOneInputPHIs*/true);
DTU.applyUpdates(DTUpdates); DTU.applyUpdates(DTUpdates);
DTUpdates.clear(); DTUpdates.clear();
for (auto *BB : DeadLoopBlocks) for (auto *BB : DeadLoopBlocks)

View File

@ -1,6 +1,4 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; XFAIL: *
; REQUIRES: asserts
; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s ; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s
; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -passes='require<domtree>,loop(simplify-cfg)' -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s ; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -passes='require<domtree>,loop(simplify-cfg)' -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s
; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -enable-mssa-loop-dependency=true -verify-memoryssa -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s ; RUN: opt -S -enable-loop-simplifycfg-term-folding=true -loop-simplifycfg -enable-mssa-loop-dependency=true -verify-memoryssa -verify-loop-info -verify-dom-info -verify-loop-lcssa < %s | FileCheck %s
@ -93,8 +91,31 @@ while.body: ; preds = %while.cond
} }
define void @bar() { define void @bar() {
; CHECK-LABEL: @bar(
; CHECK-LABEL: @bar ; CHECK-NEXT: bb:
; CHECK-NEXT: switch i32 0, label [[BB_SPLIT:%.*]] [
; CHECK-NEXT: i32 1, label [[BB10:%.*]]
; CHECK-NEXT: ]
; CHECK: bb-split:
; CHECK-NEXT: br label [[BB1:%.*]]
; CHECK: bb1:
; CHECK-NEXT: [[TMP:%.*]] = phi i32 [ [[TMP7:%.*]], [[BB6:%.*]] ], [ undef, [[BB_SPLIT]] ]
; CHECK-NEXT: switch i32 undef, label [[BB5:%.*]] [
; CHECK-NEXT: i32 0, label [[BB6]]
; CHECK-NEXT: i32 1, label [[BB8:%.*]]
; CHECK-NEXT: ]
; CHECK: bb5:
; CHECK-NEXT: ret void
; CHECK: bb6:
; CHECK-NEXT: [[TMP7]] = add i32 undef, 123
; CHECK-NEXT: br label [[BB1]]
; CHECK: bb8:
; CHECK-NEXT: [[TMP9:%.*]] = phi i32 [ [[TMP]], [[BB1]] ]
; CHECK-NEXT: [[USE:%.*]] = add i32 [[TMP9]], 1
; CHECK-NEXT: ret void
; CHECK: bb10:
; CHECK-NEXT: ret void
;
bb: bb:
br label %bb1 br label %bb1