Tool/software: TI C/C++ Compiler
I am seeing an optimization issue with C2000 compiler v16.9.3.LTS. A CCSv7.2.0 test case is attached. The problem is the following function in the file test.c:
typedef struct
{
int m1;
int m2;
} SD;
const SD D[2] = {{1000,1000},{1000,1000}};
int DemonstrateOptimizationIssue()
{
int i;
unsigned long v1 = 0;
int v0 = 1, v2 = 0, v3 = 0;
for (i = 0; i < 2; i++)
{
v1 += (unsigned long)(D[i].m2) * v0;
v2 += D[i].m1;
v3 += D[i].m2;
v0 += i;
}
v1 = v1 / v3;
if (!v1 && !v2) return(0);
return(1);
The correct return value is a 1. If you invoke -o3 optimization for test.c, you get a return of 0. The compiler seems to disregard a number of the calculations, including the multiply of v1. This wouldn't concern me normally since these are local vars and the value of them is never used outside this function, except that here the return value is wrong!
The build line is:
"C:/TI/ccsv7/tools/compiler/ti-cgt-c2000_16.9.3.LTS/bin/cl2000" -v28 -ml -mt --float_support=fpu32 -O3 --include_path="C:/TI/ccsv7/tools/compiler/ti-cgt-c2000_16.9.3.LTS/include" --include_path="C:/D/dsp/work/F28335_example_nonBIOS_ram/include" --include_path="C:/D/dsp/work/F28335_example_nonBIOS_ram/DSP2833x_headers/include" --define=EXAMPLE_NONBIOS --define=EXAMPLE_RAM -g --diag_warning=225 --display_error_number --quiet -k --asm_listing --c_src_interlist --output_all_syms --preproc_with_compile --preproc_dependency="src/test.d" --obj_directory="src" "../src/test.c"
Could I get a sanity check here that this isn't an infirmity in the C code (e.g., a missing volatile that is needed or something).
Thank you,
David