From 07b5991080ceb8af4690a6ae92961503770d4ec0 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Mon, 23 Sep 2019 15:01:19 -0700 Subject: [PATCH 1/2] No need to emit add of constant zero. --- lib/singlepass-backend/src/codegen_x64.rs | 46 ++++++++++++----------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index a12b2557f..93c4e0fdd 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -1512,22 +1512,24 @@ impl X64FunctionCode { a.emit_add(Size::S64, Location::GPR(tmp_base), Location::GPR(tmp_bound)); a.emit_mov(Size::S32, addr, Location::GPR(tmp_addr)); - // This branch is used for emitting "faster" code for the special case of (offset + value_size) not exceeding u32 range. - match (offset as u32).checked_add(value_size as u32) { - Some(x) => { - a.emit_add(Size::S64, Location::Imm32(x), Location::GPR(tmp_addr)); - } - None => { - a.emit_add( - Size::S64, - Location::Imm32(offset as u32), - Location::GPR(tmp_addr), - ); - a.emit_add( - Size::S64, - Location::Imm32(value_size as u32), - Location::GPR(tmp_addr), - ); + if offset != 0 && value_size != 0 { + // This branch is used for emitting "faster" code for the special case of (offset + value_size) not exceeding u32 range. + match (offset as u32).checked_add(value_size as u32) { + Some(x) => { + a.emit_add(Size::S64, Location::Imm32(x), Location::GPR(tmp_addr)); + } + None => { + a.emit_add( + Size::S64, + Location::Imm32(offset as u32), + Location::GPR(tmp_addr), + ); + a.emit_add( + Size::S64, + Location::Imm32(value_size as u32), + Location::GPR(tmp_addr), + ); + } } } @@ -1541,11 +1543,13 @@ impl X64FunctionCode { // Calculates the real address, and loads from it. a.emit_mov(Size::S32, addr, Location::GPR(tmp_addr)); - a.emit_add( - Size::S64, - Location::Imm32(offset as u32), - Location::GPR(tmp_addr), - ); + if offset != 0 { + a.emit_add( + Size::S64, + Location::Imm32(offset as u32), + Location::GPR(tmp_addr), + ); + } a.emit_add(Size::S64, Location::GPR(tmp_base), Location::GPR(tmp_addr)); m.release_temp_gpr(tmp_base); From be181f9119e6a24755abcf852ecc3dad26898157 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Tue, 24 Sep 2019 10:54:23 -0700 Subject: [PATCH 2/2] Correct this test and simplify. --- lib/singlepass-backend/src/codegen_x64.rs | 35 +++++++++++------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/singlepass-backend/src/codegen_x64.rs b/lib/singlepass-backend/src/codegen_x64.rs index 93c4e0fdd..1bfa5602e 100644 --- a/lib/singlepass-backend/src/codegen_x64.rs +++ b/lib/singlepass-backend/src/codegen_x64.rs @@ -1512,24 +1512,23 @@ impl X64FunctionCode { a.emit_add(Size::S64, Location::GPR(tmp_base), Location::GPR(tmp_bound)); a.emit_mov(Size::S32, addr, Location::GPR(tmp_addr)); - if offset != 0 && value_size != 0 { - // This branch is used for emitting "faster" code for the special case of (offset + value_size) not exceeding u32 range. - match (offset as u32).checked_add(value_size as u32) { - Some(x) => { - a.emit_add(Size::S64, Location::Imm32(x), Location::GPR(tmp_addr)); - } - None => { - a.emit_add( - Size::S64, - Location::Imm32(offset as u32), - Location::GPR(tmp_addr), - ); - a.emit_add( - Size::S64, - Location::Imm32(value_size as u32), - Location::GPR(tmp_addr), - ); - } + // This branch is used for emitting "faster" code for the special case of (offset + value_size) not exceeding u32 range. + match (offset as u32).checked_add(value_size as u32) { + Some(0) => {} + Some(x) => { + a.emit_add(Size::S64, Location::Imm32(x), Location::GPR(tmp_addr)); + } + None => { + a.emit_add( + Size::S64, + Location::Imm32(offset as u32), + Location::GPR(tmp_addr), + ); + a.emit_add( + Size::S64, + Location::Imm32(value_size as u32), + Location::GPR(tmp_addr), + ); } }