Minor code cleanups in simple_gvn's main loop.

Redundant load/store elimination isn't critical for the use case of
optimizing wasm code which has already been optimized, so remove the
TODO for that for now.
This commit is contained in:
Dan Gohman
2017-09-20 09:55:01 -07:00
parent b888894fbb
commit 482439c94b

View File

@@ -7,8 +7,9 @@ use std::collections::HashMap;
/// Test whether the given opcode is unsafe to even consider for GVN.
fn trivially_unsafe_for_gvn(opcode: Opcode) -> bool {
opcode.is_call() || opcode.is_branch() || opcode.is_terminator() || opcode.is_return() ||
opcode.can_trap() || opcode.other_side_effects()
opcode.is_call() || opcode.is_branch() || opcode.is_terminator() ||
opcode.is_return() || opcode.can_trap() || opcode.other_side_effects() ||
opcode.can_store() || opcode.can_load()
}
/// Perform simple GVN on `func`.
@@ -26,24 +27,15 @@ pub fn do_simple_gvn(func: &mut Function, cfg: &mut ControlFlowGraph, domtree: &
pos.goto_top(ebb);
while let Some(inst) = pos.next_inst() {
let opcode = func.dfg[inst].opcode();
let ctrl_typevar = func.dfg.ctrl_typevar(inst);
// Resolve aliases, particularly aliases we created earlier.
func.dfg.resolve_aliases_in_arguments(inst);
let opcode = func.dfg[inst].opcode();
if trivially_unsafe_for_gvn(opcode) {
continue;
}
// TODO: Implement simple redundant-load elimination.
if opcode.can_store() {
continue;
}
if opcode.can_load() {
continue;
}
let ctrl_typevar = func.dfg.ctrl_typevar(inst);
let key = (func.dfg[inst].clone(), ctrl_typevar);
let entry = visible_values.entry(key);
use std::collections::hash_map::Entry::*;