[llvm] [WebAssembly] Allow use of the common FixIrreducible pass (PR #182384)

Derek Schuff via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 19 14:03:00 PST 2026


https://github.com/dschuff created https://github.com/llvm/llvm-project/pull/182384

This allows experimentation with the common FixIrreducible pass instead of the
existing WebAssemblyFixIrreducibleControlFlow pass (and may allow trying other
options before we converge on a single one).
Repurpose the existing CL debug flag which previously allowed disabling the pass
entirely.


>From ee3a01fb53c25738edc10bf7fb0c47e3f92a406c Mon Sep 17 00:00:00 2001
From: Derek Schuff <dschuff at chromium.org>
Date: Thu, 19 Feb 2026 21:59:42 +0000
Subject: [PATCH] [WebAssembly] Allow use of the common FixIrreducible pass

This allows experimentation with the common FixIrreducible pass instead of the
existing WebAssemblyFixIrreducibleControlFlow pass (and may allow trying other
options before we converge on a single one).
Repurpose the existing CL debug flag which previously allowed disabling the pass
entirely.
---
 .../WebAssembly/WebAssemblyTargetMachine.cpp   | 18 +++++++++++-------
 llvm/lib/Transforms/Utils/FixIrreducible.cpp   |  1 +
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index ab1b24a4fd9b1..1cfaaa4e11474 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -51,11 +51,11 @@ static cl::opt<bool> WasmDisableExplicitLocals(
              " instruction output for test purposes only."),
     cl::init(false));
 
-static cl::opt<bool> WasmDisableFixIrreducibleControlFlowPass(
-    "wasm-disable-fix-irreducible-control-flow-pass", cl::Hidden,
-    cl::desc("webassembly: disables the fix "
-             " irreducible control flow optimization pass"),
-    cl::init(false));
+static cl::opt<int> WasmTestFixIrreduciblePass(
+    "wasm-test-fix-irreducible-pass", cl::Hidden,
+    cl::desc("webassembly: use WebAssemblyFixIrreducibleControlFlow (0),"
+             "the common FixIrreducible pass (1), or nothing (2)"),
+    cl::init(0));
 
 // Exception handling & setjmp-longjmp handling related options.
 
@@ -604,8 +604,10 @@ void WebAssemblyPassConfig::addPreEmitPass() {
   // Nullify DBG_VALUE_LISTs that we cannot handle.
   addPass(createWebAssemblyNullifyDebugValueLists());
 
-  // Eliminate multiple-entry loops.
-  if (!WasmDisableFixIrreducibleControlFlowPass)
+  // If this value is 1, we used an IR pass above. Otherwise,
+  // on't fix irreducible control flow. This will cause compiler crashes
+  // which is only useful for identifying programs that need fixing.
+  if (WasmTestFixIrreduciblePass == 0)
     addPass(createWebAssemblyFixIrreducibleControlFlow());
 
   // Do various transformations for exception handling.
@@ -673,6 +675,8 @@ void WebAssemblyPassConfig::addPreEmitPass() {
 bool WebAssemblyPassConfig::addPreISel() {
   TargetPassConfig::addPreISel();
   addPass(createWebAssemblyLowerRefTypesIntPtrConv());
+  if (WasmTestFixIrreduciblePass == 1)
+    addPass(createFixIrreduciblePass());
   return false;
 }
 
diff --git a/llvm/lib/Transforms/Utils/FixIrreducible.cpp b/llvm/lib/Transforms/Utils/FixIrreducible.cpp
index 804af22daa5af..9cf29450ef186 100644
--- a/llvm/lib/Transforms/Utils/FixIrreducible.cpp
+++ b/llvm/lib/Transforms/Utils/FixIrreducible.cpp
@@ -169,6 +169,7 @@ INITIALIZE_PASS_BEGIN(FixIrreducible, "fix-irreducible",
                       "Convert irreducible control-flow into natural loops",
                       false /* Only looks at CFG */, false /* Analysis Pass */)
 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
+INITIALIZE_PASS_DEPENDENCY(CycleInfoWrapperPass)
 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
 INITIALIZE_PASS_END(FixIrreducible, "fix-irreducible",
                     "Convert irreducible control-flow into natural loops",



More information about the llvm-commits mailing list