View Issue Details

IDProjectCategoryView StatusLast Update
0036669FPCCompilerpublic2020-02-10 21:49
ReporterJ. Gareth Moreton Assigned ToFlorian  
PrioritylowSeveritytweakReproducibilityN/A
Status resolvedResolutionfixed 
Platformi386 and x86_64OSMicrosoft Windows 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0036669: [Patch] Deadstore removal improvement
Description0036622 ended up removing some deadstore removal optimisations in cases where the source register of the errant MOV operation is replaced with a constant. This patch resolves that issue by allowing the source parameter to be either a register or a constnat, as well as widening the criteria to include writes to the stack below the return address, not just offsets from EBP/RBP.
Steps To ReproduceApply patch and confirm correct compilation as well as a few additional removals of ineffective MOV operations.
Tagscompiler, i386, optimization, patch, x86, x86_64
Fixed in Revision44147
FPCOldBugId
FPCTarget-
Attached Files

Activities

J. Gareth Moreton

2020-02-07 00:19

developer  

deadstore-improvement.patch (1,611 bytes)   
Index: compiler/x86/aoptx86.pas
===================================================================
--- compiler/x86/aoptx86.pas	(revision 44106)
+++ compiler/x86/aoptx86.pas	(working copy)
@@ -2552,11 +2552,24 @@
           result)
         }
         if IsExitCode(hp1) and
-          MatchOpType(taicpu(p),top_reg,top_ref) and
-          (taicpu(p).oper[1]^.ref^.base = current_procinfo.FramePointer) and
-          not(assigned(current_procinfo.procdef.funcretsym) and
-             (taicpu(p).oper[1]^.ref^.offset < tabstractnormalvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset)) and
-          (taicpu(p).oper[1]^.ref^.index = NR_NO) then
+          (taicpu(p).oper[1]^.typ = top_ref) and
+          (taicpu(p).oper[1]^.ref^.index = NR_NO) and
+          (
+            (
+              (taicpu(p).oper[1]^.ref^.base = current_procinfo.FramePointer) and
+              not (
+                assigned(current_procinfo.procdef.funcretsym) and
+                (taicpu(p).oper[1]^.ref^.offset <= tabstractnormalvarsym(current_procinfo.procdef.funcretsym).localloc.reference.offset)
+              )
+            ) or
+            { Also discard writes to the stack that are below the base pointer,
+              as this is temporary storage rather than a function result on the
+              stack, say. }
+            (
+              (taicpu(p).oper[1]^.ref^.base = NR_STACK_POINTER_REG) and
+              (taicpu(p).oper[1]^.ref^.offset < current_procinfo.final_localsize)
+            )
+          ) then
           begin
             asml.remove(p);
             p.free;
deadstore-improvement.patch (1,611 bytes)   

J. Gareth Moreton

2020-02-10 00:28

developer   ~0120986

Last edited: 2020-02-10 01:23

View 2 revisions

Full win32 and win64 regression suite with combination of patches from 36669, 0036670, 0036675 and 0036680 was successful.

(Never mind - had a script error - re-running tests)

J. Gareth Moreton

2020-02-10 09:36

developer   ~0120991

Test re-run seems to pass.

Florian

2020-02-10 21:49

administrator   ~0121003

Thanks, applied.

Issue History

Date Modified Username Field Change
2020-02-07 00:19 J. Gareth Moreton New Issue
2020-02-07 00:19 J. Gareth Moreton File Added: deadstore-improvement.patch
2020-02-07 00:19 J. Gareth Moreton Tag Attached: compiler
2020-02-07 00:19 J. Gareth Moreton Tag Attached: patch
2020-02-07 00:19 J. Gareth Moreton Tag Attached: i386
2020-02-07 00:19 J. Gareth Moreton Tag Attached: x86_64
2020-02-07 00:19 J. Gareth Moreton Tag Attached: optimization
2020-02-07 00:20 J. Gareth Moreton Priority normal => low
2020-02-07 00:20 J. Gareth Moreton Severity minor => tweak
2020-02-07 00:20 J. Gareth Moreton FPCTarget => -
2020-02-07 15:33 J. Gareth Moreton Tag Attached: x86
2020-02-10 00:28 J. Gareth Moreton Note Added: 0120986
2020-02-10 01:23 J. Gareth Moreton Note Edited: 0120986 View Revisions
2020-02-10 09:36 J. Gareth Moreton Note Added: 0120991
2020-02-10 21:49 Florian Assigned To => Florian
2020-02-10 21:49 Florian Status new => resolved
2020-02-10 21:49 Florian Resolution open => fixed
2020-02-10 21:49 Florian Fixed in Version => 3.3.1
2020-02-10 21:49 Florian Fixed in Revision => 44147
2020-02-10 21:49 Florian Note Added: 0121003