Tool/software: TI C/C++ Compiler
I am currently optimizing a software that is apparently executing fine when no optimization is activated. As soon as I activate the -O2 optimization, I can observe memory corruption at execution.
Here is a piece of code that reproduces the problem:
Data declaration (global to a file)
INT16 const TAB_BEEP_HI_1[AUDIO_BUFFER_SIZE] = // 1KHz tone
{
0, 3212, 6393, 9512, 12539, 15446, 18204, 20787, 23170, 25329, 27245, 28898,
30273, 31356, 32137, 32609, 32767, 32609, 32137, 31356, 30273, 28898, 27245,
25329, 23170, 20787, 18204, 15446, 12539, 9512, 6393, 3212, 0, -3212, -6392,
-9512, -12539, -15446, -18204, -20787, -23170, -25329, -27245, -28898, -30273,
-31356, -32137, -32609, -32767, -32609, -32137, -31356, -30273, -28898, -27245,
-25329, -23170, -20787, -18205, -15446, -12540, -9512, -6393, -3212, 0, 3212,
6392, 9512, 12539, 15446, 18204, 20787, 23170, 25329, 27245, 28898, 30273,
31356, 32137, 32609, 32767, 32609, 32137, 31356, 30273, 28898, 27245, 25329,
23170, 20787, 18205, 15446, 12540, 9512, 6393, 3212
};
Loop (located in a function of the same file) that reproduces the issue:
#pragma MUST_ITERATE(AUDIO_BUFFER_SIZE,AUDIO_BUFFER_SIZE);
for(i = 0; i < AUDIO_BUFFER_SIZE; i++)
{
beep_buff1[i] = (UINT16)(TAB_BEEP_HI_1[i] * l_volume) + DC_OFFSET;
beep_buff2[i] = (UINT16)(TAB_BEEP_HI_2[i] * l_volume) + DC_OFFSET;
beep_buff3[i] = (UINT16)(TAB_BEEP_HI_1[i] * l_volume) + DC_OFFSET;
beep_buff4[i] = (UINT16)(TAB_BEEP_HI_2[i] * l_volume) + DC_OFFSET;
}
Despite the loop only reads the constant table, its execution results in writing some random values inside it. Note that I have similar issue on other pieces of code.
That's why I am wondering if I misuse the optimization command or if the compiler is behaving wrong. Is it a known issue on TI side?
I am using the Code Composer C6000 compiler V8.3.7 and running the software on a C6748 DSP.
Thanks in advance for your support.