<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/90175>90175</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
#pragma clang loop pipeline(disable) is ignored when other transformation pragmas exist
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ytmukai
</td>
</tr>
</table>
<pre>
For example, `llvm.loop.pipeline.disable` is not generated by the following code. (https://godbolt.org/z/vaxhKfG6b)
```c
void f(double *a, int n) {
#pragma clang loop unroll(enable) pipeline(disable)
for (int i=0; i<n; i++)
a[i]++;
}
```
`llvm.loop.pipeline.disable` metadata is not generated for the loop:
```
!36 = distinct !{!36, !30, !37, !38, !39}
!37 = !DILocation(line: 4, column: 9, scope: !23)
!38 = !{!"llvm.loop.mustprogress"}
!39 = !{!"llvm.loop.unroll.enable"}
```
It is implemented in such a way that when an earlier transformation is enabled, a metadata for a later one will be generated only if it is enabled.
In fact, rewriting `pipeline(disable)` to `pipeline_initiation_interval(1)` (this means pipeline is enabled) in the above code produces the following metadata:
```
!36 = distinct !{!36, !30, !37, !38, !39, !40}
!37 = !DILocation(line: 4, column: 9, scope: !23)
!38 = !{!"llvm.loop.mustprogress"}
!39 = !{!"llvm.loop.unroll.enable"}
!40 = !{!"llvm.loop.unroll.followup_all", !41}
!41 = distinct !{!41, !30, !37, !38, !42, !43}
!42 = !{!"llvm.loop.unroll.disable"}
!43 = !{!"llvm.loop.pipeline.initiationinterval", i32 1}
```
This can be resolved by turning on a flag that indicates that a transformation exists (`HasUserTransforms`) even in the case of `disable` in the following code:
https://github.com/llvm/llvm-project/blob/f4efa067435c8137718c907bf0de2b891b76552d/clang/lib/CodeGen/CGLoopInfo.cpp#L49-L56
Will this change break the intent of the original code or have any side effects?
It is similar for other more commonly used transformations, such as vectorization and unrolling, but for those, they can be consequently disabled in other ways. `vectorize(disable)` is interpreted as `vectorize.width==1`, so `HasUserTransforms` is turned on. The metadata for `unroll(disable)` is generated by the first transformation (`createFullUnrollMetadata`), so `HasUserTransforms` is not necessary to be on.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcVsFu2zgQ_Rr6MqghkbJkHXxIYrhbbPbWYo8FJY0kbilSS1JO3a9fDGU5jpM22MNeFjAiMiJHM2_evBnpveoM4o5t7tlmv5JT6K3bncIwfZNqVdnmtDtYB_hdDqNGxh-A5YnWx2GtrR3XoxpRK4PrRnlZaWR5AsqDsQE6NOhkwAaqE4QeobVa2ydlOqhtg2tgfNuHMHom7hg_MH7obFNZHdbWdYwffjB-OMrv_e_tx7xivASW7Flyd36wPJl_9bw_WtVAy_i2sVOlERi_k-StMgFMvF3cL1e5GJ3sBgm1lqYDCgQm46zWjG_RxDh4CUtsZPQc3bMXrXUUAJlXTOwTJu5p8WDmBb-Pv8txyTb3im325xfi4kuxvw1o2S___TXYAwbZyCBfo04eEux0lSB-E70LJKnIgYk9NMoHZeoAjKesuI8vYtZ5KpJlUSyL7bIorwKhA9EW4-n-06OtZVDWML6NYIo7yOhWbfU0GNqWtPW1HeNLxlMunpGLX1mszQ4xzp8xGSYfRmc7h94zzl-6Uf7i4pzw9ZJu_vNMnB-fAmGsqAwGNISwMuCnugcJT5IoLgM89WhAGkDptEIHwUnjW-uGiAEZmD_YUMzyOXuULAlaBnRgDcKT0hoqvEqnNfoEqgUVrqysF98MtLIOZNThk1OBqozlyZsUpsiCvX79VRkVVHTxqzIB3VFSKaTnw4xvQ688DCiNv5TFi2BKAoPYJit7xFjgMDrbTDX6m-JfYo7J_o9JOS-y5P_ETorn_Zsz3tP4VZKq8QWJ9KWh9CfwZun78GYXo-KlUf6-dxcy3gQmfnH1on7PZH3mavRFCQ7pG3V8Laifici1NFRcDr3Vx3ODmpwhdloDElotu7melWlULUMksQwgbwsavysfPFUIy5PfpP_i0X1ejnj6Ni8Bj2iW-qilR7AtVd91yzRvdMiLaM9_b3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