Make const moving not depend on the order (#9245)

Since floats are not being flipped anymore this should help with const
folding for floats
This commit is contained in:
Sieds Lykles
2025-03-03 09:09:27 +01:00
committed by GitHub
parent 2cc4cb74f0
commit 27e899aea5

View File

@@ -213,8 +213,8 @@ symbolic = symbolic_simple+PatternMatcher([
((UPat.var("x", dtype=dtypes.ints)//UPat.cvar("c0", vec=False))<UPat.cvar("c1", vec=False),
lambda x,c0,c1: x<(c1.arg*c0.arg) if c0.arg > 0 else None),
# ** move add/mul consts to end (NOTE: this is still happening before constant folding) **
(UPat(Ops.ADD, src=(UPat.var("x"), UPat.cvar("c1"))) + UPat.var("y"), lambda x,c1,y: (x+y)+c1),
(UPat(Ops.MUL, src=(UPat.var("x"), UPat.cvar("c1"))) * UPat.var("y"), lambda x,c1,y: (x*y)*c1),
((UPat.var("x") + UPat.cvar("c1")) + UPat.var("y"), lambda x,c1,y: (x+y)+c1),
((UPat.var("x") * UPat.cvar("c1")) * UPat.var("y"), lambda x,c1,y: (x*y)*c1),
# *** rules from symbolic ***
# unrolled arange div folding
(UPat(Ops.ADD, name="divs", src=[UPat(), UPat(Ops.IDIV)]), fold_unrolled_divs),