mirror-llvm-project/polly
Ehsan Amiri 5a5d0fb1e4
[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.
2026-06-17 12:11:37 -04:00
..
ci [Polly] Forward VFS from PassBuilder for IO sandboxing (#188657) 2026-03-28 23:55:05 +01:00
cmake
docs [docs] try again to handle doxygen everywhere (#203081) 2026-06-11 08:58:36 -04:00
include/polly [Polly] Remove unused DenseMapInfo::getEmptyKey (#201992) 2026-06-06 11:18:12 -07:00
lib [polly] Simplify with DenseMap::remove_if. NFC (#199577) 2026-05-25 22:35:48 +00:00
test [SimpleLoopUnswitch] Generalize the notion of trivial unswitching (#193989) 2026-06-17 12:11:37 -04:00
unittests [Polly] Disable PCH reuse for unit tests (#193209) 2026-04-21 12:43:13 +00:00
utils
www
.arclint
.gitattributes
.gitignore
CMakeLists.txt [Polly] Remove Accidental Test Comment in CMakeLists.txt 2025-07-22 21:27:56 +00:00
CREDITS.txt
LICENSE.TXT
Maintainers.md
README

Polly - Polyhedral optimizations for LLVM
-----------------------------------------
http://polly.llvm.org/

Polly uses a mathematical representation, the polyhedral model, to represent and
transform loops and other control flow structures. Using an abstract
representation it is possible to reason about transformations in a more general
way and to use highly optimized linear programming libraries to figure out the
optimal loop structure. These transformations can be used to do constant
propagation through arrays, remove dead loop iterations, optimize loops for
cache locality, optimize arrays, apply advanced automatic parallelization, drive
vectorization, or they can be used to do software pipelining.