View Issue Details

IDProjectCategoryView StatusLast Update
0037929FPCCompilerpublic2020-10-16 22:13
ReporterChristo Crause Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version3.3.1 
Fixed in Version3.3.1 
Summary0037929: AVR [patch] Code generator incorrectly generates LDD instruction for avrtiny
DescriptionWhen compiling the test program below for avrtiny subarch (e.g.attiny10) an assembler error is generated: illegal opcode ld for mcu avrtiny. The generated assembler for the assignment:

# [15] wport := w;
    ldi r30,lo8(U_sPsTEST_ss_W)
    ldi r31,hi8(U_sPsTEST_ss_W)
    ldd r16,Z+1
    out 33,r16
    ld r16,Z+
    out 32,r16

It seems that the SrcQuickRef variable in cgcpu is not set true for avrtiny because of the "and (source.symbol=nil)" check on line 2533 in cgcpu.pas.

This extra check is also done on line 2555 for the destination, which forces loading/storing using two sets of index registers instead of the more compact use of LDS/STS. Removing this check from line 2555 results in more compact code for the lines "w := d1;" and "d1 := d;".

It is not clear to me whether these two change will cause problems in other situations. The other assignments in the test program below is unaffected by this patch.
Steps To Reproduceprogram test;

var
  w: word;
  wport: word absolute $20;
  d, d1: dword;

procedure dummy; alias: 'INT0_ISR'; interrupt;
begin
  d := w;
  w := d1;
end;

begin
  wport := w;
  d := wport;
  d1 := d;
end.

TagsNo tags attached.
Fixed in Revision47118
FPCOldBugId
FPCTarget-
Attached Files

Activities

Christo Crause

2020-10-15 22:07

reporter  

cgcpu.patch (697 bytes)   
diff --git a/compiler/avr/cgcpu.pas b/compiler/avr/cgcpu.pas
index 54d6664300..24d5952d0f 100644
--- a/compiler/avr/cgcpu.pas
+++ b/compiler/avr/cgcpu.pas
@@ -2530,7 +2530,7 @@ unit cgcpu;
             SrcQuickRef:=false;
             DestQuickRef:=false;
             if ((CPUAVR_16_REGS in cpu_capabilities[current_settings.cputype]) and
-              not((source.Base=NR_NO) and (source.Index=NR_NO) and (source.symbol=nil) and (source.Offset in [0..192-len]))) or
+              not((source.Base=NR_NO) and (source.Index=NR_NO) and (source.Offset in [0..192-len]))) or
               (
                  not((source.addressmode=AM_UNCHANGED) and
                      (source.symbol=nil) and
cgcpu.patch (697 bytes)   

Christo Crause

2020-10-15 22:10

reporter   ~0126338

Apologies, first patch is out of date. The second patch contain both changes discussed.
cgcpu2.patch (1,174 bytes)   
diff --git a/compiler/avr/cgcpu.pas b/compiler/avr/cgcpu.pas
index 54d6664300..244bc4885a 100644
--- a/compiler/avr/cgcpu.pas
+++ b/compiler/avr/cgcpu.pas
@@ -2530,7 +2530,7 @@ unit cgcpu;
             SrcQuickRef:=false;
             DestQuickRef:=false;
             if ((CPUAVR_16_REGS in cpu_capabilities[current_settings.cputype]) and
-              not((source.Base=NR_NO) and (source.Index=NR_NO) and (source.symbol=nil) and (source.Offset in [0..192-len]))) or
+              not((source.Base=NR_NO) and (source.Index=NR_NO) and (source.Offset in [0..192-len]))) or
               (
                  not((source.addressmode=AM_UNCHANGED) and
                      (source.symbol=nil) and
@@ -2552,7 +2552,7 @@ unit cgcpu;
               end;
 
             if ((CPUAVR_16_REGS in cpu_capabilities[current_settings.cputype]) and
-              not((dest.Base=NR_NO) and (dest.Index=NR_NO) and (dest.symbol=nil) and (dest.Offset in [0..192-len]))) or
+              not((dest.Base=NR_NO) and (dest.Index=NR_NO) and (dest.Offset in [0..192-len]))) or
               (
                  not((dest.addressmode=AM_UNCHANGED) and
                    (dest.symbol=nil) and
cgcpu2.patch (1,174 bytes)   

Florian

2020-10-16 22:02

administrator   ~0126351

Thanks, applied.

Christo Crause

2020-10-16 22:13

reporter   ~0126353

Thanks!

Issue History

Date Modified Username Field Change
2020-10-15 22:07 Christo Crause New Issue
2020-10-15 22:07 Christo Crause File Added: cgcpu.patch
2020-10-15 22:10 Christo Crause Note Added: 0126338
2020-10-15 22:10 Christo Crause File Added: cgcpu2.patch
2020-10-16 22:02 Florian Assigned To => Florian
2020-10-16 22:02 Florian Status new => resolved
2020-10-16 22:02 Florian Resolution open => fixed
2020-10-16 22:02 Florian Fixed in Version => 3.3.1
2020-10-16 22:02 Florian Fixed in Revision => 47118
2020-10-16 22:02 Florian FPCTarget => -
2020-10-16 22:02 Florian Note Added: 0126351
2020-10-16 22:13 Christo Crause Status resolved => closed
2020-10-16 22:13 Christo Crause Note Added: 0126353