Fix cranelift_preopt panic

Fix #611
This commit is contained in:
Antoni Boucher
2019-04-28 13:28:17 -04:00
committed by Dan Gohman
parent 75ec950a12
commit 4ee2747c5b
2 changed files with 24 additions and 2 deletions

View 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: }

View File

@@ -2,7 +2,7 @@
use cranelift_codegen::{ use cranelift_codegen::{
cursor::{Cursor, FuncCursor}, cursor::{Cursor, FuncCursor},
ir::{self, InstBuilder}, ir::{self, dfg::ValueDef, InstBuilder},
}; };
// use rustc_apfloat::{ // use rustc_apfloat::{
// ieee::{Double, Single}, // 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> { fn resolve_value_to_imm(dfg: &ir::DataFlowGraph, value: ir::Value) -> Option<ConstImm> {
let original = dfg.resolve_aliases(value); 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::*}; use self::ir::{InstructionData::*, Opcode::*};
match dfg[inst] { match dfg[inst] {