Skip to content

Commit

Permalink
[SimplifyCFG] Teach SimplifyCondBranchToTwoReturns() to preserve DomT…
Browse files Browse the repository at this point in the history
…ree, part 1

... for the general case of returning a value.
  • Loading branch information
LebedevRI committed Dec 19, 2020
1 parent 4d87a6a commit b94520c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 5 additions & 0 deletions llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/LoopDeletion/simplify-then-delete.ll
@@ -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
Expand Down
@@ -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]

Expand Down
@@ -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
}

0 comments on commit b94520c

Please sign in to comment.