diff --git a/tinygrad/codegen/late/control_flow.py b/tinygrad/codegen/late/control_flow.py index b58ac5fc3e..b3173c5535 100644 --- a/tinygrad/codegen/late/control_flow.py +++ b/tinygrad/codegen/late/control_flow.py @@ -99,4 +99,6 @@ class CFGContext: pm_control_flow_starts = PatternMatcher([ (UPat((Ops.RANGE, Ops.IF), src=(UPat(),), name="x"), lambda ctx,x: x.replace(src=x.src+(y,)) if (y:=ctx.edges.get(x)) is not None else None), (UPat(Ops.IF, src=(UPat(), UPat(Ops.BARRIER)), name="x"), lambda ctx,x: x.replace(src=x.src+(y,)) if (y:=ctx.edges.get(x)) is not None else None), + # remove ranges from STORE. keep NOOP since they determine ordering + (UPat(Ops.STORE, name="s"), lambda s: s.replace(src=s.src[0:2]+tuple([x for x in s.src[2:] if x.op not in {Ops.RANGE, Ops.CONST}]))), ]) diff --git a/tinygrad/uop/ops.py b/tinygrad/uop/ops.py index 6a6ab687cb..ef25e1bd48 100644 --- a/tinygrad/uop/ops.py +++ b/tinygrad/uop/ops.py @@ -235,7 +235,8 @@ class UOp(MathTrait, metaclass=UOpMetaClass): ret: dict[UOp, None] = {} if self.op is Ops.ENDRANGE: for s in self.src[1:]: ret.update(s.ranges) - assert self.src[0] not in ret + # NOTE: the ended range should always be in the ranges + if self.src[0] in ret: del ret[self.src[0]] elif self.op in range_start.keys(): for s in self.src[:range_start[self.op]]: ret.update(s.ranges) for s in UOp.sink(*self.src[range_start[self.op]:]).ranges: