Add early-stage optimization crate (#556)

* Add simple constant folding and folding tests
This commit is contained in:
Lachlan Sneff
2018-11-07 18:59:29 -05:00
committed by Dan Gohman
parent bdcc06eb15
commit 3409af7c07
22 changed files with 745 additions and 21 deletions

View File

@@ -0,0 +1,54 @@
test preopt
target x86_64
function %brz_fold() -> i32 {
ebb0:
v0 = bconst.b1 false
brz v0, ebb2
jump ebb1
ebb1:
v1 = iconst.i32 42
return v1
ebb2:
v2 = iconst.i32 24
return v2
}
; sameln: function %brz_fold
; nextln: ebb0:
; nextln: v0 = bconst.b1 false
; nextln: jump ebb2
; nextln:
; nextln: ebb1:
; nextln: v1 = iconst.i32 42
; nextln: return v1
; nextln:
; nextln: ebb2:
; nextln: v2 = iconst.i32 24
; nextln: return v2
; nextln: }
function %brnz_fold() -> i32 {
ebb0:
v0 = bconst.b1 true
brnz v0, ebb2
jump ebb1
ebb1:
v1 = iconst.i32 42
return v1
ebb2:
v2 = iconst.i32 24
return v2
}
; sameln: function %brnz_fold
; nextln: ebb0:
; nextln: v0 = bconst.b1 true
; nextln: jump ebb2
; nextln:
; nextln: ebb1:
; nextln: v1 = iconst.i32 42
; nextln: return v1
; nextln:
; nextln: ebb2:
; nextln: v2 = iconst.i32 24
; nextln: return v2
; nextln: }

View File

@@ -0,0 +1,36 @@
test preopt
target x86_64
function %iadd_fold() -> i32 {
ebb0:
v0 = iconst.i32 37
v1 = iconst.i32 5
v2 = iadd v0, v1
v3 = iconst.i32 8
v4 = iadd v2, v3
return v4
}
; sameln: function %iadd_fold
; nextln: ebb0:
; nextln: v0 = iconst.i32 37
; nextln: v1 = iconst.i32 5
; nextln: v2 = iconst.i32 42
; nextln: v3 = iconst.i32 8
; nextln: v4 = iconst.i32 50
; nextln: return v4
; nextln: }
function %isub_fold() -> i32 {
ebb0:
v0 = iconst.i32 42
v1 = iconst.i32 1
v2 = isub v0, v1
return v2
}
; sameln: function %isub_fold
; nextln: ebb0:
; nextln: v0 = iconst.i32 42
; nextln: v1 = iconst.i32 1
; nextln: v2 = iconst.i32 41
; nextln: return v2
; nextln: }

View File

@@ -1,4 +1,4 @@
test preopt
test simple_preopt
target i686 baseline
; Cases where the denominator is created by an iconst

View File

@@ -1,4 +1,4 @@
test preopt
test simple_preopt
target i686 baseline
; -------- U32 --------

View File

@@ -1,4 +1,4 @@
test preopt
test simple_preopt
target i686 baseline
; -------- U32 --------

View File

@@ -1,4 +1,4 @@
test preopt
test simple_preopt
target i686 baseline
; -------- U32 --------

View File

@@ -1,4 +1,4 @@
test preopt
test simple_preopt
target i686 baseline
; -------- U32 --------

View File

@@ -1,4 +1,4 @@
test preopt
test simple_preopt
target i686
function %iadd_imm(i32) -> i32 {