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.

CCS/MSP-CGT: Inefficient common BIC.B optimisation.

Part Number: MSP-CGT

Tool/software: Code Composer Studio

Given the following function:

extern unsigned char src, dst;

void func(void)
{
    dst &= ~src;
}

The CGT compiler produces the following output:

;*****************************************************************************
;* FUNCTION NAME: func                                                       *
;*                                                                           *
;*   Regs Modified     : SP,SR,r15                                           *
;*   Regs Used         : SP,SR,r15                                           *
;*   Local Frame Size  : 0 Args + 0 Auto + 0 Save = 0 byte                   *
;*****************************************************************************
func:
;* --------------------------------------------------------------------------*
	.dwcfi	cfa_offset, 4
	.dwcfi	save_reg_to_mem, 16, -4
;** 6	-----------------------    src &= dst^0xff;
	.dwpsn	file "../src/bic.c",line 6,column 5,is_stmt,isa 0
        MOV.W     #255,r15              ; [] |6| 
        XOR.B     &dst+0,r15            ; [] |6| 
        AND.B     r15,&src+0            ; [] |6| 
;**  	-----------------------    return;
$C$DW$4	.dwtag  DW_TAG_TI_branch
	.dwattr $C$DW$4, DW_AT_low_pc(0x00)
	.dwattr $C$DW$4, DW_AT_TI_return

        RETA      ; [] 
        ; [] 
	.dwattr $C$DW$3, DW_AT_TI_end_file("../src/bic.c")
	.dwattr $C$DW$3, DW_AT_TI_end_line(0x07)
	.dwattr $C$DW$3, DW_AT_TI_end_column(0x01)
	.dwendentry
	.dwendtag $C$DW$3

This should instead just produce `BIC.B &src,&dst`.  This doesn't seem like much of a problem except that this particular construct is very common in our program for clearing port bits and the compiler generated code is 4x the size of the trivially optimal version.

  • Sorry, the produced output should have been:

    ;*****************************************************************************
    ;* FUNCTION NAME: func                                                       *
    ;*                                                                           *
    ;*   Regs Modified     : SP,SR,r15                                           *
    ;*   Regs Used         : SP,SR,r15                                           *
    ;*   Local Frame Size  : 0 Args + 0 Auto + 0 Save = 0 byte                   *
    ;*****************************************************************************
    func:
    ;* --------------------------------------------------------------------------*
    	.dwcfi	cfa_offset, 4
    	.dwcfi	save_reg_to_mem, 16, -4
    ;** 6	-----------------------    dst &= src^0xff;
    	.dwpsn	file "../src/bic.c",line 6,column 5,is_stmt,isa 0
            MOV.W     #255,r15              ; [] |6| 
            XOR.B     &src+0,r15            ; [] |6| 
            AND.B     r15,&dst+0            ; [] |6| 
    ;**  	-----------------------    return;
    $C$DW$4	.dwtag  DW_TAG_TI_branch
    	.dwattr $C$DW$4, DW_AT_low_pc(0x00)
    	.dwattr $C$DW$4, DW_AT_TI_return
    
            RETA      ; [] 
            ; [] 
    	.dwattr $C$DW$3, DW_AT_TI_end_file("../src/bic.c")
    	.dwattr $C$DW$3, DW_AT_TI_end_line(0x07)
    	.dwattr $C$DW$3, DW_AT_TI_end_column(0x01)
    	.dwendentry
    	.dwendtag $C$DW$3

  • Thank you for notifying of us of this problem, and submitting a concise test case.  I can reproduce the same behavior.  I filed the entry EXT_EP-9617 to have this issue investigated.  Because the generated code is correct, the entry does not report a bug, but requests an improvement in the compiler.  You can track the entry by searching for the entry ID at this link.

    Note that, if you disable optimization with the build option --opt_level=off, then the BIC instruction is emitted.  I realize this may not be a practical workaround.  But it is something to consider.

    Thanks and regards,

    -George