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

Compiler may generate incorrect code for ternary max idiom with integers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: High High
    • Code Generation Tools
    • CODEGEN-12663
    • Hide
      C2000_25.3.0.LTS*
      MSP430_NEXT*
      MSP430_20.2.0.LTS
      C7000_2.1.0.LTS
      C7000_5.0.0.LTS*
      MSP430_21.6.0.LTS
      C2000_21.6.0.LTS
      C7000_3.1.0.LTS
      ARM_20.2.0.LTS
      C7000_4.1.0.LTS
      C2000_20.2.0.LTS
      C7000_1.4.0.LTS
      C2000_22.6.0.LTS
      PRU_2.4.0*
      Show
      C2000_25.3.0.LTS* MSP430_NEXT* MSP430_20.2.0.LTS C7000_2.1.0.LTS C7000_5.0.0.LTS* MSP430_21.6.0.LTS C2000_21.6.0.LTS C7000_3.1.0.LTS ARM_20.2.0.LTS C7000_4.1.0.LTS C2000_20.2.0.LTS C7000_1.4.0.LTS C2000_22.6.0.LTS PRU_2.4.0*
    • Hide
      C2000_25.3.0.LTS*
      MSP430_20.2.8.LTS*
      MSP430_NEXT*
      MSP430_21.6.2.LTS*
      C7000_5.0.0.LTS*
      C2000_22.6.2.LTS*
      ARM_20.2.8.LTS*
      PRU_2.4.0*
      C7000_4.1.1.LTS*
      C2000_21.6.2.LTS*
      C7000_3.1.2.LTS*
      Show
      C2000_25.3.0.LTS* MSP430_20.2.8.LTS* MSP430_NEXT* MSP430_21.6.2.LTS* C7000_5.0.0.LTS* C2000_22.6.2.LTS* ARM_20.2.8.LTS* PRU_2.4.0* C7000_4.1.1.LTS* C2000_21.6.2.LTS* C7000_3.1.2.LTS*
    • default
    • Hide
      This bug may trigger when all of the following conditions are met:
      1. Generating code for a ternary max operation and
      2. When integer immediate values are used in the max operation and
      3. -o2 or higher is used

      To avoid this bug, the following workarounds are available:
      1. Use an intrinsic to implement the max operation if available on your target. For example, the __max() intrinsic for C7000. This avoids using a ternary idiom.
      2. Use a function to implement the max operation that is marked __attribute__((noinline)). This avoids immediate values being used directly.
      3. Reduce the optimization level.
      Show
      This bug may trigger when all of the following conditions are met: 1. Generating code for a ternary max operation and 2. When integer immediate values are used in the max operation and 3. -o2 or higher is used To avoid this bug, the following workarounds are available: 1. Use an intrinsic to implement the max operation if available on your target. For example, the __max() intrinsic for C7000. This avoids using a ternary idiom. 2. Use a function to implement the max operation that is marked __attribute__((noinline)). This avoids immediate values being used directly. 3. Reduce the optimization level.

      A ternary operator is often used in C to implement a max operation. For example, `x < y ? y : x`.

      In rare cases, when:
      1. Generating code for a ternary max operation and
      2. When integer immediate values are used in the max operation
      Then the compiler may generate incorrect code.

      For example, `x > y ? x : y` may generate incorrect code.

      If the inputs to the max operation are not immediate values, incorrect code will not be generated. However, due to optimization, it may be difficult to identify if inputs are immediates or not.

      In these cases, incorrect code may manifest as an off-by-two error. For example, `a < 10` when `a < 12` is expected.

      Ternary min idioms are not affected by this bug.

            syncuser TI User
            syncuser TI User
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: