[SimplifyCFG] Teach SimplifyCondBranchToTwoReturns() to preserve DomTree, part 1

... for the general case of returning a value.
This commit is contained in:
Roman Lebedev 2020-12-19 19:12:30 +03:00
parent 4d87a6ad13
commit b94520c9ee
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
4 changed files with 28 additions and 2 deletions

View File

@ -2688,6 +2688,11 @@ bool SimplifyCFGOpt::SimplifyCondBranchToTwoReturns(BranchInst *BI,
EraseTerminatorAndDCECond(BI);
if (DTU) {
DTU->applyUpdatesPermissive({{DominatorTree::Delete, BB, TrueSucc},
{DominatorTree::Delete, BB, FalseSucc}});
}
return true;
}

View File

@ -1,4 +1,4 @@
; RUN: opt < %s -S -indvars -loop-deletion -simplifycfg | FileCheck %s
; RUN: opt < %s -S -indvars -loop-deletion -simplifycfg -simplifycfg-require-and-preserve-domtree=1 | FileCheck %s
; PR5794
; Indvars and loop deletion should be able to eliminate all looping

View File

@ -1,4 +1,4 @@
; RUN: opt < %s -simplifycfg -disable-output
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -disable-output
; PR 2777
@g_103 = common global i32 0 ; <i32*> [#uses=1]

View File

@ -0,0 +1,21 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -simplifycfg-dup-ret -S | FileCheck %s
declare void @bar()
declare void @baz()
define i8 @foo(i1 %c, i8 %v0, i8 %v1) {
; CHECK-LABEL: @foo(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[C:%.*]], i8 [[V0:%.*]], i8 [[V1:%.*]]
; CHECK-NEXT: ret i8 [[SPEC_SELECT]]
;
entry:
br i1 %c, label %true, label %false
true:
ret i8 %v0
false:
ret i8 %v1
}