Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-11456

When using --opt_level=3, for a loop, compiler may emit assignment to member of a struct in the wrong place

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Medium Medium
    • Code Generation Tools
    • CODEGEN-11523
    • Show
      https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1270340/c6000-cgt-loop-optimization-bug-on-8-3-10
    • Hide
      C6000_8.3.0
      MSP430_20.2.0.LTS
      C7000_2.1.0.LTS
      C2000_22.6.0.B1
      PRU_2.3.0
      C7000_3.1.0.LTS
      MSP430_21.6.0.B1
      Show
      C6000_8.3.0 MSP430_20.2.0.LTS C7000_2.1.0.LTS C2000_22.6.0.B1 PRU_2.3.0 C7000_3.1.0.LTS MSP430_21.6.0.B1
    • Hide
      MSP430_20.2.8.LTS*
      C7000_2.1.3.LTS*
      MSP430_21.6.2.LTS*
      C7000_3.1.1.LTS
      C2000_22.6.2.LTS*
      C6000_8.3.13
      C2000_NEXT*
      PRU_2.3.4*
      C7000_4.0.0.STS
      C2000_21.6.2.LTS*
      Show
      MSP430_20.2.8.LTS* C7000_2.1.3.LTS* MSP430_21.6.2.LTS* C7000_3.1.1.LTS C2000_22.6.2.LTS* C6000_8.3.13 C2000_NEXT* PRU_2.3.4* C7000_4.0.0.STS C2000_21.6.2.LTS*
    • default
    • Hide
      To fully avoid this behavior, an optimization level lower than -o2 may be used.

      To avoid this behavior in specifically affected code, inserting `__asm(“ NOP”);` between the reads and/or writes of the struct member will prevent reordering the reads and/or writes. For example:
      my_struct.member = ...;
      __asm(“ NOP”);
      ... = my_struct.member;
      Show
      To fully avoid this behavior, an optimization level lower than -o2 may be used. To avoid this behavior in specifically affected code, inserting `__asm(“ NOP”);` between the reads and/or writes of the struct member will prevent reordering the reads and/or writes. For example: my_struct.member = ...; __asm(“ NOP”); ... = my_struct.member;

      This attached code contains these lines ...

          QualityAndStatus& qualityAndStatus = outResults.qualityAndStatus[idx];
      
          qualityAndStatus.quality = 1.0F;
          qualityAndStatus.status = getResultCode(qualityAndStatus.quality, 0);
      

      outResults is a reference to a structure defined from the caller. The value of the first parameter seen in getResultCode is 0.0F, not 1.0F.

      Build it ...

      $ cl6x -@options.txt -o3 file.cpp main.cpp -z -o test.out -l lnk.cmd
      [file.cpp]
      [main.cpp]
      <Linking>
      

      (Note lnk.cmd is from the \lib directory of the compiler installation.)

      When executed see ...

      Result 1 (expect 0): 1
      Result 2 (expect 0): 1
      

      Build it again with no optimization (remove -o3) and execute it to see ...

      Result 1 (expect 0): 0
      Result 2 (expect 0): 0
      

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: