Skip to content

Commit

Permalink
Deadcode: eliminate trivial Icond instructions
Browse files Browse the repository at this point in the history
These are conditionals where the "ifso" and the "ifnot" successors are the same.  By eliminating them here and not later, we can also eliminate the instructions that compute the arguments to the condition, if any.

There is another, later point where these trivial conditional instructions are eliminated: in the Tunneling phase.  The elimination done in Tunneling is more powerful in that it works not just for conditionals whose two successors are the same, but also for conditionals whose two successors lead to the same point after a series of nops.  The elimination done in Deadcode is more powerful in that it eliminates the instructions that compute the arguments to the condition.  Hence it is worth having both eliminations.
  • Loading branch information
xavierleroy committed Sep 18, 2017
1 parent c4dcf7c commit 93d2fc9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion backend/Deadcode.v
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ Definition transfer (f: function) (approx: PMap.t VA.t)
| Some(Ibuiltin ef args res s) =>
transfer_builtin approx!!pc ef args res ne nm
| Some(Icond cond args s1 s2) =>
(add_needs args (needs_of_condition cond) ne, nm)
if peq s1 s2 then after else
(add_needs args (needs_of_condition cond) ne, nm)
| Some(Ijumptable arg tbl) =>
(add_need_all arg ne, nm)
| Some(Ireturn optarg) =>
Expand Down Expand Up @@ -191,6 +192,8 @@ Definition transf_instr (approx: PMap.t VA.t) (an: PMap.t NA.t)
if nmem_contains (snd an!!pc) (aaddr_arg approx!!pc dst) sz
then instr
else Inop s
| Icond cond args s1 s2 =>
if peq s1 s2 then Inop s1 else instr
| _ =>
instr
end.
Expand Down
6 changes: 5 additions & 1 deletion backend/Deadcodeproof.v
Original file line number Diff line number Diff line change
Expand Up @@ -1046,8 +1046,12 @@ Ltac UseTransfer :=
eapply mextends_agree; eauto.

- (* conditional *)
TransfInstr; UseTransfer.
TransfInstr; UseTransfer. destruct (peq ifso ifnot).
+ replace (if b then ifso else ifnot) with ifso by (destruct b; congruence).
econstructor; split.
eapply exec_Inop; eauto.
eapply match_succ_states; eauto. simpl; auto.
+ econstructor; split.
eapply exec_Icond; eauto.
eapply needs_of_condition_sound. eapply ma_perm; eauto. eauto. eauto with na.
eapply match_succ_states; eauto 2 with na.
Expand Down

0 comments on commit 93d2fc9

Please sign in to comment.