Skip to content

Commit

Permalink
Add docs for loop unroll
Browse files Browse the repository at this point in the history
  • Loading branch information
HHTheBest committed Apr 19, 2024
1 parent e842e35 commit a7856e0
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions docs/task4_doc/optimizations.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,29 @@ int c = a + 2;

代表测例:`bitset*.sysu.c``crypto-*.sysu.c``instruction-combining-*.sysu.c``integer-divide-optimization-*.sysu.c`

难度:待补充
难度:★★★★☆

仅介绍循环次数为常数、可完全展开的循环展开。

仅介绍循环次数为常数、可完全展开的循环展开
基本的思路如下:

```C++
// 循环展开前
while(j<60)
{
ans = ans + 20;
}

// 循环展开后
ans = ans + 20;
ans = ans + 20;
...
ans = ans + 20;

// 结合后续优化
ans = ans + 20 * 60;
```
循环展开的作用不仅仅是将原本常数的循环展开成非常数的循环,更是要结合后续优化,让循环内的语句能被后续的pass进一步优化。

#### 控制流简化

Expand Down

0 comments on commit a7856e0

Please sign in to comment.