Skip to content

Commit 9f48dae

Browse files
committed
feat: inst simplify
1 parent d9a54d7 commit 9f48dae

File tree

7 files changed

+45
-100
lines changed

7 files changed

+45
-100
lines changed

libs/@local/hashql/mir/src/pass/transform/inst_simplify/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ use crate::{
107107
location::Location,
108108
operand::Operand,
109109
place::Place,
110-
rvalue::{BinOp, Binary, RValue, Unary},
110+
rvalue::{Aggregate, AggregateKind, BinOp, Binary, RValue, Unary},
111111
statement::Assign,
112112
},
113113
context::MirContext,
@@ -503,6 +503,19 @@ impl<'heap, A: Allocator> VisitorMut<'heap> for InstSimplifyVisitor<'_, 'heap, A
503503
Ok(())
504504
}
505505

506+
fn visit_rvalue_aggregate(
507+
&mut self,
508+
_: Location,
509+
aggregate: &mut Aggregate<'heap>,
510+
) -> Self::Result<()> {
511+
// Specialize into a unit if it's an empty tuple
512+
if aggregate.kind == AggregateKind::Tuple && aggregate.operands.is_empty() {
513+
self.trampoline = Some(RValue::Load(Operand::Constant(Constant::Unit)));
514+
}
515+
516+
Ok(())
517+
}
518+
506519
fn visit_statement_assign(
507520
&mut self,
508521
location: Location,

libs/@local/hashql/mir/src/pass/transform/inst_simplify/tests.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ fn assert_inst_simplify_pass<'heap>(
6464
assert_snapshot!(name, value);
6565
}
6666

67-
// =============================================================================
68-
// Constant Folding (Bitwise on integers, Unary - not in source language)
69-
// =============================================================================
70-
7167
/// Tests constant folding for bitwise AND on integers.
7268
#[test]
7369
fn const_fold_bit_and() {
@@ -180,10 +176,6 @@ fn const_fold_unary_neg() {
180176
);
181177
}
182178

183-
// =============================================================================
184-
// Bitwise Identity on Integers (x | 0 => x - not in source language)
185-
// =============================================================================
186-
187179
/// Tests identity simplification for bitwise OR with zero.
188180
#[test]
189181
fn identity_bit_or_zero() {
@@ -212,10 +204,6 @@ fn identity_bit_or_zero() {
212204
);
213205
}
214206

215-
// =============================================================================
216-
// Identical Operand Patterns (BitAnd/BitOr on integers - not in source)
217-
// =============================================================================
218-
219207
/// Tests idempotent simplification for bitwise AND with identical operands.
220208
#[test]
221209
fn identical_operand_bit_and() {
@@ -272,10 +260,6 @@ fn identical_operand_bit_or() {
272260
);
273261
}
274262

275-
// =============================================================================
276-
// Block Parameter Propagation (requires CFG control)
277-
// =============================================================================
278-
279263
/// Tests constant propagation through block params with single predecessor.
280264
#[test]
281265
fn block_param_single_predecessor() {
@@ -381,10 +365,6 @@ fn block_param_predecessors_disagree() {
381365
);
382366
}
383367

384-
// =============================================================================
385-
// Idempotent to Constant Forwarding (requires bitwise op)
386-
// =============================================================================
387-
388368
/// Tests that idempotent simplification propagates constants through the result.
389369
#[test]
390370
fn idempotent_to_const_forwarding() {

libs/@local/hashql/mir/tests/ui/pass/inline/closure-inline.stdout

Lines changed: 6 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/@local/hashql/mir/tests/ui/pass/inline/heuristic-inline.stdout

Lines changed: 15 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)