Commit 71b83ed
committed
[CGP][CodeGenPrepare] Folding
This extends the existing fold:
```
for(i = Start; i < End; ++i)
Rem = (i nuw+- IncrLoopInvariant) u% RemAmtLoopInvariant;
```
->
```
Rem = (Start nuw+- IncrLoopInvariant) % RemAmtLoopInvariant;
for(i = Start; i < End; ++i, ++rem)
Rem = rem == RemAmtLoopInvariant ? 0 : Rem;
```
To work with a non-zero `IncrLoopInvariant`.
This is a common usage in cases such as:
```
for(i = 0; i < N; ++i)
if ((i + 1) % X) == 0)
do_something_occasionally_but_not_first_iter();
```
Alive2 w/ i4/unrolled 6x (needs to be ran locally due to timeout):
https://alive2.llvm.org/ce/z/6tgyN3
Exhaust proof over all uint8_t combinations in C++:
https://godbolt.org/z/WYa561388urem with loop invariant value plus offset1 parent 6b11573 commit 71b83ed
File tree
2 files changed
+57
-12
lines changed- llvm
- lib/CodeGen
- test/Transforms/CodeGenPrepare/X86
2 files changed
+57
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1979 | 1979 | | |
1980 | 1980 | | |
1981 | 1981 | | |
| 1982 | + | |
| 1983 | + | |
1982 | 1984 | | |
1983 | 1985 | | |
1984 | 1986 | | |
1985 | 1987 | | |
1986 | 1988 | | |
1987 | 1989 | | |
| 1990 | + | |
1988 | 1991 | | |
1989 | 1992 | | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
1990 | 2012 | | |
1991 | 2013 | | |
1992 | 2014 | | |
| |||
2026 | 2048 | | |
2027 | 2049 | | |
2028 | 2050 | | |
| 2051 | + | |
| 2052 | + | |
2029 | 2053 | | |
2030 | 2054 | | |
2031 | 2055 | | |
| |||
2040 | 2064 | | |
2041 | 2065 | | |
2042 | 2066 | | |
2043 | | - | |
2044 | | - | |
2045 | 2067 | | |
2046 | 2068 | | |
2047 | 2069 | | |
2048 | 2070 | | |
2049 | | - | |
| 2071 | + | |
2050 | 2072 | | |
2051 | | - | |
| 2073 | + | |
| 2074 | + | |
2052 | 2075 | | |
2053 | 2076 | | |
2054 | 2077 | | |
| |||
2066 | 2089 | | |
2067 | 2090 | | |
2068 | 2091 | | |
| 2092 | + | |
| 2093 | + | |
| 2094 | + | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
2069 | 2109 | | |
2070 | 2110 | | |
2071 | 2111 | | |
| |||
2093 | 2133 | | |
2094 | 2134 | | |
2095 | 2135 | | |
2096 | | - | |
| 2136 | + | |
| 2137 | + | |
2097 | 2138 | | |
2098 | 2139 | | |
| 2140 | + | |
| 2141 | + | |
2099 | 2142 | | |
2100 | 2143 | | |
2101 | 2144 | | |
| |||
Lines changed: 9 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | | - | |
| 322 | + | |
323 | 323 | | |
324 | | - | |
| 324 | + | |
325 | 325 | | |
326 | 326 | | |
327 | | - | |
328 | | - | |
| 327 | + | |
| 328 | + | |
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
| 335 | + | |
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| |||
892 | 892 | | |
893 | 893 | | |
894 | 894 | | |
| 895 | + | |
895 | 896 | | |
896 | | - | |
897 | | - | |
898 | 897 | | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
899 | 901 | | |
900 | 902 | | |
901 | 903 | | |
| |||
0 commit comments