Commit 79186af
committed
[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 #758391 parent a03b225 commit 79186af
File tree
5 files changed
+47
-27
lines changed- clang
- lib/CodeGen
- test/CodeGenCXX
5 files changed
+47
-27
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
| 203 | + | |
| 204 | + | |
204 | 205 | | |
205 | 206 | | |
206 | 207 | | |
| |||
643 | 644 | | |
644 | 645 | | |
645 | 646 | | |
646 | | - | |
647 | | - | |
648 | | - | |
| 647 | + | |
649 | 648 | | |
650 | 649 | | |
651 | 650 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 43 | + | |
| 44 | + | |
47 | 45 | | |
48 | | - | |
| 46 | + | |
49 | 47 | | |
| 48 | + | |
| 49 | + | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
41 | | - | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
120 | 120 | | |
121 | | - | |
122 | | - | |
| 121 | + | |
123 | 122 | | |
124 | | - | |
125 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
126 | 126 | | |
127 | | - | |
| 127 | + | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | | - | |
| 58 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
206 | 224 | | |
207 | 225 | | |
208 | 226 | | |
| |||
220 | 238 | | |
221 | 239 | | |
222 | 240 | | |
| 241 | + | |
223 | 242 | | |
224 | 243 | | |
225 | | - | |
226 | 244 | | |
227 | 245 | | |
228 | 246 | | |
| |||
241 | 259 | | |
242 | 260 | | |
243 | 261 | | |
244 | | - | |
| 262 | + | |
245 | 263 | | |
246 | 264 | | |
247 | 265 | | |
| |||
269 | 287 | | |
270 | 288 | | |
271 | 289 | | |
272 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
0 commit comments