cranelift: simplify x-x to 0 (#6032)

* cranelift: simplify `x-x` to `0`

* Guard `x-x => 0` rewrite with `fits_in_64`
This commit is contained in:
Karl Meakin
2023-03-17 15:14:28 +00:00
committed by GitHub
parent 28371bfd40
commit b53d66e634
2 changed files with 11 additions and 0 deletions

View File

@@ -35,6 +35,9 @@
;; ineg(ineg(x)) == x. ;; ineg(ineg(x)) == x.
(rule (simplify (ineg ty (ineg ty x))) (subsume x)) (rule (simplify (ineg ty (ineg ty x))) (subsume x))
;; x-x == 0.
(rule (simplify (isub (fits_in_64 (ty_int ty)) x x)) (subsume (iconst ty (imm64 0))))
;; x*1 == 1*x == x. ;; x*1 == 1*x == x.
(rule (simplify (imul ty (rule (simplify (imul ty
x x

View File

@@ -232,6 +232,14 @@ block0(v0: i32):
; check: return v0 ; check: return v0
} }
function %isub_self(i32) -> i32 {
block0(v0: i32):
v1 = isub v0, v0
return v1
; check: v2 = iconst.i32 0
; check: return v2
}
function %or_and_y_with_not_y_i8(i8, i8) -> i8 { function %or_and_y_with_not_y_i8(i8, i8) -> i8 {
block0(v0: i8, v1: i8): block0(v0: i8, v1: i8):
v2 = band v0, v1 v2 = band v0, v1