generating unnecessary "andl $4294967295" instructions
Original Reporter info from Mantis: rvida
-
Reporter name: Richard Vida
Original Reporter info from Mantis: rvida
- Reporter name: Richard Vida
Description:
x86_64 targets:
with -OoREGVAR options the compiler generates unnecessary instruction to clear upper 32 bits of a 64 bit register. According to AMD64 manual any operation performed on a 32 bit register (including a simple MOV) implicitly clears upper 32 bits.
Steps to reproduce:
function f(): cardinal;
begin
result := 10;
end;
var
x, y: cardinal;
begin
x := f();
y := f();
writeln(x + y);
end.
assembler output with -OoREGVAR:
# [10] x := f();
call P$PROGRAM_F$$LONGWORD
movl %eax,%ebx
# [11] y := f();
call P$PROGRAM_F$$LONGWORD
movl %eax,%esi
# [12] writeln(x + y);
call fpc_get_output
movq %rax,%rdi
movl %ebx,%r8d
andl $4294967295,%r8d
andl $4294967295,%esi
addq %rsi,%r8
movq %rdi,%rdx
movl $0,%ecx
call fpc_write_text_uint
assembler output without -OoREGVAR:
# [10] x := f();
call P$PROGRAM_F$$LONGWORD
movl %eax,U_P$PROGRAM_X(%rip)
# [11] y := f();
call P$PROGRAM_F$$LONGWORD
movl %eax,U_P$PROGRAM_Y(%rip)
# [12] writeln(x + y);
call fpc_get_output
movq %rax,%rbx
movl U_P$PROGRAM_X(%rip),%r8d
movl U_P$PROGRAM_Y(%rip),%eax
addq %rax,%r8
movq %rbx,%rdx
movl $0,%ecx
call fpc_write_text_uint
Mantis conversion info:
- Mantis ID: 17556
- Version: 2.5.1
- Fixed in version: 3.3.1
- Fixed in revision: 44241 (#9bdfbc24)
- Monitored by: » rvida (Richard Vida), » Vincent (Vincent Snijders)