Skip to content

Commit f752d2a

Browse files
committed
Disable GammaF hoisting rules that cause egraph explosion on mouse-shader
GammaF(c, FDiv(x,a), FDiv(x,b)) accumulated 1.37M matches at iter 6, exploding the egraph from 7K to 195K tuples. New FMul/FDiv/GammaF nodes feed back into reciprocal, negation distribution, and select absorption rules creating a multi-way amplification loop. Also proactively disables FAdd hoisting which has the same feedback structure via FAdd associativity. Integer GammaI hoisting rules are kept as they lack the amplifying rules.
1 parent ccfe7ee commit f752d2a

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,10 +418,15 @@
418418
; ((union e (GammaF c (FMul a x) (FMul b y)))))
419419

420420
; Hoisting common factors OUT of GammaF - ONE-DIRECTIONAL
421-
(rule ((= e (GammaF c (FAdd x a) (FAdd x b))))
422-
((union e (FAdd x (GammaF c a b)))))
423-
(rule ((= e (GammaF c (FMul x a) (FMul x b))))
424-
((union e (FMul x (GammaF c a b)))))
421+
; DISABLED: GammaF hoisting for FAdd/FMul/FDiv causes egraph explosion on mouse-shader.
422+
; New FMul/FDiv/GammaF nodes feed back into floating-point rules (reciprocals, negation
423+
; distribution, select absorption) and other GammaF distribution rules, creating a
424+
; multi-way amplification loop. FMul: 73K matches, FDiv: 1.37M matches at iter 6.
425+
; FAdd not flagged yet but has identical feedback structure via FAdd associativity.
426+
; (rule ((= e (GammaF c (FAdd x a) (FAdd x b))))
427+
; ((union e (FAdd x (GammaF c a b)))))
428+
; (rule ((= e (GammaF c (FMul x a) (FMul x b))))
429+
; ((union e (FMul x (GammaF c a b)))))
425430

426431
; =============================================================================
427432
; Theta (Loop) Optimization Rules - ONE-DIRECTIONAL
@@ -762,21 +767,26 @@
762767

763768
; Division operations: select(c, a / x, b / x) = select(c, a, b) / x - ONE-DIRECTIONAL
764769
; Integer division uses GammaI
770+
; NOTE: Integer GammaI hoisting rules are kept because integer arithmetic lacks the
771+
; associativity and reciprocal rules that amplify the float explosion. Monitor if
772+
; integer-heavy shaders cause similar issues (see floating_point.egg factoring notes).
765773
(rule ((= e (GammaI c (SDiv a x) (SDiv b x))))
766774
((union e (SDiv (GammaI c a b) x))))
767775
(rule ((= e (GammaI c (UDiv a x) (UDiv b x))))
768776
((union e (UDiv (GammaI c a b) x))))
769777
; Float division uses GammaF
770-
(rule ((= e (GammaF c (FDiv a x) (FDiv b x))))
771-
((union e (FDiv (GammaF c a b) x))))
778+
; DISABLED: See FMul/FAdd hoisting comment above. 1,167 matches at iter 6 on mouse-shader.
779+
; (rule ((= e (GammaF c (FDiv a x) (FDiv b x))))
780+
; ((union e (FDiv (GammaF c a b) x))))
772781

773782
; Division with common dividend: select(c, x / a, x / b) = x / select(c, a, b) - ONE-DIRECTIONAL
774783
(rule ((= e (GammaI c (SDiv x a) (SDiv x b))))
775784
((union e (SDiv x (GammaI c a b)))))
776785
(rule ((= e (GammaI c (UDiv x a) (UDiv x b))))
777786
((union e (UDiv x (GammaI c a b)))))
778-
(rule ((= e (GammaF c (FDiv x a) (FDiv x b))))
779-
((union e (FDiv x (GammaF c a b)))))
787+
; DISABLED: See FMul/FAdd hoisting comment above. 1,370,111 matches at iter 6 on mouse-shader.
788+
; (rule ((= e (GammaF c (FDiv x a) (FDiv x b))))
789+
; ((union e (FDiv x (GammaF c a b)))))
780790

781791
; Remainder/modulo operations - ONE-DIRECTIONAL
782792
; Integer remainder/modulo uses GammaI

0 commit comments

Comments
 (0)