From 079fe6856d0fc1bb7191a821c1d0b9875fcc074b Mon Sep 17 00:00:00 2001 From: Cyril SIX Date: Fri, 4 Dec 2020 10:40:58 +0100 Subject: Fixed infinite loop on find_last_node_before_loop Happened when a loop was predicted not to be taken --- backend/Duplicateaux.ml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'backend/Duplicateaux.ml') diff --git a/backend/Duplicateaux.ml b/backend/Duplicateaux.ml index 4684d870..98a638f3 100644 --- a/backend/Duplicateaux.ml +++ b/backend/Duplicateaux.ml @@ -624,6 +624,7 @@ type innerLoop = { * branches leading to a goto backedge * Such cases usually happen after a tail-duplication *) sb_final: P.t option; (* if the innerloop wraps a superblock, this is its final instruction *) + (* may be None if we predict that we do not loop *) } let print_pset = LICMaux.pp_pset @@ -727,9 +728,11 @@ let rec find_last_node_before_loop code node trace is_loop_header = get_some @@ PTree.get n is_loop_header && HashedSet.PSet.contains trace n) rtl_succ in match headers with | [] -> ( - match (rtl_successors_pref @@ get_some @@ PTree.get node code) with + let next_nodes = List.filter (fun n -> HashedSet.PSet.contains trace n) + (rtl_successors_pref @@ get_some @@ PTree.get node code) in + match next_nodes with | [n] -> find_last_node_before_loop code n trace is_loop_header - | _ -> None + | _ -> None (* May happen when we predict that a loop is not taken *) ) | [h] -> Some node | _ -> failwith "Multiple branches leading to a loop" @@ -897,7 +900,7 @@ let unroll_inner_loop_body code revmap iloop = debug "Too many nodes in the loop body (%d > %d)" (List.length body) limit; debug_flag := false; (code, revmap) end else if not @@ is_some iloop.sb_final then begin - debug "The loop body does not form a superblock"; debug_flag := false; + debug "The loop body does not form a superblock OR we have predicted that we do not loop"; debug_flag := false; (code, revmap) end else let (code2, revmap2, dupbody, fwmap) = clone code revmap body in -- cgit