Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cranelift: simplify fneg(fneg(x)) to x #6034

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cranelift/codegen/src/opts/algebraic.isle
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@
;; with the `bitselect` instruction, but the pattern is a bit more complicated
;; due to most bitselects-over-floats having bitcasts.

;; fneg(fneg(x)) == x.
(rule (simplify (fneg ty (fneg ty x))) (subsume x))

;; If both of the multiplied arguments to an `fma` are negated then remove
;; both of them since they cancel out.
(rule (simplify (fma ty (fneg ty x) (fneg ty y) z))
Expand Down
9 changes: 9 additions & 0 deletions cranelift/filetests/filetests/egraph/algebraic.clif
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,15 @@ block0(v1: i16):
; check: v4 = sextend.i64 v1
; check: return v4

function %double_fneg(f32) -> f32 {
block0(v1: f32):
v2 = fneg v1
v3 = fneg v2
return v3
}

; check: return v1

function %fma_double_fneg(f32, f32, f32) -> f32 {
block0(v1: f32, v2: f32, v3: f32):
v4 = fneg v1
Expand Down