[zeek/spicy] 0c87a5: Implement optimizer pass to `move` last uses

0 views
Skip to first unread message

Evan Typanski

unread,
Jul 15, 2026, 3:50:43 PM (11 days ago) Jul 15
to spicy-...@zeek.org
Branch: refs/heads/topic/etyp/move-last-uses
Home: https://github.com/zeek/spicy
Commit: 0c87a5b46433d63ddddc851183bb433e2548b302
https://github.com/zeek/spicy/commit/0c87a5b46433d63ddddc851183bb433e2548b302
Author: Evan Typanski <evan.t...@corelight.com>
Date: 2026-07-15 (Wed, 15 Jul 2026)

Changed paths:
M hilti/toolchain/CMakeLists.txt
M hilti/toolchain/include/ast/type.h
M hilti/toolchain/include/ast/types/address.h
M hilti/toolchain/include/ast/types/bool.h
M hilti/toolchain/include/ast/types/enum.h
M hilti/toolchain/include/ast/types/integer.h
M hilti/toolchain/include/ast/types/interval.h
M hilti/toolchain/include/ast/types/network.h
M hilti/toolchain/include/ast/types/port.h
M hilti/toolchain/include/ast/types/real.h
M hilti/toolchain/include/ast/types/time.h
M hilti/toolchain/include/compiler/detail/optimizer/pass-id.h
A hilti/toolchain/src/compiler/optimizer/passes/move-last-uses.cc
M tests/Baseline/hilti.cfg.dead-write-shadowed/output
M tests/Baseline/hilti.cfg.local-struct-value/output
M tests/Baseline/hilti.cfg.unreachable-return/output
M tests/Baseline/hilti.optimization.dataflow-unreachable/output
M tests/Baseline/hilti.optimization.unimplemented_hook/log
M tests/Baseline/hilti.optimization.unreachable-code/log
M tests/Baseline/hilti.optimization.unused-init/output
M tests/Baseline/hilti.optimization.unused_function/log
M tests/Baseline/hilti.types.struct.on-heap/output
M tests/Baseline/spicy.optimization.default-parser-functions/log
M tests/Baseline/spicy.optimization.feature_requirements/log
M tests/Baseline/spicy.optimization.feature_requirements/opt.hlt
M tests/Baseline/spicy.optimization.unused-functions/log
M tests/Baseline/spicy.optimization.unused-types/log
A tests/hilti/output/optimization/move-last-uses.hlt

Log Message:
-----------
Implement optimizer pass to `move` last uses

Closes #1960

Adds an optimization pass that adds moves when it's the last use. This is
relatively conservative; it doesn't try to understand expression ordering
and won't move in many cases. But, in user-code (not generated parser
code) this could give a bit of a speedup.

The analysis is just a liveness analysis. If the name isn't live after a
CFG node, we theoretically can move it.

Whether or not a node is "trivially copyable" is up to that node to
determine. We could use this in more places that we generate moves as
well.


Commit: 2615a7b5fc0e3bf893f017e6d852b995befa936f
https://github.com/zeek/spicy/commit/2615a7b5fc0e3bf893f017e6d852b995befa936f
Author: Evan Typanski <evan.t...@corelight.com>
Date: 2026-07-15 (Wed, 15 Jul 2026)

Changed paths:
M hilti/toolchain/src/compiler/cfg.cc
M hilti/toolchain/src/compiler/optimizer/passes/move-last-uses.cc
M tests/Baseline/hilti.cfg.switch/output

Log Message:
-----------
Fix CFG for switch cases

The CFG was making many parallel branches for a switch:

switch (s)
/ | \
/ | \
/ | \
/ | \
/ | \
s == "a" s == "b" s == "c"
| | |
| | |
case A case B case C

But, that's not what's happening. In reality, the first case will compare
first, then the second, then the third: it's not a choice, it's a
sequential series of comparisons:

switch (s)
|
|
s == "a"
| \
| \
| case A
|
s == "b"
| \
| \
| case B
|
s == "c"
\
\
case C

This bug would make 's' appear dead after each case expression
(comparison with "a", "b", and "c") when in reality it's only dead after
the comparison with "c".

This just updated the switch CFG baselines, since including the test for
move last uses that caused it (basically a switch over multiple strings)
would require baselining C++, which is a bit brittle.


Compare: https://github.com/zeek/spicy/compare/6d001001cba0...2615a7b5fc0e

To unsubscribe from these emails, change your notification settings at https://github.com/zeek/spicy/settings/notifications
Reply all
Reply to author
Forward
0 new messages