[all-commits] [llvm/llvm-project] 5a5d0f: [SimpleLoopUnswitch] Generalize the notion of triv...

Ehsan Amiri via All-commits all-commits at lists.llvm.org
Wed Jun 17 09:11:58 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5a5d0fb1e471b3a1e842aee1f993e885c8d19713
      https://github.com/llvm/llvm-project/commit/5a5d0fb1e471b3a1e842aee1f993e885c8d19713
  Author: Ehsan Amiri <ehsan.amiri at huawei.com>
  Date:   2026-06-17 (Wed, 17 Jun 2026)

  Changed paths:
    M llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
    M llvm/test/Transforms/PhaseOrdering/AArch64/loopflatten.ll
    M llvm/test/Transforms/PhaseOrdering/AArch64/matrix-extract-insert.ll
    M llvm/test/Transforms/PhaseOrdering/X86/hoist-load-of-baseptr.ll
    M llvm/test/Transforms/PhaseOrdering/unswitch-cold-func.ll
    A llvm/test/Transforms/PhaseOrdering/unswitch-nontrivial-cold-func.ll
    M llvm/test/Transforms/SimpleLoopUnswitch/AMDGPU/uniform-unswitch.ll
    M llvm/test/Transforms/SimpleLoopUnswitch/PGO-nontrivial-unswitch2.ll
    M llvm/test/Transforms/SimpleLoopUnswitch/PGO-nontrivial-unswitch3.ll
    A llvm/test/Transforms/SimpleLoopUnswitch/trivial-unswitch-loop-guard.ll
    M polly/test/Support/pipelineposition.ll

  Log Message:
  -----------
  [SimpleLoopUnswitch] Generalize the notion of trivial unswitching (#193989)

For a loop like this 

```
     for (int j = 0; j < M; j++) {
       if (N <= 0) continue;          // invariant guard branches to latch
       for (int i = 0; i < N; i++)
         A[i] = B[i] + 1;
     }
```
Since none of the successors of the guard branch of the inner loop are
outside the loop `j`, unswitching treats this as a non-trivial branch.
In reality, this is a perfect loop nest. If the condition of the guard
of `i` loop is false, there is nothing to do and so if we unswitch this
branch, the loop does not need to be versioned. This matches the
requirements of a trivial unswitch. This patch extends trivial loop
unswitching to catch cases like this.

The patch changes the loop guard so that instead of branching to the
latch of the outer loop, it exits the loop. This allows the existing code
for trivial unswitching to perform the transformation. The change in the
loop guard will happen only if all conditions for unswitching are met.



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