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

@@ -250,6 +250,27 @@ block0(v0: i32):
; check: return v2
}
function %mul_minus_one(i32) -> i32 {
block0(v0: i32):
v1 = iconst.i32 0xffff_ffff ; -1
v2 = imul v0, v1
return v2
; check: v3 = ineg v0
; check: v4 -> v3
; check: return v3
}
function %mul_minus_one_commuted(i32) -> i32 {
block0(v0: i32):
v1 = iconst.i32 0xffff_ffff ; -1
v2 = imul v1, v0
return v2
; check: v3 = ineg v0
; check: v5 -> v3
; check: v6 -> v3
; check: return v3
}
function %or_and_y_with_not_y_i8(i8, i8) -> i8 {
block0(v0: i8, v1: i8):
v2 = band v0, v1