Incorrect code generated for restrict-qualified min/max reductions at -o2+

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Medium
    • Code Generation Tools
    • CODEGEN-15522
    • Hide
      C2000_16.9.0.LTS
      C2000_18.1.0.LTS
      C6000_8.3.0
      MSP430_20.2.0.LTS
      MSP430_21.6.0.LTS
      C7000_5.0.0.LTS
      C2000_21.6.0.LTS
      PRU_2.1.2
      MSP430_15.12.0.LTS
      C7000_4.1.0.LTS
      C2000_20.2.0.LTS
      MSP430_18.1.0.LTS
      C7000_1.4.0.LTS
      C2000_22.6.0.LTS
      C6000_8.5.0.LTS
      C2000_15.12.2.LTS
      C7000_6.1.0.STS
      MSP430_16.9.0.LTS
      Show
      C2000_16.9.0.LTS C2000_18.1.0.LTS C6000_8.3.0 MSP430_20.2.0.LTS MSP430_21.6.0.LTS C7000_5.0.0.LTS C2000_21.6.0.LTS PRU_2.1.2 MSP430_15.12.0.LTS C7000_4.1.0.LTS C2000_20.2.0.LTS MSP430_18.1.0.LTS C7000_1.4.0.LTS C2000_22.6.0.LTS C6000_8.5.0.LTS C2000_15.12.2.LTS C7000_6.1.0.STS MSP430_16.9.0.LTS
    • Hide
      MSP430_20.2.8.LTS*
      C6000_8.5.1.LTS*
      C7000_6.x.0.LTS*
      C7000_5.0.2.LTS
      C2000_22.6.4.LTS
      C7000_4.1.3.LTS*
      C6000_8.6.0.LTS*
      MSP430_21.6.3.LTS*
      C2000_25.11.2.LTS*
      PRU_2.4.0*
      PRU_2.3.4*
      Show
      MSP430_20.2.8.LTS* C6000_8.5.1.LTS* C7000_6.x.0.LTS* C7000_5.0.2.LTS C2000_22.6.4.LTS C7000_4.1.3.LTS* C6000_8.6.0.LTS* MSP430_21.6.3.LTS* C2000_25.11.2.LTS* PRU_2.4.0* PRU_2.3.4*
    • default
    • Hide
      Workaround 1:
      Remove restrict from the affected pointer(s).

      void update(int8_t* out, const int8_t* in)

      Workaround 2:
      Rewrite the reduction to avoid the min/max idiom, keeping restrict.

      void update(int8_t* restrict out, const int8_t* restrict in)
      {
         for (int i = 0; i < N; i++) {
            int8_t v = in[i];
            if (v > out[i]) out[i] = v;
         }
      }
      Show
      Workaround 1: Remove restrict from the affected pointer(s). void update(int8_t* out, const int8_t* in) Workaround 2: Rewrite the reduction to avoid the min/max idiom, keeping restrict. void update(int8_t* restrict out, const int8_t* restrict in) {    for (int i = 0; i < N; i++) {       int8_t v = in[i];       if (v > out[i]) out[i] = v;    } }

      At optimization levels -o2 and higher, the compiler can generate incorrect code for loops that update a restrict-qualified array using a min/max-style reduction. The array element may retain a stale value instead of being updated.

      How it manifests in source:
      void update(int8_t* restrict out, const int8_t* restrict in)
      {
      for (int i = 0; i < N; i++)

      { out[i] = std::max(out[i], in[i]); }

      }

      Workaround 1:
      Remove restrict from the affected pointer(s).

      void update(int8_t* out, const int8_t* in)

      Workaround 2:
      Rewrite the reduction to avoid the min/max idiom, keeping restrict.

      void update(int8_t* restrict out, const int8_t* restrict in)
      {
      for (int i = 0; i < N; i++)

      { int8_t v = in[i]; if (v > out[i]) out[i] = v; }

      }

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

              Created:
              Updated:
              Resolved:

                Connection: Intermediate to External PROD System
                EXTSYNC-6838 - Incorrect code generated for restri...
                SYNCHRONIZED
                • Last Sync Date: