You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[clang][CodeGen] Fix metadata when vectorization is disabled by pragma
There are two ways to disable vectorization with pragma,
`vectorize(disable)` and `vectorize_width(1)`. The document
(https://clang.llvm.org/docs/LanguageExtensions.html#vectorization-interleaving-and-predication)
states:
> Specifying a width/count of 1 disables the optimization, and is
equivalent to `vectorize(disable)` or `interleave(disable)`.
So the behavior should be the same when using either is used. However,
the current implementation doesn't satisfy this. When
`vectorize(disable)` is specified, it is converted internally to the
same as `vectorize_width(1)`, and the metadata is generated as if
vectorization is not explicitly specified as enabled or disabled. This
can cause a problem when other transformations are also specified by
pragma. For example, if `unroll_count(8)` is specified, the loop should
have a metadata that contains the information directly, like:
```
!loop0 = !{!"loop0", !vectorize_disable, !unroll}
!vectorize_disable = {...}
!unroll = !{!"llvm.loop.unroll_count", i32 8}
```
But now it's attached into followup metadata for vectorization.
```
!loop0 = !{!"loop0", !vectorize_width, !followup}
!vectorize_width = !{!"llvm.loop.vectorize.width", i32 1}
!followup = !{!"llvm.loop.vectorize.followup_all", !unroll}
!unroll = !{!"llvm.loop.unroll_count", i32 8}
```
As a result, the unroll attributes are ignored because the vectorization
is not applied.
This patch fixes this issue by generating metadata that disables
vectorization when `vectorize(disable)` or `vectorize_width(1)` are
specified.
The document also says:
> If the transformation is disabled (e.g. vectorize(disable)), that
takes precedence over transformations option pragmas implying that
transformation.
Therefore, if vectorization is disabled, all other vectorize options
like `vectorize_predicate` should be ignored. This patch also omits to
generate attributes for vectorization when it is disabled.
Fix#75839
0 commit comments