<feed xmlns='http://www.w3.org/2005/Atom'>
<title>llvm-project.git/llvm/lib/Transforms/Scalar/LoopInterchange.cpp, branch main</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.
</subtitle>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/'/>
<entry>
<title>[LoopInterchange] Don't consider loops with BTC=0 (#167113)</title>
<updated>2025-11-19T13:13:35+00:00</updated>
<author>
<name>Sjoerd Meijer</name>
<email>smeijer@nvidia.com</email>
</author>
<published>2025-11-19T13:13:35+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=a2ddb020d76cdb1c5708cf3dadd2c46866202707'/>
<id>a2ddb020d76cdb1c5708cf3dadd2c46866202707</id>
<content type='text'>
Do not consider loops with a zero backedge taken count as candidates for
interchange. This seems like a sensible thing because it suggests the loop
doesn't execute and there is no point in interchanging. As a bonus, this
seems to avoid triggering an assert about phis and their uses from source
code, so this is a partial fix for #163954 but it needs more work to properly
fix that.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Do not consider loops with a zero backedge taken count as candidates for
interchange. This seems like a sensible thing because it suggests the loop
doesn't execute and there is no point in interchanging. As a bonus, this
seems to avoid triggering an assert about phis and their uses from source
code, so this is a partial fix for #163954 but it needs more work to properly
fix that.</pre>
</div>
</content>
</entry>
<entry>
<title>[LoopInterchange] Add simplifyLCSSAPhis: remove phi from non-exit bb  (#160889)</title>
<updated>2025-10-20T09:23:36+00:00</updated>
<author>
<name>Sjoerd Meijer</name>
<email>smeijer@nvidia.com</email>
</author>
<published>2025-10-20T09:23:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=b90a8d385e0d35a2e870aa7b4cf16ee37df10851'/>
<id>b90a8d385e0d35a2e870aa7b4cf16ee37df10851</id>
<content type='text'>
This deals with a corner case of LCSSA phi nodes in the outer loop latch
block: the loop was in LCSSA form, some transformations can come along
(e.g. unswitch) and create an empty block:

     BB4:
       br label %BB5
     BB5:
       %old.cond.lcssa = phi i16 [ %cond, %BB4 ]
       br outer.header

Interchange then brings it in LCSSA form again and we get:

     BB4:
       %new.cond.lcssa = phi i16 [ %cond, %BB3 ]
       br label %BB5
     BB5:
       %old.cond.lcssa = phi i16 [ %new.cond.lcssa, %BB4 ]

Which means that we have a chain of LCSSA phi nodes from %new.cond.lcssa
to %old.cond.lcssa. The problem is that interchange can reoder blocks
BB4 and BB5 placing the use before the def if we don't check this. The
solution is to simplify lcssa phis, and remove them from non-exit blocks
if they are 1-input phi nodes.

Fixes #160068</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This deals with a corner case of LCSSA phi nodes in the outer loop latch
block: the loop was in LCSSA form, some transformations can come along
(e.g. unswitch) and create an empty block:

     BB4:
       br label %BB5
     BB5:
       %old.cond.lcssa = phi i16 [ %cond, %BB4 ]
       br outer.header

Interchange then brings it in LCSSA form again and we get:

     BB4:
       %new.cond.lcssa = phi i16 [ %cond, %BB3 ]
       br label %BB5
     BB5:
       %old.cond.lcssa = phi i16 [ %new.cond.lcssa, %BB4 ]

Which means that we have a chain of LCSSA phi nodes from %new.cond.lcssa
to %old.cond.lcssa. The problem is that interchange can reoder blocks
BB4 and BB5 placing the use before the def if we don't check this. The
solution is to simplify lcssa phis, and remove them from non-exit blocks
if they are 1-input phi nodes.

Fixes #160068</pre>
</div>
</content>
</entry>
<entry>
<title>[LoopInterchange] Bail out when finding a dependency with all `*` elements (#149049)</title>
<updated>2025-09-25T09:37:41+00:00</updated>
<author>
<name>Ryotaro Kasuga</name>
<email>kasuga.ryotaro@fujitsu.com</email>
</author>
<published>2025-09-25T09:37:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=2c3453afd2d28d1a4d802af071c15b8620896ed3'/>
<id>2c3453afd2d28d1a4d802af071c15b8620896ed3</id>
<content type='text'>
If a direction vector with all `*` elements, like `[* * *]`, is present,
it indicates that none of the loop pairs are legal to interchange. In
such cases, continuing the analysis is meaningless.
This patch introduces a check to detect such direction vectors and exits
early when one is found. This slightly reduces compile time.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
If a direction vector with all `*` elements, like `[* * *]`, is present,
it indicates that none of the loop pairs are legal to interchange. In
such cases, continuing the analysis is meaningless.
This patch introduces a check to detect such direction vectors and exits
early when one is found. This slightly reduces compile time.</pre>
</div>
</content>
</entry>
<entry>
<title>[LoopInterchange] Consider forward/backward dependency in vectorize heuristic (#133672)</title>
<updated>2025-07-25T13:37:20+00:00</updated>
<author>
<name>Ryotaro Kasuga</name>
<email>kasuga.ryotaro@fujitsu.com</email>
</author>
<published>2025-07-25T13:37:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=b75530ff034a131da8ca1f05a00f3655c13839ff'/>
<id>b75530ff034a131da8ca1f05a00f3655c13839ff</id>
<content type='text'>
The vectorization heuristic of LoopInterchange attempts to move a
vectorizable loop to the innermost position. Before this patch, a loop
was deemed vectorizable if there are no loop-carried dependencies
induced by the loop.
This patch extends the vectorization heuristic by introducing the
concept of forward and backward dependencies, inspired by
LoopAccessAnalysis. Specifically, an additional element is appended to
each direction vector to indicate whether it represents a forward
dependency (`&lt;`) or not (`*`). Among these, only the forward
dependencies (i.e., those whose last element is `&lt;`) affect the
vectorization heuristic. Accordingly, the check is conservative, and
dependencies are considered forward only when this can be proven.
Currently, we only support perfectly nested loops whose body consists of
a single basic block. For other cases, dependencies are pessimistically
treated as non-forward.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
The vectorization heuristic of LoopInterchange attempts to move a
vectorizable loop to the innermost position. Before this patch, a loop
was deemed vectorizable if there are no loop-carried dependencies
induced by the loop.
This patch extends the vectorization heuristic by introducing the
concept of forward and backward dependencies, inspired by
LoopAccessAnalysis. Specifically, an additional element is appended to
each direction vector to indicate whether it represents a forward
dependency (`&lt;`) or not (`*`). Among these, only the forward
dependencies (i.e., those whose last element is `&lt;`) affect the
vectorization heuristic. Accordingly, the check is conservative, and
dependencies are considered forward only when this can be proven.
Currently, we only support perfectly nested loops whose body consists of
a single basic block. For other cases, dependencies are pessimistically
treated as non-forward.</pre>
</div>
</content>
</entry>
<entry>
<title>[LoopInterchange] Ignore the cost-model, force interchange if legal (#148858)</title>
<updated>2025-07-18T12:42:25+00:00</updated>
<author>
<name>Sjoerd Meijer</name>
<email>smeijer@nvidia.com</email>
</author>
<published>2025-07-18T12:42:25+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=a9f81430725cb3d9a776d9b743078a452cd8e3aa'/>
<id>a9f81430725cb3d9a776d9b743078a452cd8e3aa</id>
<content type='text'>
This is and has been proven useful for testing purposes, to get more
test coverage.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This is and has been proven useful for testing purposes, to get more
test coverage.</pre>
</div>
</content>
</entry>
<entry>
<title>[Scalar] Fix a warning</title>
<updated>2025-07-15T15:00:46+00:00</updated>
<author>
<name>Kazu Hirata</name>
<email>kazu@google.com</email>
</author>
<published>2025-07-15T15:00:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=1c6422c4bdd39b91fee90ce3adeb8404ee92c341'/>
<id>1c6422c4bdd39b91fee90ce3adeb8404ee92c341</id>
<content type='text'>
This patch fixes:

  llvm/lib/Transforms/Scalar/LoopInterchange.cpp:863:20: error: unused
  variable 'OpCode' [-Werror,-Wunused-variable]
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This patch fixes:

  llvm/lib/Transforms/Scalar/LoopInterchange.cpp:863:20: error: unused
  variable 'OpCode' [-Werror,-Wunused-variable]
</pre>
</div>
</content>
</entry>
<entry>
<title>[LoopInterchange] Drop nuw/nsw flags from reduction ops when interchanging (#148612)</title>
<updated>2025-07-15T13:04:16+00:00</updated>
<author>
<name>Ryotaro Kasuga</name>
<email>kasuga.ryotaro@fujitsu.com</email>
</author>
<published>2025-07-15T13:04:16+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=b3c293c5b977dd8ea824c66e932719ee8245b6ca'/>
<id>b3c293c5b977dd8ea824c66e932719ee8245b6ca</id>
<content type='text'>
Before this patch, when a reduction exists in the loop, the legality
check of LoopInterchange only verified if there exists a
non-reassociative floating-point instruction in the reduction
calculation. However, it is insufficient, because reordering integer
reductions can also lead to incorrect transformations. Consider the
following example:

```c
int A[2][2] = {
  { INT_MAX, INT_MAX },
  { INT_MIN, INT_MIN },
};

int sum = 0;
for (int i = 0; i &lt; 2; i++)
  for (int j = 0; j &lt; 2; j++)
    sum += A[j][i];
```

To make this exchange legal, we must drop nuw/nsw flags from the
instructions involved in the reduction operations.

This patch extends the legality check to correctly handle such cases. In
particular, for integer addition and multiplication, it verifies that
the nsw and nuw flags are set on involved instructions, and drop them
when the transformation actually performed. This patch also introduces
explicit checks for the kind of reduction and permits only those that
are known to be safe for interchange. Consequently, some "unknown"
reductions (at the moment, `FindFirst*` and `FindLast*`) are rejected.

Fix #148228</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Before this patch, when a reduction exists in the loop, the legality
check of LoopInterchange only verified if there exists a
non-reassociative floating-point instruction in the reduction
calculation. However, it is insufficient, because reordering integer
reductions can also lead to incorrect transformations. Consider the
following example:

```c
int A[2][2] = {
  { INT_MAX, INT_MAX },
  { INT_MIN, INT_MIN },
};

int sum = 0;
for (int i = 0; i &lt; 2; i++)
  for (int j = 0; j &lt; 2; j++)
    sum += A[j][i];
```

To make this exchange legal, we must drop nuw/nsw flags from the
instructions involved in the reduction operations.

This patch extends the legality check to correctly handle such cases. In
particular, for integer addition and multiplication, it verifies that
the nsw and nuw flags are set on involved instructions, and drop them
when the transformation actually performed. This patch also introduces
explicit checks for the kind of reduction and permits only those that
are known to be safe for interchange. Consequently, some "unknown"
reductions (at the moment, `FindFirst*` and `FindLast*`) are rejected.

Fix #148228</pre>
</div>
</content>
</entry>
<entry>
<title>[LoopInterchange] Defer CacheCost calculation until needed (#146874)</title>
<updated>2025-07-08T08:44:34+00:00</updated>
<author>
<name>Ryotaro Kasuga</name>
<email>kasuga.ryotaro@fujitsu.com</email>
</author>
<published>2025-07-08T08:44:34+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=29487759e3cc8fc056a599a38b3a6d2d8849a20e'/>
<id>29487759e3cc8fc056a599a38b3a6d2d8849a20e</id>
<content type='text'>
LoopInterchange currently stop and exit its process when the number of
loads/stores in the loop is greater than `MaxMemInstrCount`. This
prevents excessive querying to DependenceAnalysis. However, computing
`CacheCost` also involves DependenceAnalysis queries, and their number
can grow to `O(N^2)` in the worst case, where `N` is the number of
loads/stores in the loop. Therefore, we should also avoid calculating it
if the loads/stores count exceeds `MaxMemInstrCount`.
This patch defers the calculation of `CacheCost` until it is actually
needed to reduce compile time. This avoids computing `CacheCost` when
the number of loads/stores is large. Additionally, since this patch
delays its calculation as much as possible, it is also effective in
other scenarios, e.g., when there are no legal loop pairs to exchange.</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
LoopInterchange currently stop and exit its process when the number of
loads/stores in the loop is greater than `MaxMemInstrCount`. This
prevents excessive querying to DependenceAnalysis. However, computing
`CacheCost` also involves DependenceAnalysis queries, and their number
can grow to `O(N^2)` in the worst case, where `N` is the number of
loads/stores in the loop. Therefore, we should also avoid calculating it
if the loads/stores count exceeds `MaxMemInstrCount`.
This patch defers the calculation of `CacheCost` until it is actually
needed to reduce compile time. This avoids computing `CacheCost` when
the number of loads/stores is large. Additionally, since this patch
delays its calculation as much as possible, it is also effective in
other scenarios, e.g., when there are no legal loop pairs to exchange.</pre>
</div>
</content>
</entry>
<entry>
<title>[LoopInterchange] Modernize loops (NFC) (#146105)</title>
<updated>2025-06-28T10:41:05+00:00</updated>
<author>
<name>Ramkumar Ramachandra</name>
<email>ramkumar.ramachandra@codasip.com</email>
</author>
<published>2025-06-28T10:41:05+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=be9502b095d2dc08768d5723f66cf0dd8f0490fd'/>
<id>be9502b095d2dc08768d5723f66cf0dd8f0490fd</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>[LoopInterchange] Use ArrayRef in more places (NFC) (#146077)</title>
<updated>2025-06-27T16:22:24+00:00</updated>
<author>
<name>Ramkumar Ramachandra</name>
<email>ramkumar.ramachandra@codasip.com</email>
</author>
<published>2025-06-27T16:22:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.belthelziquor.com/llvm-project.git/commit/?id=7613c2412a25232f79e73777c13edd7fd36d963c'/>
<id>7613c2412a25232f79e73777c13edd7fd36d963c</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
</feed>
