View Issue Details

IDProjectCategoryView StatusLast Update
0017556FPCCompilerpublic2020-02-23 22:48
ReporterRichard VidaAssigned ToFlorian 
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version2.5.1Product Build 
Target VersionFixed in Version3.3.1 
Summary0017556: generating unnecessary "andl $4294967295" instructions
Descriptionx86_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 Reproducefunction 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

TagsNo tags attached.
Fixed in Revision44241
FPCOldBugId
FPCTarget-
Attached Files

Activities

2010-10-06 17:56

 

example.dpr (139 bytes)

Richard Vida

2010-10-06 18:03

reporter   ~0041546

function f(): cardinal;
begin
  result := 10;
end;

var
  x, y: cardinal;

begin
  x := f();
  y := f();
  writeln(x + y);
end.


# [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

the following two instructions are unnecessary:
    andl $4294967295,%r8d
    andl $4294967295,%esi

    addq %rsi,%r8
    movq %rdi,%rdx
    movl $0,%ecx
    call fpc_write_text_uint

NoName

2020-01-07 23:45

reporter   ~0120257

Last edited: 2020-01-07 23:48

View 2 revisions

Assembler output with -OoREGVAR still has the unnecessary instructions: (fpc 3.2.0-beta-r43619)

# [14] x := f();
    call P$X_$$_F$$LONGWORD
    movl %eax,%ebx
# Var x located in register ebx
# [15] y := f();
    call P$X_$$_F$$LONGWORD
    movl %eax,%r12d
# Var y located in register r12d
# [16] writeln(x + y);
    call fpc_get_output
    movq %rax,%r13
    andl $4294967295,%ebx
    andl $4294967295,%r12d
    leaq (%rbx,%r12),%rdx
    movq %r13,%rsi
    movl $0,%edi
    call fpc_write_text_uint

Issue History

Date Modified Username Field Change
2010-10-06 17:56 Richard Vida New Issue
2010-10-06 17:56 Richard Vida File Added: example.dpr
2010-10-06 18:03 Richard Vida Note Added: 0041546
2020-01-07 23:45 NoName Note Added: 0120257
2020-01-07 23:48 NoName Note Edited: 0120257 View Revisions
2020-02-23 22:48 Florian Assigned To => Florian
2020-02-23 22:48 Florian Status new => resolved
2020-02-23 22:48 Florian Resolution open => fixed
2020-02-23 22:48 Florian Fixed in Version => 3.3.1
2020-02-23 22:48 Florian Fixed in Revision => 44241
2020-02-23 22:48 Florian FPCTarget => -