[zeek/spicy] 7b2cc2: Implement optimizer pass to `move` last uses

0 views
Skip to first unread message

Evan Typanski

unread,
Jul 16, 2026, 9:58:43 AM (10 days ago) Jul 16
to spicy-...@zeek.org
Branch: refs/heads/topic/etyp/move-last-uses
Home: https://github.com/zeek/spicy
Commit: 7b2cc2aba7497279caef78528388704b3049b4e9
https://github.com/zeek/spicy/commit/7b2cc2aba7497279caef78528388704b3049b4e9
Author: Evan Typanski <evan.t...@corelight.com>
Date: 2026-07-16 (Thu, 16 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: d02ad9dee85bc5a5346a23fb2fd7767694f3eaf5
https://github.com/zeek/spicy/commit/d02ad9dee85bc5a5346a23fb2fd7767694f3eaf5
Author: Evan Typanski <evan.t...@corelight.com>
Date: 2026-07-16 (Thu, 16 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/2615a7b5fc0e...d02ad9dee85b

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