Cranelift: Add egraph rule to rewrite x * C ==> x << log2(C) when C is a power of two (#5647)
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
34
cranelift/filetests/filetests/egraph/mul-pow-2.clif
Normal file
34
cranelift/filetests/filetests/egraph/mul-pow-2.clif
Normal 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
|
||||
}
|
||||
@@ -107,6 +107,12 @@ pub trait SubTest {
|
||||
|
||||
/// Run filecheck on `text`, using directives extracted from `context`.
|
||||
pub fn run_filecheck(text: &str, context: &Context) -> anyhow::Result<()> {
|
||||
log::debug!(
|
||||
"Filecheck Input:\n\
|
||||
=======================\n\
|
||||
{text}\n\
|
||||
======================="
|
||||
);
|
||||
let checker = build_filechecker(context)?;
|
||||
if checker
|
||||
.check(text, NO_VARIABLES)
|
||||
|
||||
Reference in New Issue
Block a user