llvm-project
b3c293c5 - [LoopInterchange] Drop nuw/nsw flags from reduction ops when interchanging (#148612)

Commit
88 days ago
[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
Author
Parents
Loading