This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/TMS320F28069: Compiler: DP Load optimization problem, erroneous program behavior at opt1 and higher. CGT bug?

Part Number: TMS320F28069

Tool/software: TI C/C++ Compiler

Hello all,

I encounter strange behavior of my program on F28069 and CGT 18.2.2 after a minor (I was wrong I suppose!) change in code. There was not expected spurious memory write that caused device malfunction. The problem was isolated to small simple function (below), that initialized some struct members. The code is like this (I left the real line numbers to correlate with assembly below):

void Func()
{
|229|   float32 fTemp;

|231|   fTemp = System.b.c.d.var1;
|232|   System.b.c.d.var2 = fTemp;
|233|   System.b.c.d.var3 = fTemp;
|234|   System.b.c.d.var4 = 0;

|236|   fTemp = System.b.c.e.var1;
|237|   System.b.c.e.var2 = fTemp;
|238|   System.b.c.e.var3 = fTemp;
|239|   System.b.c.e.var4 = 0;

|241|   fTemp = System.b.c.f.var1;
|242|   System.b.c.f.var2 = fTemp;
|243|   System.b.c.f.var3 = fTemp;
|244|   System.b.c.f.var4 = 0;

|246|   fTemp = System.b.c.g.var1;
|247|   System.b.c.g.var2 = fTemp;
|248|   System.b.c.g.var3 = fTemp;
|249|   System.b.c.g.var4 = 0;

|251|   fTemp = System.b.c.h.var1;
|252|   System.b.c.h.var2 = fTemp;
|253|   System.b.c.h.var3 = fTemp;
|254|   System.b.c.h.var4 = 0;
}

With CGT 18.2.2, and later tested CGT 20.2.2 and 20.8.0, at optimization level 1 and higher the code generated caused improper program operation. There was also unexpected data write at adresses 0x957E-0x9581. When looked at the generated code, it was obvious that something went wrong with the DP (Data Page) pointer load optimization. Here is listing of assembly generated with CGT 20.8.0 and opt1:

     590 0000011b 761F!         MOVW      DP,#_System+4310      ; [CPU_ARAU] 
         0000011c 0043 
     592 0000011d E591          ZERO      R1H                   ; [CPU_FPU] |234| 
     594 0000011e E223!         MOVD32    R0H,@$BLOCKED(_System)+4310 ; [CPU_FPU] |232| 
         0000011f 0016 
     596 00000120 E203!         MOV32     @$BLOCKED(_System)+4314,R0H ; [CPU_FPU] |233| 
         00000121 001A 
     598 00000122 E203!         MOV32     @$BLOCKED(_System)+4318,R1H ; [CPU_FPU] |234| 
         00000123 011E 
     600 00000124 E223!         MOVD32    R0H,@$BLOCKED(_System)+4320 ; [CPU_FPU] |237| 
         00000125 0020 
     602 00000126 E203!         MOV32     @$BLOCKED(_System)+4324,R0H ; [CPU_FPU] |238| 
         00000127 0024 
     604 00000128 E203!         MOV32     @$BLOCKED(_System)+4328,R1H ; [CPU_FPU] |239| 
         00000129 0128 
     606 0000012a E223!         MOVD32    R0H,@$BLOCKED(_System)+4330 ; [CPU_FPU] |242| 
         0000012b 002A 
     608 0000012c E203!         MOV32     @$BLOCKED(_System)+4334,R0H ; [CPU_FPU] |243| 
         0000012d 002E 
     610 0000012e E203!         MOV32     @$BLOCKED(_System)+4338,R1H ; [CPU_FPU] |244| 
         0000012f 0132 
     611 00000130 761F!         MOVW      DP,#_System+4352      ; [CPU_ARAU] 
         00000131 0044 
     613 00000132 E223!         MOVD32    R0H,@$BLOCKED(_System)+4350 ; [CPU_FPU] |247| <=== BUG !
         00000133 003E 
     615 00000134 E203!         MOV32     @$BLOCKED(_System)+4354,R0H ; [CPU_FPU] |248| 
         00000135 0002 
     617 00000136 E203!         MOV32     @$BLOCKED(_System)+4358,R1H ; [CPU_FPU] |249| 
         00000137 0106 
     618 00000138 761F!         MOVW      DP,#_System+4340      ; [CPU_ARAU] 
         00000139 0043 
     620 0000013a E223!         MOVD32    R0H,@$BLOCKED(_System)+4340 ; [CPU_FPU] |252| 
         0000013b 0034 
     622 0000013c E203!         MOV32     @$BLOCKED(_System)+4344,R0H ; [CPU_FPU] |253| 
         0000013d 0038 
     624 0000013e E203!         MOV32     @$BLOCKED(_System)+4348,R1H ; [CPU_FPU] |254| 
         0000013f 013C 
     629 00000140 0006          LRETR     ; [CPU_ALU] 

You can see the "BUG" line. The MOVD32 instruction tries to read +4350 offset but DP was set at the +4352 (previous page in this case).
The System is a large struct located at address 0x8440 (and spans across L0-L3 RAM).

