Skip to content

Commit

Permalink
[BBUtils] Don't add 'then' block to a loop if it's terminated with un…
Browse files Browse the repository at this point in the history
…reachable

SplitBlockAndInsertIfThen utility creates two new blocks,
they're called ThenBlock and Tail (true and false destinations of a conditional
branch correspondingly). The function has a bool parameter Unreachable,
and if it's set, then ThenBlock is terminated with an unreachable.
At the end of the function the new blocks are added to the loop of the split
block. However, in case ThenBlock is terminated with an unreachable,
it cannot belong to any loop.

Differential Revision: https://reviews.llvm.org/D152434
  • Loading branch information
d-makogon committed Jun 19, 2023
1 parent 9d4c1be commit d46d968
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 7 deletions.
4 changes: 3 additions & 1 deletion llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,9 @@ Instruction *llvm::SplitBlockAndInsertIfThen(Value *Cond,

if (LI) {
if (Loop *L = LI->getLoopFor(Head)) {
L->addBasicBlockToLoop(ThenBlock, *LI);
// unreachable-terminated blocks cannot belong to any loop.
if (!Unreachable)
L->addBasicBlockToLoop(ThenBlock, *LI);
L->addBasicBlockToLoop(Tail, *LI);
}
}
Expand Down
3 changes: 0 additions & 3 deletions llvm/test/Transforms/SimpleLoopUnswitch/guards.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
; RUN: opt -passes='simple-loop-unswitch<nontrivial>' -simple-loop-unswitch-guards -S < %s | FileCheck %s
; RUN: opt -passes='loop-mssa(simple-loop-unswitch<nontrivial>),verify<loops>' -simple-loop-unswitch-guards -verify-memoryssa -verify-loop-info -S < %s | FileCheck %s

; XFAIL: *
; REQUIRES: asserts

declare void @llvm.experimental.guard(i1, ...)

define void @test_simple_case(i1 %cond, i32 %N) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ declare ptr @pluto()
declare void @llvm.experimental.guard(i1, ...)
declare void @widget()

; XFAIL: *
; REQUIRES: asserts

define void @foo(ptr addrspace(1) %arg, i64 %arg1) personality ptr @pluto {
; CHECK-LABEL: @foo(
; CHECK-NEXT: bb:
Expand Down

0 comments on commit d46d968

Please sign in to comment.