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.

Compiler/TMS320F28075: Program running unexpected if optimization enabled

Part Number: TMS320F28075

Tool/software: TI C/C++ Compiler

Hi,

Found a very strange issue with compiler version TI v16.9.5.LTS and compile options:

-v28 -ml -mt --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 -O1 --opt_for_speed=3 --fp_mode=relaxed --fp_reassoc=on

The same code is running OK with optimization disabled, but malfunctionning if optimization level set to 1:

Source code:

	mfPreRampFreq = fPreRampFreq;
	mfPreRampFreqPU = fPreRampFreq / CMotorInterface::GetRatedFrequency();

	if (fPreRampFreq * mfPostRampFreq < 0.0f) {
		fPreRampFreq = 0.0f;
	}

Compile result:

084efe:   FE02        ADDB         SP, #2
084eff:   761F0338    MOVW         DP, #0x338
 91     		fPreRampFreq = 0.0f;
084f01:   E2AF0118    MOV32        R1H, @0x18, UNCF
084f03:   761F0336    MOVW         DP, #0x336
134             return mfRatedFrequency;
084f05:   E2AF0216    MOV32        R2H, @0x16, UNCF
084f07:   761F0338    MOVW         DP, #0x338
 88     	mfPreRampFreqPU = fPreRampFreq / CMotorInterface::GetRatedFrequency();
084f09:   E2740082    DIVF32       R2H, R0H, R2H
 87     	mfPreRampFreq = fPreRampFreq;
084f0b:   E0004812    MPYF32       R1H, R1H, R0H
                   || MOV32        @0x12, R0H
 96     	switch (mState) {
084f0d:   9210        MOV          AL, @0x10
 91     		fPreRampFreq = 0.0f;
084f0e:   E8200001    MAXF32       R1H, #0x0
084f10:   E6CF0008    MOV32        R0H, R1H, UNCF

As can be seen,  R0H is holding the fPreRampFreq, R1H is holding the multiplication result. The problem is that the the multiplication result is assigned to fPreRampFreq which cause the error.

Is that a bug of the compiler? Of Any thing is wrong with my code?