This is the code generated with CGT 20.8.0 and opt0:

     591 0000011b 761F!         MOVW      DP,#_System+4310      ; [CPU_ARAU] 
         0000011c 0043 
     592 0000011d E2AF!         MOV32     R0H,@$BLOCKED(_System)+4310 ; [CPU_FPU] |231| 
         0000011e 0016 
     594 0000011f E203!         MOV32     @$BLOCKED(_System)+4312,R0H ; [CPU_FPU] |232| 
         00000120 0018 
     596 00000121 E203!         MOV32     @$BLOCKED(_System)+4314,R0H ; [CPU_FPU] |233| 
         00000122 001A 
     598 00000123 E590          ZERO      R0H                   ; [CPU_FPU] |234| 
     599 00000124 E203!         MOV32     @$BLOCKED(_System)+4318,R0H ; [CPU_FPU] |234| 
         00000125 001E 
     601 00000126 E2AF!         MOV32     R0H,@$BLOCKED(_System)+4320 ; [CPU_FPU] |236| 
         00000127 0020 
     603 00000128 E203!         MOV32     @$BLOCKED(_System)+4322,R0H ; [CPU_FPU] |237| 
         00000129 0022 
     605 0000012a E203!         MOV32     @$BLOCKED(_System)+4324,R0H ; [CPU_FPU] |238| 
         0000012b 0024 
     607 0000012c E590          ZERO      R0H                   ; [CPU_FPU] |239| 
     608 0000012d E203!         MOV32     @$BLOCKED(_System)+4328,R0H ; [CPU_FPU] |239| 
         0000012e 0028 
     610 0000012f E2AF!         MOV32     R0H,@$BLOCKED(_System)+4330 ; [CPU_FPU] |241| 
         00000130 002A 
     612 00000131 E203!         MOV32     @$BLOCKED(_System)+4332,R0H ; [CPU_FPU] |242| 
         00000132 002C 
     614 00000133 E203!         MOV32     @$BLOCKED(_System)+4334,R0H ; [CPU_FPU] |243| 
         00000134 002E 
     616 00000135 E590          ZERO      R0H                   ; [CPU_FPU] |244| 
     617 00000136 E203!         MOV32     @$BLOCKED(_System)+4338,R0H ; [CPU_FPU] |244| 
         00000137 0032 
     619 00000138 E2AF!         MOV32     R0H,@$BLOCKED(_System)+4350 ; [CPU_FPU] |246| 
         00000139 003E 
     621 0000013a 761F!         MOVW      DP,#_System+4352      ; [CPU_ARAU] 
         0000013b 0044 
     622 0000013c E203!         MOV32     @$BLOCKED(_System)+4352,R0H ; [CPU_FPU] |247| 
         0000013d 0000 
     624 0000013e E203!         MOV32     @$BLOCKED(_System)+4354,R0H ; [CPU_FPU] |248| 
         0000013f 0002 
     626 00000140 E590          ZERO      R0H                   ; [CPU_FPU] |249| 
     627 00000141 E203!         MOV32     @$BLOCKED(_System)+4358,R0H ; [CPU_FPU] |249| 
         00000142 0006 
     629 00000143 761F!         MOVW      DP,#_System+4340      ; [CPU_ARAU] 
         00000144 0043 
     630 00000145 E2AF!         MOV32     R0H,@$BLOCKED(_System)+4340 ; [CPU_FPU] |251| 
         00000146 0034 
     632 00000147 E203!         MOV32     @$BLOCKED(_System)+4342,R0H ; [CPU_FPU] |252| 
         00000148 0036 
     634 00000149 E203!         MOV32     @$BLOCKED(_System)+4344,R0H ; [CPU_FPU] |253| 
         0000014a 0038 
     636 0000014b E590          ZERO      R0H                   ; [CPU_FPU] |254| 
     637 0000014c E203!         MOV32     @$BLOCKED(_System)+4348,R0H ; [CPU_FPU] |254| 
         0000014d 003C 
     643 0000014e 0006          LRETR     ; [CPU_ALU] 

With this code everything works as expected.

I do not use CLA - I noticed some problems with DP when using global variables in C code when the global is declared in CLA code. This is not the case.
Can someone tell me what is wrong here? Am I doing something wrong or this is a bug in compiler? And one more important question: are other MCUs also affected? I'm also using extensively F28335.
The severity of this problem is very big.

Used compiler options:

"C:/ti/ccsv6/tools/compiler/ti-cgt-c2000_20.8.0.STS/bin/cl2000" -v28 -mt --cla_support=cla0 --float_support=fpu32 --vcu_support=vcu0 -O1 --opt_for_speed=5 --advice:performance=all --define=_INLINE --diag_warning=225 --diag_wrap=off --display_error_number --issue_remarks --abi=coffabi --rpt_threshold=30 --asm_listing --preproc_with_compile --preproc_dependency="sources/<filename.d>"