View Issue Details

IDProjectCategoryView StatusLast Update
0038173FPCCompilerpublic2020-12-06 18:36
ReporterChristo Crause Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0038173: AVR [patch] Use LDS for 8 bit references
DescriptionLoading an 8 bit reference into a register can be done more compactly when using LDS, rather than LDI + LD, see example below. The check for CPUAVR_16_REGS as per r47612 has been extended to tcg.a_op_ref.
Steps To Reproduceprogram test;

var
  b: byte;

procedure dummy;
begin
  if b > 0 then
    b := not(b)
  else
    inc(b);
end;

begin
  dummy;
end.
Additional InformationCompiled with ~/fpc/3.3.1/compiler/ppcrossavr -n @~/fpc/3.3.1/fpc.cfg -O3 -Wpattiny13 test.lpr the generated code size is 138 bytes, compiled with the patch it is 130 bytes.
TagsNo tags attached.
Fixed in Revision47700
FPCOldBugId
FPCTarget-
Attached Files

Activities

Christo Crause

2020-12-06 07:49

reporter  

8bitref.patch (2,015 bytes)   
diff --git a/compiler/cgobj.pas b/compiler/cgobj.pas
index ccd51fb2eb..24e0af97ec 100644
--- a/compiler/cgobj.pas
+++ b/compiler/cgobj.pas
@@ -2001,7 +2001,9 @@ implementation
         if assigned(ref.symbol)
           { for avrtiny, the code generator generates a ref which is Z relative and while using it,
             Z is changed, so the following code breaks }
-          {$ifdef avr}and not(CPUAVR_16_REGS in cpu_capabilities[current_settings.cputype]){$endif avr} then
+          {$ifdef avr}
+            and not((CPUAVR_16_REGS in cpu_capabilities[current_settings.cputype]) or (tcgsize2size[size]=1))
+          {$endif avr} then
           begin
             tmpreg:=getaddressregister(list);
             a_loadaddr_ref_reg(list,ref,tmpreg);
@@ -2037,7 +2039,9 @@ implementation
         if assigned(ref.symbol)
           { for avrtiny, the code generator generates a ref which is Z relative and while using it,
             Z is changed, so the following code breaks }
-          {$ifdef avr}and not(CPUAVR_16_REGS in cpu_capabilities[current_settings.cputype]){$endif avr} then
+          {$ifdef avr}
+            and not((CPUAVR_16_REGS in cpu_capabilities[current_settings.cputype]) or (tcgsize2size[size]=1))
+          {$endif avr} then
           begin
             tmpreg:=getaddressregister(list);
             a_loadaddr_ref_reg(list,ref,tmpreg);
@@ -2273,7 +2277,12 @@ implementation
       begin
         if not (Op in [OP_NOT,OP_NEG]) then
           internalerror(2020050710);
-        if assigned(ref.symbol) then
+        if assigned(ref.symbol)
+          { for avrtiny, the code generator generates a ref which is Z relative and while using it,
+            Z is changed, so the following code breaks }
+          {$ifdef avr}
+            and not((CPUAVR_16_REGS in cpu_capabilities[current_settings.cputype]) or (tcgsize2size[size]=1))
+          {$endif avr} then
           begin
             tmpreg:=getaddressregister(list);
             a_loadaddr_ref_reg(list,ref,tmpreg);
8bitref.patch (2,015 bytes)   

Florian

2020-12-06 17:40

administrator   ~0127376

Thanks, applied.

Christo Crause

2020-12-06 18:36

reporter   ~0127379

Thanks!

Issue History

Date Modified Username Field Change
2020-12-06 07:49 Christo Crause New Issue
2020-12-06 07:49 Christo Crause File Added: 8bitref.patch
2020-12-06 17:40 Florian Assigned To => Florian
2020-12-06 17:40 Florian Status new => resolved
2020-12-06 17:40 Florian Resolution open => fixed
2020-12-06 17:40 Florian Fixed in Version => 3.3.1
2020-12-06 17:40 Florian Fixed in Revision => 47700
2020-12-06 17:40 Florian FPCTarget => -
2020-12-06 17:40 Florian Note Added: 0127376
2020-12-06 18:36 Christo Crause Status resolved => closed
2020-12-06 18:36 Christo Crause Note Added: 0127379