View Issue Details

IDProjectCategoryView StatusLast Update
0038247FPCCompilerpublic2020-12-23 11:23
ReporterJ. Gareth Moreton Assigned ToPierre Muller  
PrioritynormalSeverityminorReproducibilityunable to reproduce
Status resolvedResolutionfixed 
Platformx86_64 cross-compiling to m68kOSUbuntu Linux 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0038247: [Patch] Optimisation fix for Internal Error 201810201
DescriptionThis patch fixes an Internal Error that occurred when cross-compiling from x86_64-win64 to m68k-amiga and other m68k platforms.
Steps To ReproduceApply patch and confirm successful cross-compilation.
Additional InformationThe And2Nop optimisation was actually sound, but it caused another optimisation to malfunction, namely MovOpMov2MovOp -for example, in hlcgobj:

(Without optimisation)
...
    movl %ebx,%eax
    notl %eax
    andl %eax,%eax
    movq %rax,%r8
...

(With optimisation)
# Peephole Optimization: MovOpMov2MovOp (movl notl movq)
    movq %rbx,%r8
    notq %r8
# Peephole Optimization: And2Nop

This caused problems because the upper 32-bits of %rbx might not be zero. The fix now forces the instructions to S_L size in this situation.
Tagscompiler, internal error, optimization, patch
Fixed in Revision47838
FPCOldBugId
FPCTarget4.0.0
Attached Files

Relationships

child of 0038130 resolvedFlorian [Patch] Miscellaneous x86 optimisations 

Activities

J. Gareth Moreton

2020-12-23 05:09

developer  

ie201810201-fix.patch (1,941 bytes)   
Index: compiler/x86/aoptx86.pas
===================================================================
--- compiler/x86/aoptx86.pas	(revision 47836)
+++ compiler/x86/aoptx86.pas	(working copy)
@@ -3002,6 +3002,23 @@
                       check opsize to avoid overflow when left shifting the 1 }
                     if (taicpu(p).oper[0]^.typ=top_const) and (topsize2memsize[taicpu(hp2).opsize]<=63) then
                       taicpu(p).oper[0]^.val:=taicpu(p).oper[0]^.val and ((qword(1) shl topsize2memsize[taicpu(hp2).opsize])-1);
+
+{$ifdef x86_64}
+                    { Be careful of, for example:
+                        movl %reg1,%reg2
+                        addl %reg3,%reg2
+                        movq %reg2,%reg4
+
+                      This will cause problems if the upper 32-bits of %reg3 or %reg4 are non-zero
+                    }
+                    if (taicpu(hp1).opsize = S_L) and (taicpu(hp2).opsize = S_Q) then
+                      begin
+                        taicpu(hp2).changeopsize(S_L);
+                        setsubreg(taicpu(hp2).oper[0]^.reg, R_SUBD);
+                        setsubreg(taicpu(hp2).oper[1]^.reg, R_SUBD);
+                      end;
+{$endif x86_64}
+
                     taicpu(hp1).changeopsize(taicpu(hp2).opsize);
                     taicpu(p).changeopsize(taicpu(hp2).opsize);
                     if taicpu(p).oper[0]^.typ=top_reg then
@@ -6218,9 +6235,6 @@
               end;
           end;
 
-(*      { Disabled this block because it causes IE201810201 in the m68k cross-compiler
-          on x86-64 at least. Feel free to re-enable after this issue is fixed. (KB) }
-
         { Backward check to determine necessity of and %reg,%reg }
         if (taicpu(p).oper[0]^.typ = top_reg) and
           (taicpu(p).oper[0]^.reg = taicpu(p).oper[1]^.reg) and
@@ -6243,7 +6257,6 @@
             Result := True;
             Exit;
           end;
-*)
 
       end;
 
ie201810201-fix.patch (1,941 bytes)   

Pierre Muller

2020-12-23 11:23

developer   ~0127776

Patch applied after testing fullcycle with RELEASE=1
and cycle CPU_TARGET=m68k with -O4 option

Issue History

Date Modified Username Field Change
2020-12-23 05:09 J. Gareth Moreton New Issue
2020-12-23 05:09 J. Gareth Moreton File Added: ie201810201-fix.patch
2020-12-23 05:10 J. Gareth Moreton Relationship added child of 0038130
2020-12-23 05:10 J. Gareth Moreton Tag Attached: patch
2020-12-23 05:10 J. Gareth Moreton Tag Attached: compiler
2020-12-23 05:10 J. Gareth Moreton Tag Attached: optimization
2020-12-23 05:10 J. Gareth Moreton Tag Attached: internal error
2020-12-23 05:14 J. Gareth Moreton Additional Information Updated View Revisions
2020-12-23 05:14 J. Gareth Moreton FPCTarget => -
2020-12-23 05:15 J. Gareth Moreton Additional Information Updated View Revisions
2020-12-23 11:23 Pierre Muller Assigned To => Pierre Muller
2020-12-23 11:23 Pierre Muller Status new => resolved
2020-12-23 11:23 Pierre Muller Resolution open => fixed
2020-12-23 11:23 Pierre Muller Fixed in Version => 3.3.1
2020-12-23 11:23 Pierre Muller Fixed in Revision => 47838
2020-12-23 11:23 Pierre Muller FPCTarget - => 4.0.0
2020-12-23 11:23 Pierre Muller Note Added: 0127776