diff --git a/cranelift/codegen/src/preopt.peepmatic b/cranelift/codegen/src/preopt.peepmatic index de9dc8342a..c6e18ec695 100644 --- a/cranelift/codegen/src/preopt.peepmatic +++ b/cranelift/codegen/src/preopt.peepmatic @@ -195,4 +195,4 @@ ;; Reminder by a power of two -> bitwise and with decreased by one constant. (=> (when (urem_imm $C $x) (is-power-of-two $C)) - (band_imm $(iadd -1 $C) $x)) \ No newline at end of file + (band_imm $(isub 1 $C) $x)) \ No newline at end of file diff --git a/cranelift/codegen/src/preopt.serialized b/cranelift/codegen/src/preopt.serialized index 9b9bc3f01f..7ef6d12642 100644 Binary files a/cranelift/codegen/src/preopt.serialized and b/cranelift/codegen/src/preopt.serialized differ diff --git a/cranelift/peepmatic/crates/runtime/src/operator.rs b/cranelift/peepmatic/crates/runtime/src/operator.rs index c8f06b8514..22a70e2a9d 100644 --- a/cranelift/peepmatic/crates/runtime/src/operator.rs +++ b/cranelift/peepmatic/crates/runtime/src/operator.rs @@ -233,6 +233,10 @@ pub enum UnquoteOperator { #[peepmatic(params(iNN, iNN), result(iNN))] Iadd, + /// Compile-time `iadd` of two constant values. + #[peepmatic(params(iNN, iNN), result(iNN))] + Isub, + /// Compile-time `imul` of two constant values. #[peepmatic(params(iNN, iNN), result(iNN))] Imul, diff --git a/cranelift/peepmatic/crates/runtime/src/optimizer.rs b/cranelift/peepmatic/crates/runtime/src/optimizer.rs index 589c3f7761..ce4a6b8e57 100644 --- a/cranelift/peepmatic/crates/runtime/src/optimizer.rs +++ b/cranelift/peepmatic/crates/runtime/src/optimizer.rs @@ -77,6 +77,7 @@ where | UnquoteOperator::Bor | UnquoteOperator::Bxor | UnquoteOperator::Iadd + | UnquoteOperator::Isub | UnquoteOperator::Imul => unreachable!("not a unary unquote operator: {:?}", operator), } } @@ -98,6 +99,7 @@ where UnquoteOperator::Bor => fold_ints!(a, b, |x, y| x | y), UnquoteOperator::Bxor => fold_ints!(a, b, |x, y| x ^ y), UnquoteOperator::Iadd => fold_ints!(a, b, |x, y| x.wrapping_add(y)), + UnquoteOperator::Isub => fold_ints!(a, b, |x, y| x.wrapping_sub(y)), UnquoteOperator::Imul => fold_ints!(a, b, |x, y| x.wrapping_mul(y)), UnquoteOperator::Log2 | UnquoteOperator::Neg => { unreachable!("not a binary unquote operator: {:?}", operator)