diff --git a/cranelift/codegen/src/context.rs b/cranelift/codegen/src/context.rs index f8a111655ea2..856bb40856ad 100644 --- a/cranelift/codegen/src/context.rs +++ b/cranelift/codegen/src/context.rs @@ -183,6 +183,8 @@ impl Context { self.eliminate_unreachable_code(isa)?; self.remove_constant_phis(isa)?; + self.func.dfg.resolve_all_aliases(); + if opt_level != OptLevel::None { self.egraph_pass(isa, ctrl_plane)?; } diff --git a/cranelift/codegen/src/egraph.rs b/cranelift/codegen/src/egraph.rs index 02e28770699c..2e48d3a78d1f 100644 --- a/cranelift/codegen/src/egraph.rs +++ b/cranelift/codegen/src/egraph.rs @@ -567,10 +567,6 @@ impl<'a> EgraphPass<'a> { /// only refer to its subset that exists at this stage, to /// maintain acyclicity.) fn remove_pure_and_optimize(&mut self) { - // This pass relies on every value having a unique name, so first - // eliminate any value aliases. - self.func.dfg.resolve_all_aliases(); - let mut cursor = FuncCursor::new(self.func); let mut value_to_opt_value: SecondaryMap = SecondaryMap::with_default(Value::reserved_value()); diff --git a/cranelift/codegen/src/machinst/lower.rs b/cranelift/codegen/src/machinst/lower.rs index 8a99cd83f919..f74faa6eb9a5 100644 --- a/cranelift/codegen/src/machinst/lower.rs +++ b/cranelift/codegen/src/machinst/lower.rs @@ -532,7 +532,7 @@ impl<'func, I: VCodeInst> Lower<'func, I> { // Iterate over all values used by all instructions, noting an // additional use on each operand. for arg in f.dfg.inst_values(inst) { - let arg = f.dfg.resolve_aliases(arg); + debug_assert!(f.dfg.value_is_real(arg)); let old = value_ir_uses[arg]; if force_multiple { trace!( @@ -555,7 +555,7 @@ impl<'func, I: VCodeInst> Lower<'func, I> { } while let Some(iter) = stack.last_mut() { if let Some(value) = iter.next() { - let value = f.dfg.resolve_aliases(value); + debug_assert!(f.dfg.value_is_real(value)); trace!(" -> DFS reaches {}", value); if value_ir_uses[value] == ValueUseState::Multiple { // Truncate DFS here: no need to go further, @@ -563,7 +563,7 @@ impl<'func, I: VCodeInst> Lower<'func, I> { // With debug asserts, check one level of // that invariant at least. debug_assert!(uses(value).into_iter().flatten().all(|arg| { - let arg = f.dfg.resolve_aliases(arg); + debug_assert!(f.dfg.value_is_real(arg)); value_ir_uses[arg] == ValueUseState::Multiple })); continue; @@ -835,13 +835,12 @@ impl<'func, I: VCodeInst> Lower<'func, I> { fn get_value_labels<'a>(&'a self, val: Value, depth: usize) -> Option<&'a [ValueLabelStart]> { if let Some(ref values_labels) = self.f.dfg.values_labels { + debug_assert!(self.f.dfg.value_is_real(val)); trace!( - "get_value_labels: val {} -> {} -> {:?}", + "get_value_labels: val {} -> {:?}", val, - self.f.dfg.resolve_aliases(val), - values_labels.get(&self.f.dfg.resolve_aliases(val)) + values_labels.get(&val) ); - let val = self.f.dfg.resolve_aliases(val); match values_labels.get(&val) { Some(&ValueLabelAssignments::Starts(ref list)) => Some(&list[..]), Some(&ValueLabelAssignments::Alias { value, .. }) if depth < 10 => { @@ -971,7 +970,7 @@ impl<'func, I: VCodeInst> Lower<'func, I> { let mut branch_arg_vregs: SmallVec<[Reg; 16]> = smallvec![]; for &arg in branch_args { - let arg = self.f.dfg.resolve_aliases(arg); + debug_assert!(self.f.dfg.value_is_real(arg)); let regs = self.put_value_in_regs(arg); branch_arg_vregs.extend_from_slice(regs.regs()); } @@ -1222,7 +1221,8 @@ impl<'func, I: VCodeInst> Lower<'func, I> { /// not be codegen'd (it has been integrated into the current instruction). pub fn input_as_value(&self, ir_inst: Inst, idx: usize) -> Value { let val = self.f.dfg.inst_args(ir_inst)[idx]; - self.f.dfg.resolve_aliases(val) + debug_assert!(self.f.dfg.value_is_real(val)); + val } /// Like `get_input_as_source_or_const` but with a `Value`. @@ -1322,7 +1322,7 @@ impl<'func, I: VCodeInst> Lower<'func, I> { /// Put the given value into register(s) and return the assigned register. pub fn put_value_in_regs(&mut self, val: Value) -> ValueRegs { - let val = self.f.dfg.resolve_aliases(val); + debug_assert!(self.f.dfg.value_is_real(val)); trace!("put_value_in_regs: val {}", val); if let Some(inst) = self.f.dfg.value_def(val).inst() {