From 482439c94b4f2ea806e04b81136eb24f5b2228d9 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 20 Sep 2017 09:55:01 -0700 Subject: [PATCH] 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. --- lib/cretonne/src/simple_gvn.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/cretonne/src/simple_gvn.rs b/lib/cretonne/src/simple_gvn.rs index 40d0ecf527..20e2298440 100644 --- a/lib/cretonne/src/simple_gvn.rs +++ b/lib/cretonne/src/simple_gvn.rs @@ -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::*;