Skip to content

Commit 416c293

Browse files
committed
Restore divide-by-zero guard on FDiv constant folding
In an e-graph where algebraic rules (FDiv(x,x)=1.0, FSub(x,x)=0.0) and constant-folding rules fire in the same saturation pass, producing NaN/Inf from 0.0/0.0 would equate FConst(NaN) with FConst(1.0), corrupting the e-graph. Keep the != 0.0 guard.
1 parent b81e14f commit 416c293

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
((union e (FConst (- a b)))))
4141
(rule ((= e (FMul (FConst a) (FConst b))))
4242
((union e (FConst (* a b)))))
43-
; Divide-by-zero produces IEEE 754 results: 0/0→NaN, x/0→±Inf
44-
(rule ((= e (FDiv (FConst a) (FConst b))))
43+
; Guard: skip divide-by-zero to avoid e-graph corruption.
44+
; FDiv(x,x)=1.0 and FSub(x,x)=0.0 algebraic rules fire in the same
45+
; saturation pass — producing NaN/Inf here would equate them with 1.0/0.0.
46+
(rule ((= e (FDiv (FConst a) (FConst b))) (!= b 0.0))
4547
((union e (FConst (/ a b)))))
4648
; Use float-neg primitive (sign bit flip) instead of 0.0 - a,
4749
; because IEEE 754: 0.0 - 0.0 = +0.0, but FNeg(+0.0) must be -0.0.

0 commit comments

Comments
 (0)