Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

Unnecessary instructions

Hello, it's my first post.

I have question about GCC generated code. We can find several unnecessary instructions.

--- sample code ---

unsigned short uh;

uh = IORD_16DIRECT(base,ofst);

printf("",uh);

--- GCC generated (part) ---

ldhuio r18,0(r16)

andi r20, r18, 65535 *

call printf

"ldhuio" instruction is zero-extending load, so r18 is already zero-extended. Next "andi" is unnecessary.

Here is another sample.

--- sample code ---

short sh;

sh = __builtin_ldhio(base);

printf("",sh);

--- GCC generated (part) ---

ldhio r17, 0(r16)

slli r7, r17, 16 *

srai r21, r7, 16 *

call printf

Also, "ldhio" is signed-extending load, so r17 is already signed-extended. Next 2 shifts are waste.

Does anyone have ideas to eliminate these unnecessary instructions?

Regards,

marm

11 Replies