From 0b17b5c0a8474e0647283abf66c3e51fb9cfcf60 Mon Sep 17 00:00:00 2001 From: Justus Fasse Date: Sat, 21 Aug 2021 21:38:04 +0200 Subject: Hopefully a proper fix to code motion below side exits + NO register renaming --- scheduling/MyRTLpathScheduleraux.ml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scheduling/MyRTLpathScheduleraux.ml b/scheduling/MyRTLpathScheduleraux.ml index 2cf58d2e..7afaeaa9 100644 --- a/scheduling/MyRTLpathScheduleraux.ml +++ b/scheduling/MyRTLpathScheduleraux.ml @@ -1525,6 +1525,29 @@ let scheduler f = (List.init (Array.length sb.instructions) (fun i -> i)) PTree.empty in + let (sb, code, pm, next_free_pc, live_renames) = + if !Clflags.option_fpoormansssa then + (* Final restoration code was already inserted. *) + (sb, code, pm, next_free_pc, live_renames) + else + (* Ther combination of code motion below side exits WITHOUT register renaming may + * cause some restoration code to be necessary. Otherwise it is not safe to + * duplicate instructions. + * The final restoration code is special since it may insert below. *) + let final_restoration = final_restoration_code sb code live_renames in + let (sb, code, pm, next_free_pc, fwmap) = insert_code sb code pm final_restoration ~next_free_pc in + let live_renames = + PTree.fold + (fun acc pc insts -> + let pc' = apply_map' fwmap pc in + (* Remove final renames, which were just inserted *) + let insts = if Camlcoq.P.eq pc sb.instructions.(Array.length sb.instructions - 1) then [] else insts in + PTree.set pc' insts acc) + live_renames + PTree.empty + in + (sb, code, pm, next_free_pc, live_renames) + in let (to_insert_restoration, to_rename, next_free_reg) = restoration_instructions' sb code live_renames ~next_free_reg in let side_exit_pcs = side_exit_pcs sb code in let code = ListLabels.fold_left side_exit_pcs -- cgit