remove noop reshapes (#16849)

This commit is contained in:
George Hotz
2026-07-03 11:39:57 -07:00
committed by GitHub
parent ed7981f8f2
commit ed3dec4674
+2
View File
@@ -125,6 +125,8 @@ def split_reduceop(reduce:UOp, x:UOp):
mop_cleanup = PatternMatcher([
# merge adjacent RESHAPES
(UPat(Ops.RESHAPE, src=(UPat(Ops.RESHAPE, name="x2"), UPat()), name="x"), lambda x,x2: x.replace(src=(x2.src[0], x.src[1]))),
# remove noop RESHAPEs
(UPat(Ops.RESHAPE, src=(UPat(name="x2"), UPat()), name="x"), lambda x,x2: x2 if x2._shape is not None and x2.shape == x.shape else None),
])
pm_gather_params = PatternMatcher([ (UPat(Ops.PARAM, name="p"), lambda ctx, p: ctx.append(p) if p.arg.slot >= 0 else None), ])