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

Alexey Bataev via cfe-commits cfe-commits at lists.llvm.org
Fri May 23 04:11:51 PDT 2025


alexey-bataev wrote:

> @alexey-bataev 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: [[Clang][OpenMP][LoopTransformations] Add support for "#pragma omp fuse" loop transformation directive and "looprange" clause #139293](https://github.com/llvm/llvm-project/pull/139293)), specifically within `checkTransformableLoopSequence`, where both `NumGeneratedLoops` and `NumGeneratedLoopNests` are read and actively utilized.

Can you remove these hardcoded values and use the stored value instead? Otherwise, it is meaningless and should be removed

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


More information about the cfe-commits mailing list