Loop-invariant Hoisting
|-------------|
|---------| L0: | t = 0 |
L0: | t = 0 | | t = a * b |
|---------| |-------------|
↓ ↓
L1: |------------------| <----| L1: |------------------| <----|
| i = i + 1 | | | i = i + 1 | |
| t = a * b | | | | |
| M[i] = t | | ------> | M[i] = t | |
| if i < N goto L1 | | | if i < N goto L1 | |
|------------------| ------ |------------------| ------
↓ ↓
L2: |---------| L2: |---------|
| x = t | | x = t |
|---------| |---------|
t = a * b
is a loop-invariant.
- The value of
a * b
does not change over the loop iterations.