Skip to content

[FixIrreducible] Use reportFatalUsageError for unsupported terminators - #205244

Merged
ro-i merged 1 commit into
llvm:mainfrom
AvhiMaz:fix/irreducible-unsupported-terminator
Jun 23, 2026
Merged

ro-i merged 1 commit into
llvm:mainfrom
AvhiMaz:fix/irreducible-unsupported-terminator

Conversation

@AvhiMaz

@AvhiMaz AvhiMaz commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown

Hello @AvhiMaz 👋

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

  • All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
  • The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.
  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.


Frequently asked questions

How do I add reviewers?

This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

What if there are no comments?

If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

Are any special GitHub settings required to contribute to LLVM?

We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.


If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

Thank you,
The LLVM Community

@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-llvm-transforms

Author: Avhi (AvhiMaz)

Changes

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

@AvhiMaz

AvhiMaz commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Hello @AvhiMaz 👋

Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.

  • All contributions to LLVM must follow our LLVM AI Tool Use Policy. In particular, if you used AI while working on this PR, remember to add a note to the PR description.
  • The LLVM Code-Review Policy and Practices document contains practical information about the PR process, including how patches are reviewed and accepted, and who can review a PR.
  • Our LLVM Developer Policy describes our expectations for code quality, commit summaries and contains notes on our CI system.

Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description.

Frequently asked questions

How do I add reviewers?

This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically.

You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using @ followed by their GitHub username.

What if there are no comments?

If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers.

Are any special GitHub settings required to contribute to LLVM?

We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details.

If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse.

Thank you, The LLVM Community

Confirming I've read the contribution and AI Tool Use policies.

@AvhiMaz
AvhiMaz force-pushed the fix/irreducible-unsupported-terminator branch from a173c0e to 1be321d Compare June 23, 2026 06:39
@AvhiMaz
AvhiMaz force-pushed the fix/irreducible-unsupported-terminator branch from 1be321d to e810244 Compare June 23, 2026 06:41
@AvhiMaz
AvhiMaz requested a review from pektezol June 23, 2026 06:42

@pektezol pektezol left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I don't have commit access, so this requires an approval from a maintaner.

@AvhiMaz

AvhiMaz commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

LGTM

I don't have commit access, so this requires an approval from a maintaner.

Thanks for the review! Let's wait for a maintainer's approval. If you're allowed to, could you tag a maintainer? That would probably help.

@pektezol

Copy link
Copy Markdown
Contributor

You are allowed to as well :) People from the issue discussion if it exists, or recent commiters to the specific pass are the people to ask. Make sure not to ping too frequently and/or too many people.

Request for review, should be a simple one, I did a first pass of review: @ro-i

@ro-i ro-i left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@ro-i
ro-i enabled auto-merge (squash) June 23, 2026 08:37
@ro-i
ro-i merged commit 8289d98 into llvm:main Jun 23, 2026
8 of 9 checks passed
@github-actions

Copy link
Copy Markdown

@AvhiMaz Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@AvhiMaz
AvhiMaz deleted the fix/irreducible-unsupported-terminator branch June 23, 2026 09:24
beamandala pushed a commit to beamandala/llvm-project that referenced this pull request Jun 24, 2026
llvm#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 llvm#191978

Signed-off-by: AvhiMaz <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[opt] -passes='fix-irreducible' reaches UNREACHABLE

3 participants