Skip to content

Commit 529e110

Browse files
committed
Enable FDiv(x, x) = 1.0 for float redundant division
Uncomment the FDiv x/x rule that was disabled due to NaN/zero concerns. The Rust optimizer already assumes fast-math for all float rules (FSub(x,x)=0 fires unconditionally), making this consistent with existing behavior. Combined with the FNeg distribution rules (FDiv(FNeg(a),b) → FNeg(FDiv(a,b)) and FDiv(a,FNeg(b)) → FNeg(FDiv(a,b))), this also handles -x/x → -1.0 and x/(-x) → -1.0, matching the C++ FoldRedundantDiv behavior.
1 parent 725c6b1 commit 529e110

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@
111111
(rule ((= e (FDiv x (FConst c))) (= c -1.0))
112112
((union e (FNeg x))))
113113

114-
; x / x = 1 (assuming not zero or NaN)
115-
; Note: commented out due to NaN/zero concerns
116-
; (rewrite (FDiv x x) (FConst 1.0))
114+
; x / x = 1.0 (fast-math: assumes x is not zero or NaN) - ONE-DIRECTIONAL
115+
; Combined with FNeg distribution rules below, also handles -x/x and x/(-x)
116+
(rule ((= e (FDiv x x)))
117+
((union e (FConst 1.0))))
117118

118119
; x - x = 0 - ONE-DIRECTIONAL
119120
(rule ((= e (FSub x x)))

0 commit comments

Comments
 (0)