From b970ff1850ba88717d11a9ced55fb83334b38ffe Mon Sep 17 00:00:00 2001 From: Max Bernstein Date: Tue, 29 Apr 2025 12:27:10 -0400 Subject: [PATCH] Default instruction output type to Any If we're adding a bunch of instructions in the middle of an optimization pass, we don't want to use their (currently uninitialized) types because they start as Empty, and Empty is a subtype of everything. This breaks some optimizations. This Any will get refined the next time we call infer_types. --- zjit/src/hir.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/zjit/src/hir.rs b/zjit/src/hir.rs index 24b7cb6a0e..300d0d85ac 100644 --- a/zjit/src/hir.rs +++ b/zjit/src/hir.rs @@ -666,8 +666,12 @@ impl Function { // Add an instruction to the function without adding it to any block fn new_insn(&mut self, insn: Insn) -> InsnId { let id = InsnId(self.insns.len()); + if insn.has_output() { + self.insn_types.push(types::Any); + } else { + self.insn_types.push(types::Empty); + } self.insns.push(insn); - self.insn_types.push(types::Empty); id } @@ -2854,8 +2858,8 @@ mod opt_tests { bb0(): PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_PLUS) PatchPoint BOPRedefined(INTEGER_REDEFINED_OP_FLAG, BOP_PLUS) - v14:Fixnum[6] = Const Value(6) - Return v14 + v15:Fixnum[6] = Const Value(6) + Return v15 "#]]); }