Commit d1a1434e authored by qinsoon's avatar qinsoon

correct logic on deciding whether a const is x86 immediate

parent e31c8105
...@@ -3934,6 +3934,8 @@ impl <'a> InstructionSelection { ...@@ -3934,6 +3934,8 @@ impl <'a> InstructionSelection {
debug!("tmp's ty: {}", tmp.ty); debug!("tmp's ty: {}", tmp.ty);
self.backend.emit_mov_r_imm(&tmp, val) self.backend.emit_mov_r_imm(&tmp, val)
} else { } else {
assert!(tmp.ty.get_int_length().is_some());
assert!(tmp.ty.get_int_length().unwrap() == 64);
self.backend.emit_mov_r64_imm64(&tmp, val as i64); self.backend.emit_mov_r64_imm64(&tmp, val as i64);
} }
}, },
......
...@@ -518,13 +518,18 @@ pub fn is_callee_saved(reg_id: MuID) -> bool { ...@@ -518,13 +518,18 @@ pub fn is_callee_saved(reg_id: MuID) -> bool {
} }
pub fn is_valid_x86_imm(op: &P<Value>) -> bool { pub fn is_valid_x86_imm(op: &P<Value>) -> bool {
use std::u32; use std::i32;
if op.ty.get_int_length().is_some() && op.ty.get_int_length().unwrap() <= 32 {
match op.v { match op.v {
Value_::Constant(Constant::Int(val)) if val <= u32::MAX as u64 => { Value_::Constant(Constant::Int(val)) if val as i32 >= i32::MIN && val as i32 <= i32::MAX => {
true true
}, },
_ => false _ => false
} }
} else {
false
}
} }
use ast::inst::*; use ast::inst::*;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment