[clang] [Clang][OpenMP][LoopTransformations] Fix incorrect number of generated loops for Tile and Reverse directives (PR #140532)

Walter J.T.V via cfe-commits cfe-commits at lists.llvm.org
Thu May 22 02:19:56 PDT 2025


eZWALT wrote:

After conducting an examination of the directive handling logic, I can confidently state that the number of generated loops (`NumGeneratedLoops`) does not affect the semantic checks for the majority of transformations. This is because values are usually hardcoded in the `ActOnXXX` semantic handlers. For example:

- In the case of the `'reverse'` directive, the number of loops (`NumLoops`) is hardcoded to `1`, meaning it remains unaffected by any external loop count logic.
  
- For the `'interchange'` directive, the number of loops is also explicitly set using the following logic:

```
size_t NumLoops = PermutationClause ? PermutationClause->getNumLoops() : 2;
```

These values are passed into the `checkTransformableLoopNest` function and are not accessed elsewhere in the codebase, except:

- In `doForAllLoops`, where only the **presence** of loops is checked (i.e., `NumLoops == 0` or `> 0`), not the actual count, therefore this change won't break this conditional flow.
- In the newly introduced analysis functions (as part of the `'fuse'` transformation: #139293), specifically within `checkTransformableLoopSequence`, where both `NumGeneratedLoops` and `NumGeneratedLoopNests` are read and actively utilized.

https://github.com/llvm/llvm-project/pull/140532


More information about the cfe-commits mailing list