Skip to content

Compare a kept loop forest with a fresh one by what it says, not by block order - #3708

Merged
tamnd merged 2 commits into
mainfrom
opt/forest-check
Oct 16, 2026
Merged

tamnd merged 2 commits into
mainfrom
opt/forest-check

Conversation

@tamnd

@tamnd tamnd commented Oct 16, 2026

Copy link
Copy Markdown
Owner

The "instrumented libraries that have to be right" job on main fails on zlib at -O2 with the short-circuit pass said it preserved the loop forest of gz_decomp and did not [E0652]. It reproduces on the Linux box with rucc -S -O2 -Zverify-each gzread.c, with or without -fsafety.

The forest was right. Short-circuit keeps the loop forest through each merge with Loops::merged, and a forest kept that way lists a loop's blocks in the order it found them before the merge. A fresh build after the merge found the new latch second rather than last. Printing both forests for gz_decomp showed that one block moving in the list and nothing else. The -Zverify-each check compared the two with ==, so it took the order for a difference. The debug assertion in clear_merging already compared them with Loops::summary, which sorts every list, and that is what the check now uses too. summary is no longer debug only.

The new test in analysis.rs is the smallest shape that does it, a loop of three blocks whose latch is folded into the block above it. It fails on the old check and passes now.

Checked on the Linux box: cargo test -p rucc-opt (1,938 unit tests and the integration tests) passes, cargo clippy -p rucc-opt --all-targets -- -D warnings and cargo fmt --all --check are clean, and every zlib 1.3.1 source compiles with -O2 -Zverify-each.

…order it lists blocks in

Short-circuit keeps the loop forest through each merge. A forest kept that way lists a loop's blocks in the order it found them before the merge, and a fresh build can find the new latch earlier. The -Zverify-each check compared the two with ==, so it called a correct forest stale and the compile failed with E0652, which is how zlib's gzread.c failed at -O2 in the instrumented libraries job. The check now compares the order-free summary the debug assertion in clear_merging already used.
@tamnd tamnd added kind/bug Crash, wrong diagnostic, or a valid program rejected area/optimizer Pass manager, the aegraph, rewrite rules, analyses labels Oct 16, 2026
@tamnd
tamnd merged commit ee23ac3 into main Oct 16, 2026
@tamnd
tamnd deleted the opt/forest-check branch October 16, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/optimizer Pass manager, the aegraph, rewrite rules, analyses kind/bug Crash, wrong diagnostic, or a valid program rejected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant