This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

arm-ecos-elf-gcc strange optimization


Hi,

I tried to use gcc v.3.1 for small test project. My goal was to get from the
compiler the smallest possible code size. Using different optimization
options I have got very strange results: as a rule code size is much smaller
with optimization by speed (-O2) than with optimization by size (-Os). The
compiler produces even smaller code with -O3 because of extensive inline
substitutions.

As an example you can see two listing fragments with different optimization
options. Both are the same function, initializing USART (it stores a few
numbers into memory).

With -O2:

  21 0000 0A12A0E3 		mov	r1, #-1610612736
  22 0004 C116A0E1 		mov	r1, r1, asr #13
  23 0008 4130A0E3 		mov	r3, #65
  24 000c 203081E5 		str	r3, [r1, #32]
  25              	.LM3:
  26 0010 232DA0E3 		mov	r2, #2240
  27              	.LM4:
  28 0014 2800A0E3 		mov	r0, #40
  29 0018 BF3BE0E3 		mvn	r3, #195584
  30              	.LM5:
  31 001c 042081E5 		str	r2, [r1, #4]
  32              	.LM6:
  33 0020 D70303E5 		str	r0, [r3, #-983]
  34              	.LM7:
  35 0024 572FA0E3 		mov	r2, #348
  36              	.LM8:
  37 0028 0309A0E3 		mov	r0, #49152
  38 002c FF3CE0E3 		mvn	r3, #65280
  39              	.LM9:
  40 0030 002081E5 		str	r2, [r1, #0]
  41              	.LM10:
  42              		@ lr needed for prologue
  43              	.LM11:
  44 0034 FB0003E5 		str	r0, [r3, #-251]
  45 0038 0EF0A0E1 		mov	pc, lr

With -Os:

  21 0000 38309FE5 		ldr	r3, .L2
  22 0004 4120A0E3 		mov	r2, #65
  23 0008 002083E5 		str	r2, [r3, #0]
  24              	.LM3:
  25 000c 232DA0E3 		mov	r2, #2240
  26 0010 1C3043E2 		sub	r3, r3, #28
  27 0014 002083E5 		str	r2, [r3, #0]
  28              	.LM4:
  29 0018 2820A0E3 		mov	r2, #40
  30 001c 243083E2 		add	r3, r3, #36
  31 0020 002083E5 		str	r2, [r3, #0]
  32              	.LM5:
  33 0024 4D2F82E2 		add	r2, r2, #308
  34 0028 283043E2 		sub	r3, r3, #40
  35 002c 002083E5 		str	r2, [r3, #0]
  36              	.LM6:
  37 0030 0C309FE5 		ldr	r3, .L2+4
  38 0034 0329A0E3 		mov	r2, #49152
  39              	.LM7:
  40              		@ lr needed for prologue
  41              	.LM8:
  42 0038 002083E5 		str	r2, [r3, #0]
  43 003c 0EF0A0E1 		mov	pc, lr
  44              	.L3:
  45              		.align	2
  46              	.L2:
  47 0040 2000FDFF 		.word	-196576
  48 0044 0400FFFF 		.word	-65532

Any thoughts?

Eugene.


------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]