# optimizing address calculation?

## joggingsong@gmail.comTue, 18 Sep 2007 03:36:12 -0000

From comp.compilers

Related articles
optimizing address calculation? joggingsong@gmail.com (2007-09-18)
Re: optimizing address calculation? DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-09-18)
Re: optimizing address calculation? rupesh0508@gmail.com (2007-09-24)
Re: optimizing address calculation? alexc@TheWorld.com (Alex Colvin) (2007-09-24)
Re: optimizing address calculation? joggingsong@gmail.com (2007-09-25)
| List of all articles for this month |

 From: joggingsong@gmail.com Newsgroups: comp.compilers Date: Tue, 18 Sep 2007 03:36:12 -0000 Organization: Compilers Central Keywords: C, optimize, question Posted-Date: 18 Sep 2007 08:13:52 EDT

Hi, everyone.I encountered the problem and hope to get help from you.

Here is some structs definition.
typedef struct test{
int a[20];
int b[20];

}test1;

typedef struct test{
int c[20];
int d[20];
test1 test1a[20];
}test2;

test2 test2a;
test2 *pTest2a = &test2a;

in the program, I refer to the variable test2a by the pointer
for example

for(i = 0; i <20; i++)
{
pTest2a->test1a[x].b[i] = i;
}

Although in the loop pTest2a->test1a[x] is fixed, it seems the
generated codes calculate
the address from pTest2a. If it is changed to the following:

int pInt = pTest2a->test1a[x].b;
for(i = 0; i < 20; i++)
{
*pInt++ = i;
}
The new generated code is much faster.
Is it difficult for c compiler to generate the faster code?

Thanks
Jogging

[I don't think it's difficult, I think nested structures of arrays are
rare enough that the people who write optimizer in whatever compiler
you're using didn't worry about it. -John]

Post a followup to this message