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.

Unexpected C6748 code generation behavior when optimization is enabled

Hello,

 

I am experiencing some strange behavior in my program running on a C6748 (L-138 EVM board). There's an IF that appears not to be working properly:

 

(line 555) if(verify_sync_pulse(&sig_buf_rx_fs, index_max, &sync1)!=PLM_OK){

    return plm_error=SYNC_MISSING;
  }

 

(Sorry, I could not figure how to format code properly)

 

The part of the listing file that matches the code above is this, I think:

    3307                            .dwpsn  file "plm.c",line 555,column 3,is_stmt
    3308                    $C$DW$317       .dwtag  DW_TAG_TI_branch
    3309                            .dwattr $C$DW$317, DW_AT_low_pc(0x00)
    3310                            .dwattr $C$DW$317, DW_AT_name("_verify_sync_pulse")
    3311                            .dwattr $C$DW$317, DW_AT_TI_call
    3312 00000d08 0FFE6710             CALL    .S1     _verify_sync_pulse ; |555|
    3313 00000d0c 023C22E6             LDW     .D2T2   *+SP(4),B4        ; |555|
    3314 00000d10 0186902A'            MVKL    .S2     $C$RL90,B3        ; |555|
    3315 00000d14 0180006A'            MVKH    .S2     $C$RL90,B3        ; |555|
    3316 00000d18 033D1058             ADD     .L1X    8,SP,A6           ; |555|
    3317 00000d1c 02280058             MV      .L1     A10,A4            ; |555|
    3318 00000d20           $C$RL90:   ; CALL OCCURS {_verify_sync_pulse} {0}  ; |555|
    3319                    ;** --------------------------------------------------------------------------*
    3320 00000d20 00900058             MV      .L1     A4,A1             ; |555|
    3321                            .dwpsn  file "plm.c",line 556,column 5,is_stmt
    3322 00000d24 80006410     [ A1]   B       .S1     $C$L27            ; |556|
    3323 00000d28 820009AA     [ A1]   MVK     .S2     19,B4             ; |556|
    3324 00000d2c 860009A8     [ A1]   MVK     .S1     0x13,A12          ; |556|
    3325 00000d30 8200057E-    [ A1]   STW     .D2T2   B4,*+DP(_plm_error) ; |556|
    3326 00000d34 00002000             NOP             2
    3327                               ; BRANCHCC OCCURS {$C$L27}        ; |556|


The above is compiled with optimization options: (optimize for speed = 5, opt. level=function -o2).

 

