Commit e8219e5
authored
[VPlan] Use BlockFrequencyInfo in getPredBlockCostDivisor (#158690)
In 531.deepsjeng_r from SPEC CPU 2017 there's a loop that we
unprofitably loop vectorize on RISC-V.
The loop looks something like:
```c
for (int i = 0; i < n; i++) {
if (x0[i] == a)
if (x1[i] == b)
if (x2[i] == c)
// do stuff...
}
```
Because it's so deeply nested the actual inner level of the loop rarely
gets executed. However we still deem it profitable to vectorize, which
due to the if-conversion means we now always execute the body.
This stems from the fact that `getPredBlockCostDivisor` currently
assumes that blocks have 50% chance of being executed as a heuristic.
We can fix this by using BlockFrequencyInfo, which gives a more accurate
estimate of the innermost block being executed 12.5% of the time. We can
then calculate the probability as `HeaderFrequency / BlockFrequency`.
Fixing the cost here gives a 7% speedup for 531.deepsjeng_r on RISC-V.
Whilst there's a lot of changes in the in-tree tests, this doesn't
affect llvm-test-suite or SPEC CPU 2017 that much:
- On armv9-a -flto -O3 there's 0.0%/0.2% more geomean loops vectorized
on llvm-test-suite/SPEC CPU 2017.
- On x86-64 -flto -O3 **with PGO** there's 0.9%/0% less geomean loops
vectorized on llvm-test-suite/SPEC CPU 2017.
Overall geomean compile time impact is 0.03% on stage1-ReleaseLTO:
https://llvm-compile-time-tracker.com/compare.php?from=9eee396c58d2e24beb93c460141170def328776d&to=32fbff48f965d03b51549fdf9bbc4ca06473b623&stat=instructions%3Au1 parent dd06214 commit e8219e5
File tree
11 files changed
+463
-42
lines changed- llvm
- include/llvm/Transforms/Vectorize
- lib/Transforms/Vectorize
- test/Transforms
- LoopVectorize
- AArch64
- RISCV
- PhaseOrdering
- AArch64
11 files changed
+463
-42
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
367 | | - | |
| 367 | + | |
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
| 148 | + | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1443 | 1443 | | |
1444 | 1444 | | |
1445 | 1445 | | |
1446 | | - | |
| 1446 | + | |
| 1447 | + | |
1447 | 1448 | | |
1448 | 1449 | | |
1449 | 1450 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| 149 | + | |
149 | 150 | | |
150 | 151 | | |
151 | 152 | | |
| |||
873 | 874 | | |
874 | 875 | | |
875 | 876 | | |
876 | | - | |
877 | | - | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
878 | 880 | | |
879 | 881 | | |
880 | | - | |
881 | | - | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
882 | 885 | | |
883 | 886 | | |
884 | 887 | | |
| |||
1219 | 1222 | | |
1220 | 1223 | | |
1221 | 1224 | | |
1222 | | - | |
| 1225 | + | |
1223 | 1226 | | |
1224 | 1227 | | |
1225 | 1228 | | |
| |||
1234 | 1237 | | |
1235 | 1238 | | |
1236 | 1239 | | |
1237 | | - | |
1238 | | - | |
1239 | | - | |
| 1240 | + | |
| 1241 | + | |
| 1242 | + | |
1240 | 1243 | | |
1241 | 1244 | | |
1242 | | - | |
1243 | | - | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
1247 | | - | |
1248 | | - | |
1249 | | - | |
1250 | | - | |
1251 | | - | |
| 1245 | + | |
1252 | 1246 | | |
1253 | 1247 | | |
1254 | 1248 | | |
1255 | 1249 | | |
1256 | 1250 | | |
1257 | 1251 | | |
1258 | | - | |
1259 | | - | |
| 1252 | + | |
1260 | 1253 | | |
1261 | 1254 | | |
1262 | 1255 | | |
| |||
1729 | 1722 | | |
1730 | 1723 | | |
1731 | 1724 | | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
1732 | 1739 | | |
1733 | 1740 | | |
1734 | 1741 | | |
| |||
2792 | 2799 | | |
2793 | 2800 | | |
2794 | 2801 | | |
2795 | | - | |
2796 | | - | |
| 2802 | + | |
| 2803 | + | |
2797 | 2804 | | |
2798 | 2805 | | |
2799 | 2806 | | |
| |||
2886 | 2893 | | |
2887 | 2894 | | |
2888 | 2895 | | |
| 2896 | + | |
| 2897 | + | |
| 2898 | + | |
| 2899 | + | |
| 2900 | + | |
| 2901 | + | |
| 2902 | + | |
| 2903 | + | |
| 2904 | + | |
| 2905 | + | |
| 2906 | + | |
| 2907 | + | |
| 2908 | + | |
| 2909 | + | |
| 2910 | + | |
| 2911 | + | |
| 2912 | + | |
2889 | 2913 | | |
2890 | 2914 | | |
2891 | | - | |
| 2915 | + | |
2892 | 2916 | | |
2893 | 2917 | | |
2894 | 2918 | | |
| |||
9182 | 9206 | | |
9183 | 9207 | | |
9184 | 9208 | | |
9185 | | - | |
9186 | | - | |
| 9209 | + | |
| 9210 | + | |
| 9211 | + | |
9187 | 9212 | | |
9188 | 9213 | | |
9189 | 9214 | | |
| |||
9196 | 9221 | | |
9197 | 9222 | | |
9198 | 9223 | | |
9199 | | - | |
9200 | | - | |
| 9224 | + | |
| 9225 | + | |
9201 | 9226 | | |
9202 | 9227 | | |
9203 | 9228 | | |
| |||
9897 | 9922 | | |
9898 | 9923 | | |
9899 | 9924 | | |
9900 | | - | |
9901 | | - | |
| 9925 | + | |
| 9926 | + | |
| 9927 | + | |
| 9928 | + | |
9902 | 9929 | | |
9903 | 9930 | | |
9904 | 9931 | | |
| |||
9932 | 9959 | | |
9933 | 9960 | | |
9934 | 9961 | | |
9935 | | - | |
| 9962 | + | |
| 9963 | + | |
9936 | 9964 | | |
9937 | 9965 | | |
9938 | 9966 | | |
| |||
10035 | 10063 | | |
10036 | 10064 | | |
10037 | 10065 | | |
10038 | | - | |
| 10066 | + | |
10039 | 10067 | | |
10040 | 10068 | | |
10041 | 10069 | | |
| |||
10353 | 10381 | | |
10354 | 10382 | | |
10355 | 10383 | | |
10356 | | - | |
10357 | | - | |
10358 | | - | |
| 10384 | + | |
| 10385 | + | |
| 10386 | + | |
10359 | 10387 | | |
10360 | 10388 | | |
10361 | 10389 | | |
| |||
Lines changed: 5 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
| 60 | + | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
108 | | - | |
| 108 | + | |
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
| 123 | + | |
| 124 | + | |
123 | 125 | | |
Lines changed: 53 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
385 | 385 | | |
386 | 386 | | |
387 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
388 | 441 | | |
389 | 442 | | |
390 | 443 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
389 | | - | |
| 389 | + | |
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
| |||
0 commit comments