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.

Disqualified loop: Loop contains control code

I'm trying to optimize a small loop, but the compiler is complaining about

a non qualified loop. I would like to understand why is this happening, if anyone can help. Here

is the loop:

for( i = 0; i < numOfSeqConst; i++, dciSeqPtr++ )
{
numOfBitTemp = numOfBit[*dciSeqPtr];
for(numOfBitTemp=numOfBitTemp; numOfBitTemp > 0 ; )
{
if(numOfShift > numOfBitTemp)
{
numOfShift = numOfShift - numOfBitTemp;
dciElemTemp = (u8)(dciElem[*dciSeqPtr] << numOfShift);
dciTbl[arrayNum] = dciTbl[arrayNum] | dciElemTemp;
numOfBitTemp = 0;
}
else if( numOfShift < numOfBitTemp )
{
numOfShift = numOfBitTemp - numOfShift;
dciElemTemp = (u8)(dciElem[*dciSeqPtr] >> numOfShift);
dciTbl[arrayNum] = dciTbl[arrayNum] | dciElemTemp ;
/* the byte is full, start new byte to next round */
arrayNum ++;
numOfBitTemp = numOfShift; /* amount of bits to next round */
numOfShift = MAX_NUM_OF_BITS_PER_DCI_ARRAY;
}
else /* numOfShift = numOfBit */
{
dciElemTemp = (u8)dciElem[*dciSeqPtr];
dciTbl[arrayNum] = dciTbl[arrayNum] | dciElemTemp;
/* the byte is full, start new byte to next round */
arrayNum ++;
numOfBitTemp = 0;
numOfShift = MAX_NUM_OF_BITS_PER_DCI_ARRAY;

}
}
}

asm info:

;*----------------------------------------------------------------------------*
;* SOFTWARE PIPELINE INFORMATION
;* Disqualified loop: Loop contains control code
;*----------------------------------------------------------------------------*
$C$L246:
$C$DW$L$_DciMap__27CDlPsCpLaMain_IDlPsCpLaCtrlCFPC15SCellCfgCpLaDcmP11SDciInfoDcm$31$B:
0,is_stmt
; EXCLUSIVE CPU CYCLES: 22
;** -----------------------g27:
;* 2436 ----------------------- if ( numOfShift > numOfBitTemp ) goto g31;
;* 2443 ----------------------- if ( numOfShift < numOfBitTemp ) goto g30;
;* 2456 ----------------------- A$8 = *U$291|U$294;
;* 2456 ----------------------- *U$291++ = A$8;
;* 2458 ----------------------- ++arrayNum;
;* 2459 ----------------------- numOfBitTemp = 0u;
;* 2460 ----------------------- numOfShift = 8u;
;* 2460 ----------------------- goto g32;
;** -----------------------g30:
;* 2445 ----------------------- numOfShift = numOfBitTemp-numOfShift;
;* 2447 ----------------------- A$7 = *U$291|U$294>>numOfShift;
;* 2447 ----------------------- *U$291++ = A$7;
;* 2449 ----------------------- ++arrayNum;
;* 2450 ----------------------- numOfBitTemp = numOfShift;
;* 2451 ----------------------- numOfShift = 8u;
;* 2452 ----------------------- goto g32;
;** -----------------------g31:
;* 2438 ----------------------- numOfShift -= numOfBitTemp;
;* 2440 ----------------------- *U$291 = *U$291|U$294<<numOfShift;
;* 2441 ----------------------- numOfBitTemp = 0u;
;** -----------------------g32:
;* 2434 ----------------------- if ( numOfBitTemp ) goto g27;
CMPGTU .L1 A10,A1,A2 ; |2436|

[ A2] LDBU .D1T1 *A4,A6 ; |2440|
|| [ A2] SUB .S1 A10,A1,A10 ; |2438|
|| [!A2] CMPLTU .L1 A10,A1,A0 ; |2443|

[ A2] SHL .S1 A5,A10,A7 ; |2440|
|| [ A2] MVK .L1 0x1,A0
|| [ A2] ZERO .D1 A1 ; |2441|

[!A0] ADD .L2 1,B11,B11 ; |2458|
[!A0] MVK .L1 0x8,A10 ; |2460|
[!A0] ZERO .L1 A1 ; |2459|
[ A2] OR .L1 A7,A6,A6 ; |2440|

[ A2] STB .D1T1 A6,*A4 ; |2440|
|| MV .L1 A0,A6

[!A0] LDBU .D1T1 *A4,A7 ; |2456|
|| [ A2] ZERO .L1 A6

MV .L1 A6,A2 ; |2456|
[ A2] SUB .L1 A1,A10,A1 ; |2445|
[ A2] ADD .L2 1,B11,B11 ; |2449|
[ A2] MVK .L1 0x8,A10 ; |2451|
[!A0] OR .L1 A5,A7,A7 ; |2456|

[!A0] STB .D1T1 A7,*A4++ ; |2456|
|| [ A2] SHRU .S1 A5,A1,A7 ; |2447|

[ A2] LDBU .D1T1 *A4,A6 ; |2447|
[ A1] BNOP .S1 $C$L246,3 ; |2434|
[ A2] OR .L1 A7,A6,A6 ; |2447|

  • In your case, "Loop contains control code" means that the innermost loop has an if-then statement that the compiler could not turn into predicated code, most likely because it is too long.  After software pipelineing was disqualified, the compiler apparently was able to turn it into predicated code; I don't know why.

    You might be able to get this to software pipeline if you adjust your code a bit.  Note that the '<' case and the '=' case are nearly identical, and they can be folded together by taking advantage of the fact that a shift by zero is legal:

    [..]
    else if( numOfShift <= numOfBitTemp )
    {
    numOfShift = numOfBitTemp - numOfShift;
    dciElemTemp = (u8)(dciElem[*dciSeqPtr] >> numOfShift);
    dciTbl[arrayNum] = dciTbl[arrayNum] | dciElemTemp ;
    /* the byte is full, start new byte to next round */
    arrayNum ++;
    numOfBitTemp = numOfShift; /* amount of bits to next round */
    numOfShift = MAX_NUM_OF_BITS_PER_DCI_ARRAY;
    }
    [..]