In the debugger I have verified that the function verify_sync_pulse resurns zero, which is the value for the enumeration element PLM_OK. Both the tooltip and the memory window confirm that (and is what I expected for the data I'm processing). Yet the 'if' does not work: the body does get executed when it should not.

 

When I disable all the optimization options, the problem dissapears. With no optimization, the generation code does have a B.S1 instruction where you would expect it -- I haven't yet decyphered all the instructions in the listing above but the fact is that the branch is not taken when optimization is enabled.

 

In short, what can be going on? Is there something else that needs to be done besides just passing the optimization options to the compiler?

 

My Code Generation Tools is version 6.1.10.

 

Thanks!

 

 

  • This generated assembly code looks correct.  I think you are misinterpreting what you see as you step through it.

    The assembly syntax ...

    [ register ] instruction

    means the effect of the instruction is carried out only if the register is non-zero.  In your case A1 does have the value 0, so when you step an instruction like ...

    [ A1]   B       .S1     $C$L27

    You see control pass through it, but the branch to that label never occurs. For more detail, see the "Conditional Operations" section of http://www-s.ti.com/sc/techlit/spru732 .

    Thanks and regards,

    -George

     

     

     

  • Hello,

    I think I did not post the relevant listing code snippet in my previous post, so I've been more careful now. I have been able to reproduce the error and will copy here the relevant parts of the listing files:

     

    This is the listing for the code that does work (i.e. IF does not get executed because return value is zero):

     

        2609                            .dwpsn  file "plm.c",line 555,column 3,is_stmt
        2610                    $C$DW$268       .dwtag  DW_TAG_TI_branch
        2611                            .dwattr $C$DW$268, DW_AT_low_pc(0x00)
        2612                            .dwattr $C$DW$268, DW_AT_name("_verify_sync_pulse")
        2613                            .dwattr $C$DW$268, DW_AT_TI_call
        2614 00000cb0 00063090             CALL    .S1     _verify_sync_pulse ; |555|
        2615 00000cb4 023C22E6             LDW     .D2T2   *+SP(4),B4        ; |555|
        2616 00000cb8 0186662A'            MVKL    .S2     $C$RL103,B3       ; |555|
        2617 00000cbc 02004828-            MVKL    .S1     _sig_buf_rx_fs,A4
        2618 00000cc0 0180006A'            MVKH    .S2     $C$RL103,B3       ; |555|
        2619                   
        2620 00000cc4 02000069-            MVKH    .S1     _sig_buf_rx_fs,A4
        2621 00000cc8 033D1058  ||         ADD     .L1X    8,SP,A6           ; |555|
        2622                   
        2623 00000ccc           $C$RL103:  ; CALL OCCURS {_verify_sync_pulse} {0}  ; |555|
        2624 00000ccc 00900058             MV      .L1     A4,A1             ; |555|
        2625 00000cd0 90000510     [!A1]   B       .S1     $C$L24            ; |555|
        2626 00000cd4 00008000             NOP             5
        2627                               ; BRANCHCC OCCURS {$C$L24}        ; |555|
        2628                    ;** --------------------------------------------------------------------------*
        2629                            .dwpsn  file "plm.c",line 556,column 5,is_stmt
        2630 00000cd8 00008210             B       .S1     $C$L32            ; |556|
        2631 00000cdc 020009A8             MVK     .S1     0x13,A4           ; |556|
        2632 00000ce0 0200057C-            STW     .D2T1   A4,*+DP(_plm_error) ; |556|
        2633 00000ce4 00004000             NOP             3
        2634                               ; BRANCH OCCURS {$C$L32}          ; |556|
        2635                    ;** --------------------------------------------------------------------------*

     

    This is the same part of the listing for the code that does not work, compiled with the options specified in the first post:

     

        3442                            .dwpsn  file "plm.c",line 555,column 3,is_stmt
        3443                    $C$DW$325       .dwtag  DW_TAG_TI_branch
        3444                            .dwattr $C$DW$325, DW_AT_low_pc(0x00)
        3445                            .dwattr $C$DW$325, DW_AT_name("_verify_sync_pulse")
        3446                            .dwattr $C$DW$325, DW_AT_TI_call
        3447 00000dc8 0FFE5C10             CALL    .S1     _verify_sync_pulse ; |555|
        3448 00000dcc 023C22E6             LDW     .D2T2   *+SP(4),B4        ; |555|
        3449 00000dd0 0186F02A'            MVKL    .S2     $C$RL96,B3        ; |555|
        3450 00000dd4 0180006A'            MVKH    .S2     $C$RL96,B3        ; |555|
        3451 00000dd8 033D1058             ADD     .L1X    8,SP,A6           ; |555|
        3452 00000ddc 02280058             MV      .L1     A10,A4            ; |555|
        3453 00000de0           $C$RL96:   ; CALL OCCURS {_verify_sync_pulse} {0}  ; |555|
        3454                    ;** --------------------------------------------------------------------------*
        3455 00000de0 00900058             MV      .L1     A4,A1             ; |555|
        3456                            .dwpsn  file "plm.c",line 556,column 5,is_stmt
        3457 00000de4 80006410     [ A1]   B       .S1     $C$L28            ; |556|
        3458 00000de8 820009AA     [ A1]   MVK     .S2     19,B4             ; |556|
        3459 00000dec 860009A8     [ A1]   MVK     .S1     0x13,A12          ; |556|
        3460 00000df0 8200057E-    [ A1]   STW     .D2T2   B4,*+DP(_plm_error) ; |556|
        3461 00000df4 00002000             NOP             2
        3462                               ; BRANCHCC OCCURS {$C$L28}        ; |556|
        3463                    ;** --------------------------------------------------------------------------*

     

    Labels $C$L24 and $C$L28 respectively are in both cases the end of the function this code is in.

    This code has been tested with a dummy version of the function verify_sync_pulse that always returns 0 (==PLM_OK). The if body (return right after line 555) should never execute, yet it does in the second case.

    Please note that in the first case (the case that works) the conditional branch is the 8th instruction after the call, while in the second case it is the 7th; don't know if that's relevant.

    Besides the optimization options, both codes have been compiled with the DEBUG option.

     

    This is not very critical to me, at least in this stage, but if there are incompatibilities between compiler options, please point me to the relevant documentation, I've been unable to find anything on my own. I understand that debugging optimized code is not recommended (in the compiler manual) but this is not a debugging problem, it's code that seems not to execute properly.

     

    Thank you!

     

     

     

  • Please do this experiment.  Set a breakpoint on this instruction ...

     [ A1]   B       .S1     $C$L28  

    What is the value of A1?  If it is 0 (as I expect), then the device executes a NOP instead of the branch you see.  Likewise for the other instructions predicated by A1.

    Thanks and regards,

    -George