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

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 22 20:14:49 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Avhi (AvhiMaz)

<details>
<summary>Changes</summary>

`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


---
Full diff: https://github.com/llvm/llvm-project/pull/205244.diff


2 Files Affected:

- (modified) llvm/lib/Transforms/Utils/FixIrreducible.cpp (+3-2) 
- (added) llvm/test/Transforms/FixIrreducible/unsupported-terminator.ll (+19) 


``````````diff
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
+}

``````````

</details>


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


More information about the llvm-commits mailing list