Commit f8ec02f
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 3793264 commit f8ec02f
File tree
2 files changed
+58
-16
lines changed- llvm
- lib/CodeGen
- test/Transforms/CodeGenPrepare/X86
2 files changed
+58
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1982 | 1982 | | |
1983 | 1983 | | |
1984 | 1984 | | |
1985 | | - | |
1986 | | - | |
1987 | | - | |
1988 | | - | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
1989 | 1988 | | |
1990 | 1989 | | |
1991 | 1990 | | |
1992 | 1991 | | |
1993 | 1992 | | |
| 1993 | + | |
1994 | 1994 | | |
1995 | 1995 | | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
1996 | 2015 | | |
1997 | 2016 | | |
1998 | 2017 | | |
| |||
2032 | 2051 | | |
2033 | 2052 | | |
2034 | 2053 | | |
| 2054 | + | |
| 2055 | + | |
2035 | 2056 | | |
2036 | 2057 | | |
2037 | 2058 | | |
| |||
2046 | 2067 | | |
2047 | 2068 | | |
2048 | 2069 | | |
2049 | | - | |
2050 | | - | |
2051 | 2070 | | |
2052 | 2071 | | |
2053 | 2072 | | |
2054 | 2073 | | |
2055 | | - | |
| 2074 | + | |
2056 | 2075 | | |
2057 | | - | |
| 2076 | + | |
| 2077 | + | |
2058 | 2078 | | |
2059 | 2079 | | |
2060 | 2080 | | |
| |||
2072 | 2092 | | |
2073 | 2093 | | |
2074 | 2094 | | |
| 2095 | + | |
| 2096 | + | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
2075 | 2112 | | |
2076 | 2113 | | |
2077 | 2114 | | |
| |||
2099 | 2136 | | |
2100 | 2137 | | |
2101 | 2138 | | |
2102 | | - | |
| 2139 | + | |
| 2140 | + | |
2103 | 2141 | | |
2104 | 2142 | | |
| 2143 | + | |
| 2144 | + | |
2105 | 2145 | | |
2106 | 2146 | | |
2107 | 2147 | | |
| |||
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