View Issue Details

IDProjectCategoryView StatusLast Update
0038066FPCCompilerpublic2020-11-15 17:18
Reporterajax16384 Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Platformwindows 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0038066: i386 record field access wrong Peephole Optimization
Description3.3.1 for i386 introduces wrong Peephole Optimization

  TPack1 = record
    P1: Cardinal;
    P2: Integer;
  end;

function IsZero2(const aVal: TPack1): Boolean;
begin
  Result := (0 = aVal.P1)
        and (0 = aVal.P2); // Hint: Mixing signed expressions and longwords gives a 64bit result
end;

.section .text.n_p$fpc_bug_$$_iszero2$tpack1$$boolean,"ax"
    .balign 16,0x90
.globl P$FPC_BUG_$$_ISZERO2$TPACK1$$BOOLEAN
P$FPC_BUG_$$_ISZERO2$TPACK1$$BOOLEAN:
# [26] begin
    pushl %ebx
# Var aVal located in register eax
# [27] Result := (0 = aVal.P1)
    movl (%eax),%ebx
    xorl %ecx,%ecx
# [28] and (0 = aVal.P2);
    movl 4(%eax),%eax
# Peephole Optimization: MovSar2Cltd
    cltd
    orl %eax,%ebx
    orl %edx,%ecx
    jne .Lj8
    testl %ebx,%ebx
    jne .Lj8
# Var $result located in register al
    movb $1,%al
    jmp .Lj9
.Lj8:
    xorb %al,%al
.Lj9:
# [29] end;
    popl %ebx
    ret
Steps To Reproducebin\i386-win32\fpc.exe -vh -al fpc_bug.dpr
TagsNo tags attached.
Fixed in Revision47423
FPCOldBugId
FPCTarget-
Attached Files

Activities

ajax16384

2020-11-11 15:45

reporter  

fpc_bug.dpr (550 bytes)   
´╗┐program fpc_bug;

{$IFDEF MSWINDOWS}
{$APPTYPE CONSOLE}
{$ENDIF}

{$IFDEF FPC}
{$MODE objfpc}
{$ENDIF}

{$OPTIMIZATION ON}

type
  TPack1 = record
    P1: Cardinal;
    P2: Integer;
  end;

function IsZero1(const aVal: TPack1): Boolean;
begin
  Result := (0 = Integer(aVal.P1))
        and (0 = Integer(aVal.P2));
end;

function IsZero2(const aVal: TPack1): Boolean;
begin
  Result := (0 = aVal.P1)
        and (0 = aVal.P2);
end;

var
 t: TPack1;
begin
 t.P1 := 1;
 t.P2 := 2;
 IsZero1(t);
 IsZero2(t);
end.
fpc_bug.dpr (550 bytes)   

Issue History

Date Modified Username Field Change
2020-11-11 15:45 ajax16384 New Issue
2020-11-11 15:45 ajax16384 File Added: fpc_bug.dpr
2020-11-15 17:18 Florian Assigned To => Florian
2020-11-15 17:18 Florian Status new => resolved
2020-11-15 17:18 Florian Resolution open => fixed
2020-11-15 17:18 Florian Fixed in Version => 3.3.1
2020-11-15 17:18 Florian Fixed in Revision => 47423
2020-11-15 17:18 Florian FPCTarget => -