[all-commits] [llvm/llvm-project] 9d2e7e: [FixIrreducible][UnifyLoopExits] Support switch st...

Lukas via All-commits all-commits at lists.llvm.org
Sun Jul 19 23:40:05 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9d2e7e6836beadbe63380f64c716df2c086ff2ea
      https://github.com/llvm/llvm-project/commit/9d2e7e6836beadbe63380f64c716df2c086ff2ea
  Author: Lukas <43409484+hertelukas at users.noreply.github.com>
  Date:   2026-07-20 (Mon, 20 Jul 2026)

  Changed paths:
    M llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
    M llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
    M llvm/lib/Transforms/Utils/FixIrreducible.cpp
    M llvm/lib/Transforms/Utils/UnifyLoopExits.cpp
    M llvm/test/Transforms/FixIrreducible/bug45623.ll
    M llvm/test/Transforms/FixIrreducible/multiedge.ll
    M llvm/test/Transforms/FixIrreducible/nested.ll
    M llvm/test/Transforms/FixIrreducible/switch.ll
    M llvm/test/Transforms/FixIrreducible/unreachable.ll
    M llvm/test/Transforms/FixIrreducible/unsupported-terminator.ll
    M llvm/test/Transforms/UnifyLoopExits/basic.ll
    M llvm/test/Transforms/UnifyLoopExits/integer_guards.ll
    M llvm/test/Transforms/UnifyLoopExits/multiedge.ll
    M llvm/test/Transforms/UnifyLoopExits/nested.ll
    M llvm/test/Transforms/UnifyLoopExits/restore-ssa.ll
    M llvm/test/Transforms/UnifyLoopExits/switch.ll
    M llvm/test/Transforms/UnifyLoopExits/undef-phis.ll

  Log Message:
  -----------
  [FixIrreducible][UnifyLoopExits] Support switch statements (#206567)

This builds on #149308, which implemented `callbr` support.

The same approach of splitting multi-branch edges entering irreducible
loops can be used for switches. It does not introduce any new switch
statements, but alleviates the requirement of having to run the
`LowerSwitch` pass first. This makes the pass usable for users other
than AMDGPU, which can handle switch statements (e.g., WebAssembly, see
[here](https://github.com/llvm/llvm-project/pull/181755#issuecomment-3936316307)).

I'm also implementing a flag into the `ControlFlowHub` to support
switches as well, for which I will open a separate PR. Currently the
`ControlFlowHub` creates a branch-sled, mimicking a `switch` (a series
of blocks consisting only of conditional branches, selectively entering
an irreducible loop at a certain point or continuing to the next
potential entry point). If the target can support switches, that should
be the clear goal here, as shown in the image below. This PR implements
the step from (a) to (b), whereas extending the `ControlFlowHub`
represents the step from (b) to (c). ((c) to (d) already exists through
`SwitchToLookup` and `SwitchToArithmetic`).

<img width="1055" height="432" alt="image"
src="https://github.com/user-attachments/assets/780b7894-1895-4137-8148-b2bbc7f73a8f"
/>

The test cases in `switch.ll` were adapted from the `callbr.ll` tests
using an LLM to ensure equivalent coverage. I've manually reviewed the
control flow and conditions for every case, and the final assertions
were generated using `update_test_checks.py`.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list