Commit 77f5b58
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 b7eac8c commit 77f5b58
File tree
2 files changed
+69
-12
lines changed- llvm
- lib/CodeGen
- test/Transforms/CodeGenPrepare/X86
2 files changed
+69
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1976 | 1976 | | |
1977 | 1977 | | |
1978 | 1978 | | |
1979 | | - | |
1980 | | - | |
1981 | | - | |
1982 | | - | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
1983 | 1983 | | |
1984 | 1984 | | |
1985 | 1985 | | |
1986 | 1986 | | |
1987 | 1987 | | |
| 1988 | + | |
| 1989 | + | |
1988 | 1990 | | |
1989 | 1991 | | |
| 1992 | + | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
| 2008 | + | |
| 2009 | + | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
1990 | 2016 | | |
1991 | 2017 | | |
1992 | 2018 | | |
| |||
2026 | 2052 | | |
2027 | 2053 | | |
2028 | 2054 | | |
| 2055 | + | |
| 2056 | + | |
2029 | 2057 | | |
2030 | 2058 | | |
2031 | 2059 | | |
| |||
2040 | 2068 | | |
2041 | 2069 | | |
2042 | 2070 | | |
2043 | | - | |
2044 | | - | |
2045 | 2071 | | |
2046 | 2072 | | |
2047 | 2073 | | |
2048 | 2074 | | |
2049 | | - | |
| 2075 | + | |
| 2076 | + | |
2050 | 2077 | | |
2051 | | - | |
| 2078 | + | |
| 2079 | + | |
2052 | 2080 | | |
2053 | 2081 | | |
2054 | 2082 | | |
| |||
2066 | 2094 | | |
2067 | 2095 | | |
2068 | 2096 | | |
| 2097 | + | |
| 2098 | + | |
| 2099 | + | |
| 2100 | + | |
| 2101 | + | |
| 2102 | + | |
| 2103 | + | |
| 2104 | + | |
| 2105 | + | |
| 2106 | + | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
2069 | 2120 | | |
2070 | 2121 | | |
2071 | 2122 | | |
| |||
2096 | 2147 | | |
2097 | 2148 | | |
2098 | 2149 | | |
| 2150 | + | |
| 2151 | + | |
2099 | 2152 | | |
2100 | 2153 | | |
2101 | 2154 | | |
| |||
Lines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
892 | 892 | | |
893 | 893 | | |
894 | 894 | | |
| 895 | + | |
895 | 896 | | |
896 | | - | |
897 | | - | |
898 | 897 | | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
899 | 901 | | |
900 | 902 | | |
901 | 903 | | |
| |||
1003 | 1005 | | |
1004 | 1006 | | |
1005 | 1007 | | |
| 1008 | + | |
1006 | 1009 | | |
1007 | | - | |
1008 | | - | |
1009 | 1010 | | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
1010 | 1014 | | |
1011 | 1015 | | |
1012 | 1016 | | |
| |||
0 commit comments