| ... | @@ -4160,7 +4160,7 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -4160,7 +4160,7 @@ fn airIntcast(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 4160 | | 4160 | |
| 4161 | const op_bits = toWasmBits(@as(u16, @intCast(operand_ty.bitSize(mod)))).?; | 4161 | const op_bits = toWasmBits(@as(u16, @intCast(operand_ty.bitSize(mod)))).?; |
| 4162 | const wanted_bits = toWasmBits(@as(u16, @intCast(ty.bitSize(mod)))).?; | 4162 | const wanted_bits = toWasmBits(@as(u16, @intCast(ty.bitSize(mod)))).?; |
| 4163 | const result = if (op_bits == wanted_bits) | 4163 | const result = if (op_bits == wanted_bits and !ty.isSignedInt(mod)) |
| 4164 | func.reuseOperand(ty_op.operand, operand) | 4164 | func.reuseOperand(ty_op.operand, operand) |
| 4165 | else | 4165 | else |
| 4166 | try (try func.intcast(operand, operand_ty, ty)).toLocal(func, ty); | 4166 | try (try func.intcast(operand, operand_ty, ty)).toLocal(func, ty); |
| ... | @@ -4181,7 +4181,19 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro | ... | @@ -4181,7 +4181,19 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro |
| 4181 | | 4181 | |
| 4182 | const op_bits = toWasmBits(given_bitsize).?; | 4182 | const op_bits = toWasmBits(given_bitsize).?; |
| 4183 | const wanted_bits = toWasmBits(wanted_bitsize).?; | 4183 | const wanted_bits = toWasmBits(wanted_bitsize).?; |
| 4184 | if (op_bits == wanted_bits) return operand; | 4184 | if (op_bits == wanted_bits) { |
| | 4185 | if (given.isSignedInt(mod)) { |
| | 4186 | if (given_bitsize < wanted_bitsize) { |
| | 4187 | // signed integers are stored as two's complement, |
| | 4188 | // when we upcast from a smaller integer to larger |
| | 4189 | // integers, we must get its absolute value similar to |
| | 4190 | // i64_extend_i32_s instruction. |
| | 4191 | return func.signAbsValue(operand, given); |
| | 4192 | } |
| | 4193 | return func.wrapOperand(operand, wanted); |
| | 4194 | } |
| | 4195 | return operand; |
| | 4196 | } |
| 4185 | | 4197 | |
| 4186 | if (op_bits > 32 and op_bits <= 64 and wanted_bits == 32) { | 4198 | if (op_bits > 32 and op_bits <= 64 and wanted_bits == 32) { |
| 4187 | try func.emitWValue(operand); | 4199 | try func.emitWValue(operand); |