| 1 | import v3.ssa |
| 2 | import v3.ssa.optimize |
| 3 | |
| 4 | // test_optimize_verifies_and_preserves_valid_ssa validates this v3 regression case. |
| 5 | fn test_optimize_verifies_and_preserves_valid_ssa() { |
| 6 | mut m := ssa.Module.new() |
| 7 | i64_type := m.type_store.get_int(64) |
| 8 | func_id := m.new_function('main', i64_type) |
| 9 | entry := m.add_block(func_id, 'entry') |
| 10 | two := m.get_or_add_const(i64_type, '2') |
| 11 | three := m.get_or_add_const(i64_type, '3') |
| 12 | add := m.add_instr(.add, entry, i64_type, [two, three]) |
| 13 | m.add_instr(.ret, entry, ssa.TypeID(0), [add]) |
| 14 | |
| 15 | optimize.optimize(mut m) |
| 16 | |
| 17 | assert m.funcs[func_id].blocks == [entry] |
| 18 | assert m.blocks[entry].instrs.len == 1 |
| 19 | ret_id := m.blocks[entry].instrs[0] |
| 20 | ret := m.instrs[m.values[ret_id].index] |
| 21 | assert ret.op == .ret |
| 22 | assert ret.operands.len == 1 |
| 23 | ret_operand := m.values[ret.operands[0]] |
| 24 | assert ret_operand.kind == .constant |
| 25 | assert ret_operand.name == '5' |
| 26 | } |
| 27 | |