Skip to content

Commit c9f7855

Browse files
committed
[herd] Avoid one useless HW update
When a writes effect value is the same as the value read by the same instruction from the same location, there is no need to perform a HW update.
1 parent 0c73828 commit c9f7855

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

herd/mem.ml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,30 @@ module Make(C:Config) (S:Sem.Semantics) : S with module S = S =
692692
(fun e k ->
693693
match SM.can_unset_af_loc e with
694694
| None -> k
695-
| Some loc -> loc::k)
695+
| Some loc ->
696+
let v = Misc.as_some @@ E.written_of e in
697+
Printf.eprintf
698+
"loc=%s,v=%s\n%!" (V.pp_v loc) (V.pp_v v) ;
699+
let write_loaded =
700+
try
701+
E.is_atomic e
702+
&& (match v with V.Var _ -> true | V.Val _ -> false)
703+
&& E.EventSet.exists
704+
(fun er ->
705+
E.po_eq e er && E.is_mem_load er &&
706+
begin
707+
match
708+
E.global_loc_of er,
709+
E.read_of er
710+
with
711+
| Some loc_r,Some v_r
712+
->
713+
V.equal loc loc_r && V.equal v v_r
714+
| _,_ -> false
715+
end)
716+
es.E.events
717+
with Not_found -> false in
718+
if write_loaded then k else loc::k)
696719
es.E.events []
697720
|> Misc.group V.compare in
698721
let om =

0 commit comments

Comments
 (0)