Optimize load/store with an iadd_imm operand.

Fold the immediate into the load/store offset when possible.
This commit is contained in:
Dan Gohman
2018-09-28 22:56:39 -07:00
parent 709eed21c1
commit 54ab1ea533
3 changed files with 159 additions and 89 deletions

View File

@@ -224,6 +224,16 @@ impl Offset32 {
None
}
}
/// Add in the signed number `x` if possible.
pub fn try_add_i64(self, x: i64) -> Option<Self> {
let casted = x as i32;
if casted as i64 == x {
self.0.checked_add(casted).map(Self::new)
} else {
None
}
}
}
impl Into<i32> for Offset32 {