| 616 | assert_eq!( |
| 617 | format!("{base_outcome:?}"), |
| 618 | format!("{opt_outcome:?}"), |
| 619 | "IR optimization changed the exit outcome" |
| 620 | ); |
| 621 | assert_eq!(base_uart, opt_uart, "IR optimization changed UART output"); |
| 622 | assert!( |
| 623 | opt_lines < base_lines, |
| 624 | "const-fold + DCE should remove instructions: {base_lines} -> {opt_lines}" |
| 625 | ); |
| 626 | } |
| 627 | |
| 628 | #[test] |
| 629 | fn ir_opt_preserves_control_flow_program() { |
| 630 | // The peephole stress program has params and loops: optimization must not |
| 631 | // change its result even where little folds. |
| 632 | let (base_outcome, base_uart, _) = |
| 633 | run_hll_optimize(PEEPHOLE_PROGRAM, hll_to_ir::OptOptions::none()); |
| 634 | let (opt_outcome, opt_uart, _) = |
| 635 | run_hll_optimize(PEEPHOLE_PROGRAM, hll_to_ir::OptOptions::all()); |
| 636 | |
| 637 | assert_eq!( |
| 638 | format!("{base_outcome:?}"), |
| 639 | format!("{opt_outcome:?}"), |