[llvm] [FixIrreducible] Use reportFatalUsageError for unsupported terminators (PR #205244)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 22 20:13:58 PDT 2026


https://github.com/AvhiMaz created https://github.com/llvm/llvm-project/pull/205244

`opt -passes=fix-irreducible` crashed via `llvm_unreachable` on a
`switch` terminator incident to an irreducible cycle header. Such
terminators must be lowered first (`lower-switch`); replace the
`llvm_unreachable` at both sites with `reportFatalUsageError` so the
pass fails gracefully instead of crashing.

Fixes #191978


>From a173c0ebf2f15b56f1d6948a387469a930655ea6 Mon Sep 17 00:00:00 2001
From: AvhiMaz <avhimazumder5 at outlook.com>
Date: Tue, 23 Jun 2026 08:10:07 +0530
Subject: [PATCH] [FixIrreducible] Use reportFatalUsageError for unsupported
 terminators

Signed-off-by: AvhiMaz <avhimazumder5 at outlook.com>
---
 llvm/lib/Transforms/Utils/FixIrreducible.cpp  |  5 +++--
 .../FixIrreducible/unsupported-terminator.ll  | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/Transforms/FixIrreducible/unsupported-terminator.ll

diff --git a/llvm/lib/Transforms/Utils/FixIrreducible.cpp b/llvm/lib/Transforms/Utils/FixIrreducible.cpp
index 8e6425adc2855..2e59787a4adbb 100644
--- a/llvm/lib/Transforms/Utils/FixIrreducible.cpp
+++ b/llvm/lib/Transforms/Utils/FixIrreducible.cpp
@@ -134,6 +134,7 @@
 #include "llvm/Analysis/LoopInfo.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Pass.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
 #include "llvm/Transforms/Utils/ControlFlowUtils.h"
@@ -320,7 +321,7 @@ static bool fixIrreducible(Cycle &C, CycleInfo &CI, DominatorTree &DT,
                           << printBasicBlock(Succ) << '\n');
       }
     } else {
-      llvm_unreachable("unsupported block terminator");
+      reportFatalUsageError("unsupported block terminator");
     }
   }
 
@@ -364,7 +365,7 @@ static bool fixIrreducible(Cycle &C, CycleInfo &CI, DominatorTree &DT,
                           << printBasicBlock(Succ) << '\n');
       }
     } else {
-      llvm_unreachable("unsupported block terminator");
+      reportFatalUsageError("unsupported block terminator");
     }
   }
 
diff --git a/llvm/test/Transforms/FixIrreducible/unsupported-terminator.ll b/llvm/test/Transforms/FixIrreducible/unsupported-terminator.ll
new file mode 100644
index 0000000000000..a572514b7421b
--- /dev/null
+++ b/llvm/test/Transforms/FixIrreducible/unsupported-terminator.ll
@@ -0,0 +1,19 @@
+; RUN: not opt < %s -passes=fix-irreducible -S 2>&1 | FileCheck %s
+; CHECK: unsupported block terminator
+
+define void @loop_1(i32 %Value, i1 %PredEntry) {
+entry:
+  br i1 %PredEntry, label %A, label %B
+
+A:
+  br label %B
+
+B:
+  switch i32 %Value, label %exit [
+    i32 0, label %A
+    i32 1, label %B
+  ]
+
+exit:
+  ret void
+}



More information about the llvm-commits mailing list