[all-commits] [llvm/llvm-project] b3c293: [LoopInterchange] Drop nuw/nsw flags from reductio...
Ryotaro Kasuga via All-commits
all-commits at lists.llvm.org
Tue Jul 15 06:04:37 PDT 2025
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: b3c293c5b977dd8ea824c66e932719ee8245b6ca
https://github.com/llvm/llvm-project/commit/b3c293c5b977dd8ea824c66e932719ee8245b6ca
Author: Ryotaro Kasuga <kasuga.ryotaro at fujitsu.com>
Date: 2025-07-15 (Tue, 15 Jul 2025)
Changed paths:
M llvm/lib/Transforms/Scalar/LoopInterchange.cpp
A llvm/test/Transforms/LoopInterchange/reductions-non-wrapped-operations.ll
A llvm/test/Transforms/LoopInterchange/reductions-with-nowraps.ll
Log Message:
-----------
[LoopInterchange] Drop nuw/nsw flags from reduction ops when interchanging (#148612)
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 < 2; i++)
for (int j = 0; j < 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
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