From 0f34eb745d437c161c5343c3a8c9d8cef2a23440 Mon Sep 17 00:00:00 2001 From: Ekaterina Ignasheva Date: Fri, 5 Dec 2025 14:26:37 -0800 Subject: [PATCH] Fix modified flag for RemovePermutesAroundElementwiseOps (#16047) Summary: This change fixes an issue where the `RemovePermutesAroundElementwiseOps` pass was not correctly returning the modified flag to indicate whether the graph was changed during the optimization. The modified flag is crucial for the pass manager to determine if additional passes need to be run or if the optimization has reached a fixed point. Without properly returning this flag, the pass manager may not iterate correctly or may run unnecessary additional passes. Reviewed By: hsharma35 Differential Revision: D88109865 --- backends/cadence/aot/remove_ops.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backends/cadence/aot/remove_ops.py b/backends/cadence/aot/remove_ops.py index 9dc695c68af..98102a415e5 100644 --- a/backends/cadence/aot/remove_ops.py +++ b/backends/cadence/aot/remove_ops.py @@ -566,13 +566,17 @@ def call(self, graph_module: torch.fx.GraphModule) -> PassResult: for node in subgraph.nodes: processed_nodes.add(node) + modified = False for subgraph in subgraphs_found: self.permute_subgraph(subgraph) + modified = True - graph_module.graph.eliminate_dead_code() - graph_module.recompile() + if modified: + graph_module.graph.eliminate_dead_code() + graph_module.recompile() + return super().call(graph_module) - return super().call(graph_module) + return PassResult(graph_module, False) def visit( self,