Hi there, we ported gcc 4.8.1 to our ptivate target and the code is bloated for the array access as shown below
C file : int a[10]; int i; test() { a[9] = 10; a[i] = 20; } xgcc -O2 -S test.c _test: ld (_a+18), 10 ;a[9] = 10; ld WA, (_i) ; a[i] = 20; add WA, WA add WA, _a ld HL, WA ld (HL), 20 ret .comm _i, 2,2 .comm _a, 20,20 The above generated code looks better when compare to below generated code with no optimisations xgcc -S test.c .comm _a, 20,20 .comm _i, 2,2 .type _test, %function _test: sub SP, 4 ld WA, 10 ld (_a+18), WA ; a[9] = 10; ld WA, (_i) ;code bloated here for a[i] ld IX, WA ld BC, 15 cal _C87C_shris ld IY, WA ld DE, WA ld HL, BC ld WA, IX add WA, IX ld DE, WA ld WA, DE ld BC, HL ld HL, 1 ld (SP+2), HL cmp WA,IX j lt,_.L2 ld DE, 0 ld (SP+2), DE .L2: ld DE, WA ld HL, BC ld BC, IY add BC, IY ld HL, BC ld WA, DE ld BC, HL ld DE, (SP+2) add DE, BC ld BC, DE ld HL, WA ld (SP+0), HL ld WA, 20 ld HL, (SP+0) ld (a+i), WA add SP, 4 ret when you access the array with the constant index i.e a[9] the generated code was better. but could not track why the code is bloated for the a[i] access. Please somebody from the group can share their thoughts and will be appricate the same. Thank you ~Umesh