diff --git a/dace/transformation/passes/constant_propagation.py b/dace/transformation/passes/constant_propagation.py index 19e17066fa..d95b72ab28 100644 --- a/dace/transformation/passes/constant_propagation.py +++ b/dace/transformation/passes/constant_propagation.py @@ -369,6 +369,14 @@ def _collect_constants_for_region(self, cfg: ControlFlowRegion, arrays: Set[str] if reassignments and (used_in_assignments - reassignments): assignments[aname] = _UnknownValue + if isinstance(block, LoopRegion): + # Any constants before a loop that may be overwritten inside the loop cannot be assumed as constants + # for the loop itself. + assigned_in_loop = self._assignments_in_loop(block) + for k in assignments.keys(): + if k in assigned_in_loop: + assignments[k] = _UnknownValue + if block not in in_const_dict: in_const_dict[block] = {} if assignments: