Skip to content

Commit 9070a17

Browse files
committed
fix: resolve merge conflicts with memory IR
1 parent e4aa109 commit 9070a17

2 files changed

Lines changed: 4 additions & 34 deletions

File tree

crates/revmc-codegen/src/compiler/translate/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,13 +1893,14 @@ impl<'a, B: Backend> FunctionCx<'a, B> {
18931893
self.bytecode.op_block_name(self.current_inst, name)
18941894
}
18951895

1896-
/// Converts a 256-bit unsigned integer to a 64-bit unsigned integer, saturating at `u64::MAX`.
1896+
/// Converts a 256-bit unsigned integer to a 64-bit unsigned integer, saturating at
1897+
/// `2^bits - 1`.
18971898
fn u256_to_u64_saturating(&mut self, value: B::Value, bits: usize) -> B::Value {
18981899
let i64_type = self.bcx.type_int(64);
18991900
let reduced = self.bcx.ireduce(i64_type, value);
1900-
let extended = self.bcx.zext(self.word_type, reduced);
1901-
let fits = self.bcx.icmp(IntCC::Equal, value, extended);
19021901
let sentinel_lit = 1u128.checked_shl(bits as u32).unwrap_or(0).wrapping_sub(1);
1902+
let sentinel_u256 = self.bcx.iconst_256(U256::from(sentinel_lit));
1903+
let fits = self.bcx.icmp(IntCC::UnsignedLessThanOrEqual, value, sentinel_u256);
19031904
let sentinel = self.bcx.iconst(i64_type, sentinel_lit as i64);
19041905
self.bcx.select(fits, reduced, sentinel)
19051906
}

crates/revmc-codegen/src/compiler/translate/peephole.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -250,37 +250,6 @@ impl<'a, B: Backend> FunctionCx<'a, B> {
250250
}
251251
}
252252

253-
fn peephole_mstore(&mut self) -> bool {
254-
let [offset, value] = self.const_operands();
255-
let offset = offset.and_then(|x| u64::try_from(x).ok());
256-
let value = value.and_then(|x| u64::try_from(x).ok());
257-
match (offset, value) {
258-
(Some(offset), None) => {
259-
let offset = self.bcx.iconst(self.isize_type, offset as i64);
260-
let sp = self.sp_after_inputs_with(&[1]);
261-
self.call_fallible_builtin(Builtin::MstoreCD, &[self.ecx, offset, sp]);
262-
true
263-
}
264-
(None, Some(value)) => {
265-
let value = self.bcx.iconst(self.isize_type, value as i64);
266-
let _ = self.sp_after_inputs_with(&[0]);
267-
let sp = self.sp_from_top(1);
268-
self.call_fallible_builtin(Builtin::MstoreDC, &[self.ecx, sp, value]);
269-
true
270-
}
271-
(Some(offset), Some(value)) => {
272-
// Both operands constant; consume from virtual stack.
273-
self.pop_ignore(2);
274-
let offset = self.bcx.iconst(self.isize_type, offset as i64);
275-
let value = self.bcx.iconst(self.isize_type, value as i64);
276-
self.call_fallible_builtin(Builtin::MstoreCC, &[self.ecx, offset, value]);
277-
true
278-
}
279-
(None, None) => false,
280-
}
281-
}
282-
283-
284253
fn peephole_keccak256(&mut self) -> bool {
285254
if let Some((offset, len)) = self.const_memory_operands(self.const_operands()) {
286255
let offset = self.bcx.iconst(self.isize_type, offset as i64);

0 commit comments

Comments
 (0)