[llvm] d46d968 - [BBUtils] Don't add 'then' block to a loop if it's terminated with unreachable
Dmitry Makogon via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 19 06:26:02 PDT 2023
Author: Dmitry Makogon
Date: 2023-06-19T20:24:30+07:00
New Revision: d46d9689f7c3fe16010cd07761858a6392239b3f
URL: https://github.com/llvm/llvm-project/commit/d46d9689f7c3fe16010cd07761858a6392239b3f
DIFF: https://github.com/llvm/llvm-project/commit/d46d9689f7c3fe16010cd07761858a6392239b3f.diff
LOG: [BBUtils] Don't add 'then' block to a loop if it's terminated with unreachable
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
Added:
Modified:
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/test/Transforms/SimpleLoopUnswitch/guards.ll
llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 4b93b624c2eb0..68ff16f70a5d5 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -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);
}
}
diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/guards.ll b/llvm/test/Transforms/SimpleLoopUnswitch/guards.ll
index 52580382d1d55..07668616ff86d 100644
--- a/llvm/test/Transforms/SimpleLoopUnswitch/guards.ll
+++ b/llvm/test/Transforms/SimpleLoopUnswitch/guards.ll
@@ -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) {
diff --git a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll
index e7bf39dd74e42..543ee092e810c 100644
--- a/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll
+++ b/llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll
@@ -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:
More information about the llvm-commits
mailing list