From 3532c3533a00b553d1ffb28345f903a1501e1cd7 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 30 Aug 2017 14:33:54 -0700 Subject: [PATCH] Teach simple_gvn that iconst.i32 is not congruent to iconst.i64. --- cranelift/filetests/simple_gvn/reject.cton | 14 ++++++++++++++ lib/cretonne/src/ir/types.rs | 2 +- lib/cretonne/src/simple_gvn.rs | 7 ++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cranelift/filetests/simple_gvn/reject.cton b/cranelift/filetests/simple_gvn/reject.cton index 755891ad5d..1bb6ad16fa 100644 --- a/cranelift/filetests/simple_gvn/reject.cton +++ b/cranelift/filetests/simple_gvn/reject.cton @@ -9,3 +9,17 @@ ebb0(v0: i32): ; check: regmove v0, %10 -> %20 return v0 } + +function %differing_typevars() -> i64 { +ebb0: + v0 = iconst.i32 7 + v1 = iconst.i64 7 + v2 = iconst.i64 8 +; check: v0 = iconst.i32 7 +; check: v1 = iconst.i64 7 +; check: v2 = iconst.i64 8 + v3 = uextend.i64 v0 + v4 = iadd v2, v1 + v5 = iadd v4, v3 + return v5 +} diff --git a/lib/cretonne/src/ir/types.rs b/lib/cretonne/src/ir/types.rs index 0007154025..275ec70c9b 100644 --- a/lib/cretonne/src/ir/types.rs +++ b/lib/cretonne/src/ir/types.rs @@ -23,7 +23,7 @@ use std::fmt::{self, Display, Debug, Formatter}; /// /// SIMD vector types have power-of-two lanes, up to 256. Lanes can be any int/float/bool type. /// -#[derive(Copy, Clone, PartialEq, Eq)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] pub struct Type(u8); /// No type. Used for functions without a return value. Can't be loaded or stored. Can't be part of diff --git a/lib/cretonne/src/simple_gvn.rs b/lib/cretonne/src/simple_gvn.rs index 2d1c5a7e61..8a8022ed2d 100644 --- a/lib/cretonne/src/simple_gvn.rs +++ b/lib/cretonne/src/simple_gvn.rs @@ -2,7 +2,7 @@ use flowgraph::ControlFlowGraph; use dominator_tree::DominatorTree; -use ir::{Cursor, CursorBase, InstructionData, Function, Inst, Opcode}; +use ir::{Cursor, CursorBase, InstructionData, Function, Inst, Opcode, Type}; use std::collections::HashMap; /// Test whether the given opcode is unsafe to even consider for GVN. @@ -14,7 +14,7 @@ fn trivially_unsafe_for_gvn(opcode: Opcode) -> bool { /// Perform simple GVN on `func`. /// pub fn do_simple_gvn(func: &mut Function, cfg: &mut ControlFlowGraph) { - let mut visible_values: HashMap = HashMap::new(); + let mut visible_values: HashMap<(InstructionData, Type), Inst> = HashMap::new(); let domtree = DominatorTree::with_function(func, cfg); @@ -26,6 +26,7 @@ pub fn do_simple_gvn(func: &mut Function, cfg: &mut ControlFlowGraph) { 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); @@ -42,7 +43,7 @@ pub fn do_simple_gvn(func: &mut Function, cfg: &mut ControlFlowGraph) { continue; } - let key = func.dfg[inst].clone(); + let key = (func.dfg[inst].clone(), ctrl_typevar); let entry = visible_values.entry(key); use std::collections::hash_map::Entry::*; match entry {