This is an automated email from the ASF dual-hosted git repository.

tlopex pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 23a6dbe710 [Fix][Relax] Preserve impure calls with unused tuple 
outputs (#20816)
23a6dbe710 is described below

commit 23a6dbe710dfcd445a090af1c49c8d7e8a57fb10
Author: Chen Yufan <[email protected]>
AuthorDate: Mon Nov 16 03:10:07 2026 +0800

    [Fix][Relax] Preserve impure calls with unused tuple outputs (#20816)
    
    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.
---
 src/relax/transform/remove_unused_outputs.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/relax/transform/remove_unused_outputs.cc 
b/src/relax/transform/remove_unused_outputs.cc
index 7a6a72456b..bf1c073da7 100644
--- a/src/relax/transform/remove_unused_outputs.cc
+++ b/src/relax/transform/remove_unused_outputs.cc
@@ -239,6 +239,12 @@ Pass RemoveUnusedOutputs() {
         if (auto func = base_func.as<Function>()) {
           if (auto it = usage.find(gvar); it != usage.end()) {
             const auto& usage_mask = it->second;
+            if (!func.value()->is_pure && std::none_of(usage_mask.begin(), 
usage_mask.end(),
+                                                       [](bool used) { return 
used; })) {
+              // With no used outputs, the callsite rewrite would drop the call
+              // entirely.  Preserve impure calls for their side effects.
+              continue;
+            }
             auto new_func = UpdateCallee(func.value(), usage_mask);
 
             GlobalVar new_gvar(gvar->name_hint);

Reply via email to