| 470 | } |
| 471 | |
| 472 | // A program with disjoint branches and locals: lots of per-vreg store/reload |
| 473 | // churn for the peephole to clean up, while exercising real control flow. |
| 474 | const PEEPHOLE_PROGRAM: &str = r#" |
| 475 | compute: (n: i64) -> i64 { |
| 476 | a: i64 = n + 1 |
| 477 | b: i64 = a * 2 |
| 478 | c: i64 = 0 |
| 479 | if b > 10 { |
| 480 | c = b - a |
| 481 | } else { |
| 482 | c = a + b |
| 483 | } |
| 484 | d: i64 = c + a |
| 485 | return d |
| 486 | } |
| 487 | |
| 488 | main: () -> i32 { |
| 489 | total: i64 = 0 |
| 490 | i: i64 = 0 |
| 491 | while i < 5 { |
| 492 | total = total + compute(i) |
| 493 | i = i + 1 |
| 494 | } |
| 495 | return total as i32 |
| 496 | } |
| 497 | "#; |
| 498 | |
| 499 | #[test] |
| 500 | fn peephole_preserves_behavior_and_shrinks_code() { |