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.

Optimizer error, 2-dimensional array, 2 multiplications

Environment:
- DSP: TMS320C64xx
- Tool set #1:
  - CCS: 5.0.3 (Ubuntu Linux AND Windows XP gives same result)
    Help shows version N201105110900
  - Code Generation Tools: 7.2.1 (bundled with CCS)
- Tool set #2:
  - CCS: 4.2.4.00033 (Windows XP)
  - Code Generation Tools: 7.2.1 (bundled with CCS)

I see the same problem in both tool sets.

I have a function that fails when optimized with -O3 or -O2.
(-O1 works fine). Also compiling with older tools (the tools bundled
with CSS 3.3 -O3 works fine for this code).

I have created a new projeckt based on the "Basic/Hello world" example for C64xx and changed settings to optimization level = 3.

hello.c should be replaced by the attached hello.c.txt.

The error can be removed by one of those things - but I don't like to do that:
- Replace the last multiplication by:
   tmpb = (int)a[i][1]
- Replace the 2-dimensional array by two one-dimensional arrays


Console output:
(Same result have been found for Windows XP installation)
from Linux Ubuntu 11.04 with updates:
**** Build of configuration Debug for project css_err_mult2 ****

/usr/local/CCSv5/ccsv5/utils/gmake/gmake -k all
Building file: ../hello.c
Invoking: C6000 Compiler
"/usr/local/CCSv5/ccsv5/tools/compiler/c6000/bin/cl6x" -mv6400 -g -O3 --include_path="/usr/local/CCSv5/ccsv5/tools/compiler/c6000/include" --diag_warning=225 --abi=coffabi --preproc_with_compile --preproc_dependency="hello.pp"  "../hello.c"

>>>> Optimizer terminated abnormally
>>>>    in function _sqr2()
>>>>    in file "../hello.c"

>> Compilation failure
gmake: *** [hello.obj] Error 1
gmake: Target `all' not remade because of errors.

#include <stdio.h>

#define DATA_LGD 3 // Normally longer

static int sqr2(const short (*a)[2], int n) {
  int max = 0;

  int i;
  for(i = 0; i<n; i++) {
    int tmpa;
    int tmpb;

    tmpa = (int)a[i][0] * a[i][0];
    tmpb = (int)a[i][1] * a[i][1];
    tmpa += tmpb;
    if (tmpa > max) {
      max = tmpa;
    }
  }
  return max;
}

void main(void) {
  printf("Hello World example expanded to show CCS5 optimize error.\n");

  int num = DATA_LGD; // Normally higher value
  const short data[DATA_LGD][2] = {{0, 1},{0, 1},{0, 1}};
  int res = sqr2(data, num);
  printf("Dummy result: %i", res);
}

  • I can reproduce this error with your attached source file. The optimizer bug exists with codegen tools v7.2.5 and 7.3.0 as well.

    I have submitted bug report SDSCM00041564 so this can be fixed for a future release. You can track the status of the bug by going to the SDOWP link in my signature and entering the bug # in the "Find Record ID" field.

  • I have submitted this as SDSCM00041565

    You can track this issue at SDOWP

  • Another workaround is to create two new temps:

      int tmp0 = a[i][0];

      int tmp1 = a[i][1];

      tmpa = (int)tmp0 * tmp0;

      tmpb = (int)tmp1 * tmp1;

    As the optimiser creates its own temps for the array references, it messes up some of the annotations and trips over a sanity check.  Creating them in the source avoids that sequence.

    I'm still searching for a clean solution to the problem.