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.

c2000 v15.12.3 LTS Compiler optimiser removing code

I am currently developing on the TMS320F28377DPTPT  Rev C processor. I have recently updated to the 15.12.3 LTS compiler. I am using CSS v6.1.3.

I have been struggling with some strange behaviour of the compiler optimiser. I am using level 0 register level optimisation.

My original code was:

1:if(a < 0)
2:{
3: /*Do nothing*/
4:}
5:else
6:{
7: a = -a;
8:{

I originally wrote the code in this way as I planned to fill the /*do nothing*/ condition at a later date and it would be executed more often so I placed it first.

The problem is that when I have optimisation turned on, the assembly is not generated correctly.

Line 7 becomes:

MOVB XAR0,#22 ; [CPU_] |964|
MOVB XAR1,#22 ; [CPU_] |964|
MOV32 R0H,*+XAR2[AR0] ; [CPU_] |964|
MAXF32 R0H,#0 ; [CPU_] |964|
MOV32 *+XAR2[AR1],R0H ; [CPU_] |964|

I don't know why the MAXF32 function is being used in this instance. It does not negate my value but simply sets it to 0.

In order to fix the problem I used the following code instead:

1:if(a > 0)
2:{
3: a = -a;
4:}

The assembly of line 3 now becomes:
MOVB XAR0,#22 ; [CPU_] |960|
MOVB XAR1,#22 ; [CPU_] |960|
MOV32 R0H,*+XAR2[AR0] ; [CPU_] |960|
NEGF32 R0H,R0H ; [CPU_] |960|
MOV32 *+XAR2[AR1],R0H ; [CPU_] |960|

The NEGF32 instruction now performs the negation as expected.

Do you know what might be wrong with the original code that confused the compiler? As far as I can see, even if the code is inefficient it should not change the result of the operation on line 7/3.

  • Your C code example is incomplete, so I had to guess at a few things.  After doing that, I have a test case for which the compiler generates incorrect output, but not the same incorrect output as what you show.  So while it is clear I have found a problem, and it is probably related to your problem, I cannot be certain is the same problem.  So, I need you to submit a test case.  Please preprocess the source file which contains these problem lines.  Add a the comment /* PROBLEM HERE */ to the source, so we can find it.  Then attach that to your next post.  Also show all the build options exactly as the compiler sees them.

    Thanks and regards,

    -George

  • Hi George,

    Thank you for your reply.  Unfortunately I'm not able to post the processed file due to confidentiality issues. I am able to share it privately with you however. What would be the best way to send it to you directly? 

    -Ryan

  • Dear all,

    I have a case that if sentence partially not translated into assembly code. However, my if part is not empty.

    I tried both with I used V6.4.10 and V6.4.11, the results were the same. I switched off optimization completely because of suspicious findings with having success in removing the issues. I added junk code to the if part, or including an else part AND included junk code in the else part, then the code part is translated in diassembly. 

    I have c code and diassembly code side by side. It was pretty clear that the compiler did not do its job correctly. 

    How can I send you my screenshots. I have it in a pdf file. 

  • Hi George,

    Any progress on how I can send you the file directly? I would like to get to the bottom of this issue.

    -Ryan

  • In addition, there seems to be problem with LB. The jump address is wrong.

    Without having got an reply here, I have sent the screenshots to the field application engineer. 

  • Ryan47 said:

    Hi George,

    Any progress on how I can send you the file directly? I would like to get to the bottom of this issue.

    George is out of the office this week so his response may be delayed. You can still send him files via private message. If you hover your mouse over his avatar or screen name a dialog box should pop up. Click on Send a private message, here you can type your message and attach files (using the paper clip icon).

  • Thank you, I have now sent the file directly to George.
  • I apologize for the delay.

    Thank you for sending in a test case.  I can reproduce the same problem MAXF32 sequence.  I filed CODEGEN-1662 in the SDOWP system to have this addressed.  Feel free to follow it with the SDOWP link below in my signature.

    Thanks and regards,

    -George