Skip to content

Commit aaf2966

Browse files
committed
Lifted restrictions on shift.
1 parent c0d6f03 commit aaf2966

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

integration/src/const_collapse.rs

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,18 @@ pub fn collapse_const_if_possible(op: &Operator, inputs: &[MaybeConstant]) {
2424
| Operator::I64Or
2525
| Operator::I32And
2626
| Operator::I64And
27-
| Operator::I32Shl
28-
| Operator::I64Shl
29-
| Operator::I32ShrS
30-
| Operator::I64ShrS
31-
| Operator::I32ShrU
32-
| Operator::I64ShrU
3327
| Operator::I32LtS
3428
| Operator::I64LtS
3529
| Operator::I32LtU
3630
| Operator::I64LtU
37-
| Operator::I32Eq
38-
| Operator::I64Eq
39-
| Operator::I32Ne
40-
| Operator::I64Ne
4131
| Operator::I32GeS
4232
| Operator::I64GeS
4333
| Operator::I32GeU
44-
| Operator::I64GeU
45-
//| Operator::I32Rotl
46-
//| Operator::I64Rotl
47-
//| Operator::I32Rotr
48-
//| Operator::I64Rotr
49-
=> {
34+
| Operator::I64GeU
35+
| Operator::I32Eq
36+
| Operator::I64Eq
37+
| Operator::I32Ne
38+
| Operator::I64Ne => {
5039
if let [
5140
_,
5241
MaybeConstant::ReferenceConstant {
@@ -73,6 +62,22 @@ pub fn collapse_const_if_possible(op: &Operator, inputs: &[MaybeConstant]) {
7362
}
7463
}
7564

65+
// Shift and rot operations are special because they can handle immediates bigger than i16,
66+
// as the value is masked to the bitwidth of the type.
67+
Operator::I32Shl
68+
| Operator::I64Shl
69+
| Operator::I32ShrS
70+
| Operator::I64ShrS
71+
| Operator::I32ShrU
72+
| Operator::I64ShrU
73+
//| Operator::I32Rotl
74+
//| Operator::I64Rotl
75+
//| Operator::I32Rotr
76+
//| Operator::I64Rotr
77+
=> if let [_, MaybeConstant::ReferenceConstant { must_collapse, .. }] = inputs {
78+
must_collapse.replace(true);
79+
}
80+
7681
// GT is special because the left operand is the one that can be immediate
7782
Operator::I32GtS
7883
| Operator::I32GtU

integration/src/womir_translation.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -787,9 +787,8 @@ impl<'a, F: PrimeField32> Settings<'a> for OpenVMSettings<F> {
787787
// Doesn't matter the order, because only commutative operations will
788788
// have the constant operand on the left side, as const folding ensures.
789789

790-
// The constant has already been validated to be in i16 range during
791-
// const folding, now we need to sign-extend it to 24-bits and then
792-
// convert to field element.
790+
// The constant folding step guarantees that the constant can be safely
791+
// truncated to i16.
793792
let c = const_i16_as_field(c);
794793

795794
return Directive::Instruction(ib::instr_i(
@@ -856,14 +855,14 @@ impl<'a, F: PrimeField32> Settings<'a> for OpenVMSettings<F> {
856855

857856
// Handle the complex instructions that supports constant inlining
858857
match &op {
859-
Op::I32LeS
860-
| Op::I32LeU
861-
| Op::I32GeS
858+
Op::I32GeS
862859
| Op::I32GeU
863-
| Op::I64LeS
864-
| Op::I64LeU
865860
| Op::I64GeS
866-
| Op::I64GeU => {
861+
| Op::I64GeU
862+
| Op::I32LeS
863+
| Op::I32LeU
864+
| Op::I64LeS
865+
| Op::I64LeU => {
867866
let inverse_result = c.register_gen.allocate_type(ValType::I32).start as usize;
868867
let output = output.unwrap().start as usize;
869868

0 commit comments

Comments
 (0)