[EXT_EP-10449] Optimizer drops part of a compound conditional expression controlling a loop Created: 12/Jul/21  Updated: 10/Feb/22  Resolved: 10/Feb/22

Status: Fixed
Project: Embedded Software & Tools
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Medium
Reporter: TI User Assignee: TI User
Resolution: Fixed Votes: 0
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Product: Code Generation Tools
Internal ID: CODEGEN-9082
Forum URL: https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1014790/c6000-cgt-cgt-8-3-9---cl6x-not-considering-multiple-exit-conditions-present-in-for-loop-syntax
Found In Release: C6000_8.3.9
Fix In Release: C7000_2.1.1.LTS
MSP430_18.12.9.LTS*
C6000_8.3.12*
C7000_1.4.3.LTS*
MSP430_20.2.6.LTS
MSP430_21.6.1.LTS*
Affected Platform/Device: default

 Description   

The attached test case contains this code ...

    for (u32 i = 0; (i < arrSize && i < CByteAligner::bitsToOctetsRoundUp(tbSize)); i++) /* PROBLEM FOR LOOP */ 
        localMem[i] = p_corruptedPdu[i];

The generated code accounts for the i < CByteAligner::bitsToOctetsRoundUp(tbSize)) part of the condition controlling the loop. But not the i < arrSize part.

Build it ...

% cl6x -@options.txt file.cpp

Inspect the compiler generated comments for the problem loop.

;* 128211       -----------------------    memset(&localMem, 0, 16u);
;* 128212       -----------------------    K$13 = tbSize+7u;
;* 128212       -----------------------    if ( !(C$5 = K$13>>3) ) goto g4;
;**     -----------------------    U$21 = p_corruptedPdu;
;* 128213       -----------------------    L$1 = C$5;
;**     -----------------------    U$23 = &localMem[0];
;**     -----------------------    #pragma MUST_ITERATE(1, 16, 1)
;**     -----------------------    #pragma LOOP_FLAGS(4096u)
;**     -----------------------g3:
;* 128213       -----------------------    *U$23++ = *U$21++;
;* 128212       -----------------------    if ( L$1 = L$1-1 ) goto g3;
;**     -----------------------g4:

L$1 controls this loop. It down counts from CByteAligner::bitsToOctetsRoundUp(tbSize)) to 0. But this ignores the i < 16 part of the loop condition.


Generated at Sun Apr 06 14:18:35 CDT 2025 using Jira 9.12.17#9120017-sha1:aba4002bcd633f188b6a4bb5dd8a0e1f20b79ee4.