[PATCH] D152434: [BBUtils] Don't add 'then' block to a loop if it's terminated with unreachable

Dmitry Makogon via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 8 05:04:37 PDT 2023


dmakogon created this revision.
dmakogon added reviewers: nikic, fhahn, apilipenko.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
dmakogon requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

`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.


https://reviews.llvm.org/D152434

Files:
  llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
  llvm/test/Transforms/SimpleLoopUnswitch/guards.ll
  llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll


Index: llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll
===================================================================
--- llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll
+++ llvm/test/Transforms/SimpleLoopUnswitch/nontrivial-unswitch-skip-selects-in-guards.ll
@@ -7,9 +7,6 @@
 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:
Index: llvm/test/Transforms/SimpleLoopUnswitch/guards.ll
===================================================================
--- llvm/test/Transforms/SimpleLoopUnswitch/guards.ll
+++ 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 -S < %s | FileCheck %s
 
-; XFAIL: *
-; REQUIRES: asserts
-
 declare void @llvm.experimental.guard(i1, ...)
 
 define void @test_simple_case(i1 %cond, i32 %N) {
Index: llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1518,7 +1518,9 @@
 
   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);
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152434.529559.patch
Type: text/x-patch
Size: 1773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230608/6f3049a4/attachment.bin>


More information about the llvm-commits mailing list