Skip to content

[Fix][Relax] Preserve impure calls with unused tuple outputs - #20816

Merged
tlopex merged 1 commit into
apache:mainfrom
hiyufan:fix/preserve-impure-unused-outputs-20592
Nov 15, 2026
Merged

tlopex merged 1 commit into
apache:mainfrom
hiyufan:fix/preserve-impure-unused-outputs-20592

Conversation

@hiyufan

@hiyufan hiyufan commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

When every tuple output of an impure private function is unused, RemoveUnusedOutputs drops the call and its side effects. A callee containing R.print, for example, no longer prints after the pass.

Skip output pruning only for an impure callee whose output-usage mask is entirely false. Preserve its call and return signature. Pure callees and impure callees with partially used outputs keep the existing pruning behavior.

Fixes #20592.

Validation against main a0ffe06def, Python 3.11 and source-built pinned TIRx/FFI dependencies:

  • Existing test_transform_remove_unused_outputs.py, test_transform_dead_code_elimination.py, and test_transform_canonicalize_bindings.py: 58 passed, 1 existing xfailed.
  • The local unused-impure-call reproducer retains its printed side effect and returned tensor after the pass; an unused pure-call control is still removed.
  • File-scoped pre-commit checks passed.

Prepared with OpenAI Codex assistance. The build and validation above were executed locally. Fresh CI results for this revision are pending.

@hiyufan
hiyufan marked this pull request as ready for review October 25, 2026 11:27
@hiyufan
hiyufan force-pushed the fix/preserve-impure-unused-outputs-20592 branch from 7cf1c8b to eb6d479 Compare November 15, 2026 02:51
@hiyufan

hiyufan commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

@tlopex, would you have time to review this follow-up to RemoveUnusedOutputs? When all tuple fields of an impure callee are unused, the current rewrite drops the call and its side effects. This change preserves the callee signature only in that case; pure and partially used cases retain the existing pruning.

I've rebased onto current main and rerun the pass, DCE and canonicalization suites (64 passed, one existing xfail). The added VM cases check exact print counts and returned values before/after the pass. Fresh CI results are pending. Thank you.

@hiyufan
hiyufan force-pushed the fix/preserve-impure-unused-outputs-20592 branch from eb6d479 to 80dd7f1 Compare November 15, 2026 03:38

@tlopex tlopex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we simplify the tests and rebase onto main?

@hiyufan
hiyufan force-pushed the fix/preserve-impure-unused-outputs-20592 branch from 80dd7f1 to ffed390 Compare November 15, 2026 06:27
@hiyufan

hiyufan commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review, @tlopex. Rebased onto current main (f0267a0a3e) and simplified the tests: removed the parameterized BlockBuilder/execution matrix and redundant computation, retaining two focused IR regressions and a single side-effect execution check.

The impure regression still fails without the fix. With the fix, the pass/DCE/canonicalization suites report 60 passed and one existing xfail. File-scoped pre-commit checks also pass. Fresh CI results are pending.

@tlopex

tlopex commented Nov 15, 2026

Copy link
Copy Markdown
Member

actually I don't think we need to add extra tests for this. Could you just preserve the fix?

@hiyufan
hiyufan force-pushed the fix/preserve-impure-unused-outputs-20592 branch from ffed390 to 001855c Compare November 15, 2026 06:56
@hiyufan

hiyufan commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Done, @tlopex. Removed all added tests and rebased onto current main. The PR now contains one commit changing only remove_unused_outputs.cc with the six-line fix.

The existing pass/DCE/canonicalization suites report 58 passed and one existing xfail. The side-effect reproducer also passes locally. Fresh CI results are pending. Thanks for the guidance.

@tlopex
tlopex merged commit 23a6dbe into apache:main Nov 15, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][Relax] RemoveUnusedOutputs drops impure calls when tuple outputs are unused

2 participants