This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/51506] New: Function cloning misses constant struct
- From: "peteraward+gcc at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 11 Dec 2011 23:41:13 +0000
- Subject: [Bug tree-optimization/51506] New: Function cloning misses constant struct
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51506
Bug #: 51506
Summary: Function cloning misses constant struct
Classification: Unclassified
Product: gcc
Version: 4.6.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: peteraward+gcc@gmail.com
The actual problem Iâm dealing with is with avr-gcc, so the goal is to achieve
a small code size. Iâm trying to write my code like this:
lcd_init(lcd_t l, ...)
where the first parameter is passed a *constant* struct which contains the
memory addresses of each of the pins for the LCD. Thus, I want the compiler to
note that all calls have the same first argument, clone the function, and
propagate the constant.
However, it doesnât seem to be working in practice.
In trying to build this test case, I found the compiler would just inline all
the functions, which defeats the point (in the actual code, the cost of
inlining is too high). So, Iâve added the noinline attribute, which I donât
think should stop this optimisation, but apologies if it does.
Anyhow, hereâs the testcase.
(using gcc version 4.6.2 (Debian 4.6.2-5), on 64-bit Linux)
$ cat test.c
typedef struct {
int a;
int b;
} dint;
__attribute__((noinline))
static int compute_int(int x, int var) {
int y = 0;
for (int i = 0; i < x; i++)
y += i * x;
return y + var;
}
__attribute__((noinline))
static int compute_dint(dint x, int var) {
int z = x.a + x.b;
int y = 0;
for (int i = 0; i < z; i++)
y += i * z;
return y + var;
}
int main() {
int rv;
rv += compute_dint((dint) {6, 1}, 1);
rv += compute_dint((dint) {6, 1}, 2);
rv += compute_dint((dint) {6, 1}, 3);
rv += compute_int(5, 1);
rv += compute_int(5, 2);
rv += compute_int(5, 3);
return rv;
}
$ gcc -fdump-ipa-all -fipa-cp -fipa-cp-clone -Os -std=c99 test.c
Expected result:
both compute_int and compute_dint should be optimised to versions where "x" is
constant.
Actual reslut:
only compute_int is optimised.