Commit 39b0cbe
authored
[IndVarSimplify] Allow predicateLoopExit on some loops with thread-local writes (#155901)
This is important to optimize patterns that frequently appear with
bounds checks:
```
for (int i = 0; i < N; ++i) {
bar[i] = foo[i] + 123;
}
```
which gets roughly turned into
```
for (int i = 0; i < N; ++i) {
if (i >= size of foo)
ubsan.trap();
if (i >= size of bar)
ubsan.trap();
bar[i] = foo[i] + 123;
}
```
Motivating example:
https://github.com/google/boringssl/blob/main/crypto/fipsmodule/hmac/hmac.cc.inc#L138
I hand-verified the assembly and confirmed that this optimization
removes the check in the loop.
This also allowed the loop to be vectorized.
Alive2: https://alive2.llvm.org/ce/z/3qMdLF
I did a `stage2-check-all` for both normal and
`-DBOOTSTRAP_CMAKE_C[XX]_FLAGS="-fsanitize=array-bounds
-fsanitize-trap=all"`.
I also ran some Google-internal tests with `fsanitize=array-bounds`.
Everything passes.1 parent 7fe0691 commit 39b0cbe
File tree
3 files changed
+794
-14
lines changed- llvm
- lib/Transforms/Scalar
- test/Transforms/IndVarSimplify
- X86
3 files changed
+794
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
56 | 57 | | |
57 | 58 | | |
58 | 59 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
120 | 125 | | |
121 | 126 | | |
122 | 127 | | |
| |||
1704 | 1709 | | |
1705 | 1710 | | |
1706 | 1711 | | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
1707 | 1730 | | |
1708 | 1731 | | |
1709 | 1732 | | |
| |||
1816 | 1839 | | |
1817 | 1840 | | |
1818 | 1841 | | |
| 1842 | + | |
1819 | 1843 | | |
1820 | 1844 | | |
1821 | 1845 | | |
1822 | | - | |
1823 | | - | |
| 1846 | + | |
| 1847 | + | |
| 1848 | + | |
| 1849 | + | |
| 1850 | + | |
| 1851 | + | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
1824 | 1861 | | |
1825 | 1862 | | |
1826 | 1863 | | |
| |||
1840 | 1877 | | |
1841 | 1878 | | |
1842 | 1879 | | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
1843 | 1893 | | |
1844 | 1894 | | |
1845 | 1895 | | |
| |||
Lines changed: 4 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
| 63 | + | |
65 | 64 | | |
66 | 65 | | |
67 | 66 | | |
| |||
150 | 149 | | |
151 | 150 | | |
152 | 151 | | |
153 | | - | |
154 | | - | |
| 152 | + | |
155 | 153 | | |
156 | 154 | | |
157 | 155 | | |
| |||
243 | 241 | | |
244 | 242 | | |
245 | 243 | | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
| 244 | + | |
250 | 245 | | |
251 | 246 | | |
252 | 247 | | |
| |||
339 | 334 | | |
340 | 335 | | |
341 | 336 | | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
| 337 | + | |
346 | 338 | | |
347 | 339 | | |
348 | 340 | | |
| |||
0 commit comments