committed by
Dan Gohman
parent
75ec950a12
commit
4ee2747c5b
19
cranelift/filetests/filetests/preopt/constant_fold.clif
Normal file
19
cranelift/filetests/filetests/preopt/constant_fold.clif
Normal file
@@ -0,0 +1,19 @@
|
||||
test preopt
|
||||
target x86_64
|
||||
|
||||
function %constant_fold(f64) -> f64 {
|
||||
ebb0(v0: f64):
|
||||
v1 = f64const 0x1.0000000000000p0
|
||||
v2 = f64const 0x1.0000000000000p1
|
||||
v3 = fadd v1, v2
|
||||
v4 = fadd v3, v0
|
||||
return v4
|
||||
}
|
||||
; sameln: function %constant_fold(f64) -> f64 fast {
|
||||
; nextln: ebb0(v0: f64):
|
||||
; nextln: v1 = f64const 0x1.0000000000000p0
|
||||
; nextln: v2 = f64const 0x1.0000000000000p1
|
||||
; nextln: v3 = f64const 0x1.8000000000000p1
|
||||
; nextln: v4 = fadd v3, v0
|
||||
; nextln: return v4
|
||||
; nextln: }
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use cranelift_codegen::{
|
||||
cursor::{Cursor, FuncCursor},
|
||||
ir::{self, InstBuilder},
|
||||
ir::{self, dfg::ValueDef, InstBuilder},
|
||||
};
|
||||
// use rustc_apfloat::{
|
||||
// ieee::{Double, Single},
|
||||
@@ -69,7 +69,10 @@ pub fn fold_constants(func: &mut ir::Function) {
|
||||
fn resolve_value_to_imm(dfg: &ir::DataFlowGraph, value: ir::Value) -> Option<ConstImm> {
|
||||
let original = dfg.resolve_aliases(value);
|
||||
|
||||
let inst = dfg.value_def(original).unwrap_inst();
|
||||
let inst = match dfg.value_def(original) {
|
||||
ValueDef::Result(inst, _) => inst,
|
||||
ValueDef::Param(_, _) => return None,
|
||||
};
|
||||
|
||||
use self::ir::{InstructionData::*, Opcode::*};
|
||||
match dfg[inst] {
|
||||
|
||||
Reference in New Issue
Block a user