[gnu.gcc.bug] const declarations ignored for inline functions

dl@ROCKY.OSWEGO.EDU (Doug Lea) (03/21/89)

gcc (1.34) and g++ (1.34.1) (Vax750, 4.3BSD) appear to ignore the
fact that functions are `const' when they have been inlined. Here is
an example where this detrimentally impacts optimization, especially
strength reduction.


------ file t321.c

struct mat {  double * d;  int r, c; };

static        int const    rows(struct mat* m) { return m->r; }
static        int const    cols(struct mat* m) { return m->c; }

static inline int const il_rows(struct mat* m) { return m->r; }
static inline int const il_cols(struct mat* m) { return m->c; }

void fill1(struct mat* m, double x) /* paradoxically, the faster version */
{
  int i, j;
  for (i = 0; i < rows(m); ++i)
    for (j = 0; j < cols(m); ++j)
      *(m->d + (i * cols(m) + j)) = x;
}

void fill2(struct mat* m, double x)
{
  int i, j;
  for (i = 0; i < il_rows(m); ++i)
    for (j = 0; j < il_cols(m); ++j)
      *(m->d + (i * il_cols(m) + j)) = x;
}

------ after gcc -O -S -fstrength-reduce t321.c on a Vax

#NO_APP
gcc_compiled.:
.text
	.align 1
_rows:
	.word 0x0
	movl 4(ap),r1
	movl 4(r1),r0
	ret
	.align 1
_cols:
	.word 0x0
	movl 4(ap),r1
	movl 8(r1),r0
	ret
	.align 1
.globl _fill1
_fill1:
	.word 0xfc0
	movl 4(ap),r9
	movd 8(ap),r10
	clrl r8
	pushl r9
	calls $1,_cols
	movl r0,r7
	clrl r6
	jbr L5
L12:
	clrl r1
	movl r6,r2
	jbr L8
L11:
	addl3 r2,r1,r0
	movd r10,*(r9)[r0]
	incl r1
L8:
	cmpl r1,r7
	jlss L11
	addl2 r7,r6
	incl r8
L5:
	pushl r9
	calls $1,_rows
	cmpl r8,r0
	jlss L12
	ret
	.align 1
.globl _fill2
_fill2:
	.word 0x0
	movl 4(ap),r3
	movd 8(ap),r4
	clrl r2
	jbr L13
L26:
	clrl r1
	jbr L18
L25:
	mull3 r2,8(r3),r0
	addl2 r1,r0
	movd r4,*(r3)[r0]
	incl r1
L18:
	cmpl r1,8(r3)
	jlss L25
	incl r2
L13:
	cmpl r2,4(r3)
	jlss L26
	ret