Skip to content

Commit 151c09a

Browse files
committed
Disable FMul/FDiv cross-interaction and GammaF select absorption rules
FDiv-to-FMul constant chain rules create feedback loop: new FMul nodes from FDiv(FMul(x,c1),c2)→FMul(x,c1/c2) feed back into FMul chain merge, which creates more FMul nodes that re-enter FDiv cross rules. 252K matches at iter 7 on mouse-shader with exponential growth. Pure FMul and FDiv constant chains are preserved. Also disables GammaF FMul select absorption which injects 599 new FMul nodes per iteration into the chain merging pipeline.
1 parent f752d2a commit 151c09a

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

rust/spirv-tools-opt/src/rules/floating_point.egg

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,19 @@
290290
((union e (FDiv x (FConst (* a b))))))
291291

292292
; (x * a) / b = x * (a / b)
293-
(rule ((= e (FDiv (FMul x (FConst a)) (FConst b)))
294-
(!= b 0.0))
295-
((union e (FMul x (FConst (/ a b))))))
293+
; DISABLED: FDiv→FMul cross-interaction creates feedback loop with FMul chain merging.
294+
; New FMul nodes from these rules feed back into FMul(FMul(x,c1),c2) chain merge,
295+
; which creates more FMul nodes that re-enter FDiv cross rules. 252K matches at iter 7
296+
; on mouse-shader with exponential growth. Pure FMul and FDiv chains are kept.
297+
; (rule ((= e (FDiv (FMul x (FConst a)) (FConst b)))
298+
; (!= b 0.0))
299+
; ((union e (FMul x (FConst (/ a b))))))
296300

297301
; (x / a) * b = x * (b / a)
298-
(rule ((= e (FMul (FDiv x (FConst a)) (FConst b)))
299-
(!= a 0.0))
300-
((union e (FMul x (FConst (/ b a))))))
302+
; DISABLED: Same feedback loop as above. 73K matches at iter 7 on mouse-shader.
303+
; (rule ((= e (FMul (FDiv x (FConst a)) (FConst b)))
304+
; (!= a 0.0))
305+
; ((union e (FMul x (FConst (/ b a))))))
301306

302307
; (x + a) + b = x + (a + b)
303308
(rule ((= e (FAdd (FAdd x (FConst a)) (FConst b))))

rust/spirv-tools-opt/src/rules/rvsdg.egg

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,13 @@
700700
(rule ((= e (GammaI c x (Mul x y))))
701701
((union e (Mul x (GammaI c (Const 1) y)))))
702702
; Float ops use GammaF and FConst
703-
(rule ((= e (GammaF c (FMul x y) x)))
704-
((union e (FMul x (GammaF c y (FConst 1.0))))))
705-
(rule ((= e (GammaF c x (FMul x y))))
706-
((union e (FMul x (GammaF c (FConst 1.0) y)))))
703+
; DISABLED: Creates 599 new FMul nodes that feed into FMul constant chain merging,
704+
; amplifying the exponential growth. This is a special case of the GammaF FMul
705+
; hoisting that was already disabled above (lines 428-429).
706+
; (rule ((= e (GammaF c (FMul x y) x)))
707+
; ((union e (FMul x (GammaF c y (FConst 1.0))))))
708+
; (rule ((= e (GammaF c x (FMul x y))))
709+
; ((union e (FMul x (GammaF c (FConst 1.0) y)))))
707710

708711
; Nested Gamma flattening (when inner condition relates to outer)
709712
; select(c, select(c, a, b), d) = select(c, a, d) - already have

0 commit comments

Comments
 (0)