diff --git a/src/compiler/backend/x64/code-generator-x64.cc b/src/compiler/backend/x64/code-generator-x64.cc index 519ae17962..4bf367bd5b 100644 --- a/src/compiler/backend/x64/code-generator-x64.cc +++ b/src/compiler/backend/x64/code-generator-x64.cc @@ -5335,7 +5335,22 @@ void CodeGenerator::AssembleMove(InstructionOperand* source, case MoveType::kStackToRegister: { Operand src = g.ToOperand(source); if (source->IsStackSlot()) { - __ movq(g.ToRegister(destination), src); + MachineRepresentation mr = + LocationOperand::cast(source)->representation(); + const bool is_32_bit = mr == MachineRepresentation::kWord32 || + mr == MachineRepresentation::kCompressed || + mr == MachineRepresentation::kCompressedPointer; + // TODO(13581): Fix this for other code kinds (see + // https://crbug.com/1356461). + if (code_kind() == CodeKind::WASM_FUNCTION && is_32_bit) { + // When we need only 32 bits, move only 32 bits. Benefits: + // - Save a byte here and there (depending on the destination + // register; "movl eax, ..." is smaller than "movq rax, ..."). + // - Safeguard against accidental decompression of compressed slots. + __ movl(g.ToRegister(destination), src); + } else { + __ movq(g.ToRegister(destination), src); + } } else { DCHECK(source->IsFPStackSlot()); XMMRegister dst = g.ToDoubleRegister(destination);