cranelift: rewrite x*-1 to ineg(x) (#6052)

* cranelift: rewrite `x*-1` to `ineg(x)`

* Add commuted test
This commit is contained in:
Karl Meakin
2023-03-17 19:52:13 +00:00
committed by GitHub
parent c3f5b71b6a
commit 208d09e9f0
2 changed files with 29 additions and 0 deletions

View File

@@ -62,6 +62,14 @@
_))
(subsume zero))
;; x*-1 == -1*x == ineg(x).
(rule (simplify (imul ty x (iconst ty c)))
(if-let -1 (i64_sextend_imm64 ty c))
(ineg ty x))
(rule (simplify (imul ty (iconst ty c) x))
(if-let -1 (i64_sextend_imm64 ty c))
(ineg ty x))
;; x/1 == x.
(rule (simplify (sdiv ty
x