Skip to content

Commit

Permalink
[InstCombine] Instruction sinking: fix check for function terminating…
Browse files Browse the repository at this point in the history
… block

Checking for specific function terminating opcodes
means we don't handle other non-hardcoded ones :)

This should probably be generalized to something
similar to the `IsBlockFollowedByDeoptOrUnreachable()`.

Reviewed By: spatel

Differential Revision: https://reviews.llvm.org/D117810
  • Loading branch information
LebedevRI committed Jan 20, 2022
1 parent 63a991d commit ba8eb31
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Expand Up @@ -3966,12 +3966,11 @@ bool InstCombinerImpl::run() {
// predecessor, so that we don't have to split the critical edge.
// Another option where we can sink is a block that ends with a
// terminator that does not pass control to other block (such as
// return or unreachable). In this case:
// return or unreachable or resume). In this case:
// - I dominates the User (by SSA form);
// - the User will be executed at most once.
// So sinking I down to User is always profitable or neutral.
if (UserParent->getUniquePredecessor() == BB ||
(isa<ReturnInst>(Term) || isa<UnreachableInst>(Term))) {
if (UserParent->getUniquePredecessor() == BB || succ_empty(Term)) {
assert(DT.dominates(BB, UserParent) && "Dominance relation broken?");
return UserParent;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/InstCombine/sink-into-resume-block.ll
Expand Up @@ -7,7 +7,6 @@ define void @t0_noop(i32 %arg) personality i8* bitcast (i32 (...)* @__gxx_person
; CHECK-LABEL: @t0_noop(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C:%.*]] = call i1 @cond()
; CHECK-NEXT: [[V0:%.*]] = add i32 [[ARG:%.*]], 42
; CHECK-NEXT: br i1 [[C]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]
; CHECK: if.then:
; CHECK-NEXT: invoke void @simple_throw()
Expand All @@ -17,6 +16,7 @@ define void @t0_noop(i32 %arg) personality i8* bitcast (i32 (...)* @__gxx_person
; CHECK: lpad:
; CHECK-NEXT: [[EH:%.*]] = landingpad { i8*, i32 }
; CHECK-NEXT: cleanup
; CHECK-NEXT: [[V0:%.*]] = add i32 [[ARG:%.*]], 42
; CHECK-NEXT: call void @consume(i32 [[V0]])
; CHECK-NEXT: call void @destructor()
; CHECK-NEXT: resume { i8*, i32 } [[EH]]
Expand Down

0 comments on commit ba8eb31

Please sign in to comment.