[llvm-branch-commits] [llvm] [LoopInterchange] Drop loop metadata and branch weights of interchanged loops (PR #235892)
Madhur Amilkanthwar via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Nov 3 23:03:09 PST 2026
================
@@ -2168,6 +2170,26 @@ void LoopInterchangeTransform::restructureLoops(
SE->forgetLoop(NewOuter);
}
+/// Update the metadata attached to the latch branches of the two loops. The
+/// loop metadata and the branch weights are dropped. Some attributes of the
+/// loop metadata may not hold after interchange (e.g.,
+/// llvm.loop.parallel_accesses of the inner loop doesn't imply that the loop is
+/// parallel when it becomes the outer loop), and no followup attributes are
+/// defined for interchange.
+/// TODO: Preserve the branch weights by swapping them.
----------------
madhur13490 wrote:
I don't think swapping is the right direction. adjustLoopBranches() keeps each latch branch's condition and back edge, and only retargets the exit successor:
```
updateSuccessor(InnerLoopLatchBI, InnerLoopLatchSuccessor,
OuterLoopLatchSuccessor, DTUpdates);
updateSuccessor(OuterLoopLatchBI, OuterLoopLatchSuccessor, InnerLoopLatch,
DTUpdates);
```
So the branch that tests j is still the latch of the j loop, which is now outermost, and the order of its successors doesn't change. If we swapped the weights, the j loop's back-edge probability would end up on the i branch. Could you reword the TODO, or drop it if we keep the weights (see the next comment)?
https://github.com/llvm/llvm-project/pull/235892
More information about the llvm-branch-commits
mailing list