Cranelift: Add egraph rule to rewrite x * C ==> x << log2(C) when C is a power of two (#5647)

This commit is contained in:
Nick Fitzgerald
2023-01-31 10:04:17 -08:00
committed by GitHub
parent 61270cdaed
commit c9d1c068bc
6 changed files with 64 additions and 4 deletions

View File

@@ -7,8 +7,8 @@ function %f0(i32) -> i32 {
block0(v0: i32):
v1 = iconst.i32 2
v2 = imul v0, v1
; check: v3 = iadd v0, v0
; check: return v3
; check: v5 = ishl v0, v4 ; v4 = 1
; check: return v5
return v2
}

View File

@@ -0,0 +1,34 @@
test optimize
set opt_level=speed
set use_egraphs=true
target x86_64
function %f0(i32) -> i32 {
block0(v0: i32):
v1 = iconst.i32 4
v2 = imul v0, v1
; check: v3 = iconst.i32 2
; nextln: v4 = ishl v0, v3
; check: return v4
return v2
}
function %f1(i32) -> i32 {
block0(v0: i32):
v1 = iconst.i32 8
v2 = imul v0, v1
; check: v3 = iconst.i32 3
; nextln: v4 = ishl v0, v3
; check: return v4
return v2
}
function %f2(i32) -> i32 {
block0(v0: i32):
v1 = iconst.i32 16
v2 = imul v0, v1
; check: v3 = iconst.i32 4
; nextln: v4 = ishl v0, v3
; check: return v4
return v2
}