aboutsummaryrefslogtreecommitdiffstats
path: root/backend/Duplicateaux.ml
diff options
context:
space:
mode:
authorCyril SIX <cyril.six@kalray.eu>2020-12-04 10:40:58 +0100
committerCyril SIX <cyril.six@kalray.eu>2020-12-04 10:40:58 +0100
commit079fe6856d0fc1bb7191a821c1d0b9875fcc074b (patch)
treeca16915894b11a375e56bf6f2ffcb26c19cd7e49 /backend/Duplicateaux.ml
parentabae3de5118a4741ae1c2350a3e75b6e0a84a57d (diff)
downloadcompcert-kvx-079fe6856d0fc1bb7191a821c1d0b9875fcc074b.tar.gz
compcert-kvx-079fe6856d0fc1bb7191a821c1d0b9875fcc074b.zip
Fixed infinite loop on find_last_node_before_loop
Happened when a loop was predicted not to be taken
Diffstat (limited to 'backend/Duplicateaux.ml')
-rw-r--r--backend/Duplicateaux.ml9
1 files changed, 6 insertions, 3 deletions
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