From e62e530b7ceb5cd1ae69ab15e746744905b752cc Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Mon, 24 Oct 2022 22:22:28 -0700 Subject: [PATCH] egraphs: fix fill-in-the-types logic for multiple projections of one value. (#5112) In particular, this was found to happen in #5099 because a `Result` projection node was not deduplicating across two separate `isplit`s that created it. (This is a separate issue we should also fix; `needs_dedup` is I think overly conservative because `Result` can project out a single value from a pure or impure node, but the projection itself should be treated like any other pure operator.) In any case, if we have a value `v0` and two separate `Result { value: v0, result: N, ty }` nodes, each of these will fill in the type `ty` for the `N`th output of `v0`, and the second will idempotently overwrite the first; we should loosen the assert so that it allows this case. Fixes #5099. Fixes #5100. --- cranelift/codegen/src/ir/dfg.rs | 2 +- cranelift/filetests/filetests/egraph/isplit.clif | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cranelift/codegen/src/ir/dfg.rs b/cranelift/codegen/src/ir/dfg.rs index f76c7a3517..50f62f8857 100644 --- a/cranelift/codegen/src/ir/dfg.rs +++ b/cranelift/codegen/src/ir/dfg.rs @@ -276,7 +276,7 @@ impl DataFlowGraph { /// Fill in the type of a value, only if currently invalid (as a placeholder). pub(crate) fn fill_in_value_type(&mut self, v: Value, ty: Type) { - debug_assert!(self.values[v].ty().is_invalid()); + debug_assert!(self.values[v].ty().is_invalid() || self.values[v].ty() == ty); self.values[v].set_type(ty); } diff --git a/cranelift/filetests/filetests/egraph/isplit.clif b/cranelift/filetests/filetests/egraph/isplit.clif index ef3d8513a8..e5cb3ea49d 100644 --- a/cranelift/filetests/filetests/egraph/isplit.clif +++ b/cranelift/filetests/filetests/egraph/isplit.clif @@ -16,3 +16,14 @@ block0(v0: i128): } ; run: %a(871558149430564685057836279141) == 2147483647 + +function %b(i128, i16) -> i16 { +block0(v0: i128, v1: i16): + v2, v3 = isplit v0 + v4 = rotr v1, v3 + v5, v6 = isplit v0 + v7 = rotr v4, v6 + return v7 +} + +; run: %b(1234, 56) == 56