126_switch_sparse_chain.toy (717B)
1 // Sparse case values: vmax - vmin = 999 with only 3 cases. Density 2 // thresholds must reject the jump table at every opt level and stay on 3 // the chain. Pins the no-promotion behavior so a tuning regression that 4 // relaxes thresholds too far is caught. 5 6 fn pick(x: i64): i64 { 7 return switch x { 8 1 { 11 } 9 50 { 22 } 10 1000 { 33 } 11 default { 99 } 12 }; 13 } 14 15 fn __user_main(): i64 { 16 var s: i64 = 0; 17 s = s + pick(1); // 11 18 s = s + pick(50); // 22 19 s = s + pick(1000); // 33 20 s = s + pick(2); // miss -> 99 21 s = s + pick(999); // miss -> 99 22 s = s + pick(1001); // miss -> 99 23 return s; // 11+22+33+99+99+99 = 363 24 } 25 26 fn main(): i32 { return __user_main() as i32; }