View Issue Details

IDProjectCategoryView StatusLast Update
0030260FPCCompilerpublic2020-09-29 22:15
ReporterBenjamin Rosseaux Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.0.0 
Fixed in Version3.3.1 
Summary0030260: "if TypeInfo(TSameTypeXYZ) = TypeInfo(TSameTypeXYZ) then" alway-true-check isn't optimized out
Description
As said in the summary, at "if TypeInfo(TSameTypeXYZ) = TypeInfo(TSameTypeXYZ) then" the always-true-check isn't optimized out (even not with -O4). For example:

function TSupraHashMap<TSupraHashMapKey,TSupraHashMapValue>.HashKey(const Key:TSupraHashMapKey):UInt32;
...
 end else if TypeInfo(TSupraHashMapKey)=TypeInfo(RawByteString) then begin
  result:=HashData(PByte(@RawByteString(pointer(@Key)^)[1]),length(RawByteString(pointer(@Key)^)));
...

will be to on i386:

# [208] (TypeInfo(TSupraHashMapKey)=TypeInfo(RawByteString)) then begin
    movl $RTTI_$SYSTEM_$$_RAWBYTESTRING,%edx
    movl $RTTI_$SYSTEM_$$_RAWBYTESTRING,%eax
    cmpl %eax,%edx
    jne .Lj7369

and on x64:

# [208] (TypeInfo(TSupraHashMapKey)=TypeInfo(RawByteString)) then begin
    leaq RTTI_$SYSTEM_$$_RAWBYTESTRING(%rip),%rax
    leaq RTTI_$SYSTEM_$$_RAWBYTESTRING(%rip),%rdx
    cmpq %rdx,%rax
    jne .Lj7507

and the same thing with the "if TypeInfo(TSameTypeXYZ) = TypeInfo(TNotSameTypeXYZ) then" case, where the whole always-false-if-branch will be also not killed yet.



Tagsoptimization, typinfo
Fixed in Revision47008
FPCOldBugId
FPCTarget-
Attached Files

Activities

Bi0T1N

2020-03-23 17:14

reporter   ~0121691

Last edited: 2020-03-23 17:16

View 5 revisions

Still the same with FPC 3.3.1-r44326 on Windows x64:

program test;

{$mode ObjFPC}
//{$mode Delphi}
//{$mode DelphiUnicode}

begin
  if TypeInfo(String)=TypeInfo(RawByteString) then
    writeln('equal')
  else
    writeln('not equal');
        
  if TypeInfo(NativeInt)=TypeInfo(NativeInt) then
    writeln('equal')
  else
    writeln('not equal');
end.

fpc -O4 -a test.pas
    leaq	RTTI_$SYSTEM_$$_SHORTSTRING(%rip),%rdx
    leaq	RTTI_$SYSTEM_$$_RAWBYTESTRING(%rip),%rax
    cmpq	%rax,%rdx
    jne	.Lj4
        ...equal output...
.Lj4:
        ...not equal output...


    leaq	RTTI_$SYSTEM_$$_NATIVEINT(%rip),%rax
    leaq	RTTI_$SYSTEM_$$_NATIVEINT(%rip),%rdx
    cmpq	%rdx,%rax
    jne	.Lj7
        ...equal output...
.Lj7:
        ...not equal output...


Issue History

Date Modified Username Field Change
2016-06-11 05:39 Benjamin Rosseaux New Issue
2020-03-23 17:09 Bi0T1N Tag Attached: optimization
2020-03-23 17:09 Bi0T1N Tag Attached: typinfo
2020-03-23 17:14 Bi0T1N Note Added: 0121691
2020-03-23 17:14 Bi0T1N Note Edited: 0121691 View Revisions
2020-03-23 17:15 Bi0T1N Note Edited: 0121691 View Revisions
2020-03-23 17:16 Bi0T1N Note Edited: 0121691 View Revisions
2020-03-23 17:16 Bi0T1N Note Edited: 0121691 View Revisions
2020-09-29 22:15 Florian Assigned To => Florian
2020-09-29 22:15 Florian Status new => resolved
2020-09-29 22:15 Florian Resolution open => fixed
2020-09-29 22:15 Florian Fixed in Version => 3.3.1
2020-09-29 22:15 Florian Fixed in Revision => 47008
2020-09-29 22:15 Florian FPCTarget => -