Hello, I am looking at a testsuite failure (wo_prof_global_var.c) in my porting. Somehow, I found GCC 4.3.0 seems to generate unnecessary malloc during structure optimization. In the code, the structure is split into two individual fields (D.2240 and D.2242) and they are allocated separately. But the original structure (D.2215) is still allocated, and not used afterward. The following RTL-level optimization cannot eliminate it.
Cheers, Bingfeng Mei Broadcom UK Original C code: /* { dg-do compile } */ /* { dg-do run } */ #include <stdlib.h> typedef struct { int a; float b; }str_t; #define N 1000 str_t *p; int main () { int i, sum; p = malloc (N * sizeof (str_t)); for (i = 0; i < N; i++) p[i].a = p[i].b + 1; for (i = 0; i < N; i++) if (p[i].a != p[i].b + 1) abort (); return 0; } .final_cleanup /*---------------------------------------------------------------------- ----*/ /* { dg-final { scan-ipa-dump "Number of structures to transform is 1" "ipa_struct_reorg" } } */ /* { dg-final { cleanup-ipa-dump "*" } } */ ;; Function main (main) main () { int i.43; unsigned int D.2245; unsigned int D.2243; void * D.2242; void * D.2240; struct struct.0_sub.1 * p.0.4; struct struct.0_sub.0 * p.0.3; int i; void * D.2215; <bb 2>: D.2215 = malloc (8000); D.2240 = malloc (4000); p.0.3 = (struct struct.0_sub.0 *) D.2240; D.2242 = malloc (4000); p.0.4 = (struct struct.0_sub.1 *) D.2242; p = (struct str_t *) D.2215; p.1 = p.0.4; p.0 = p.0.3; i = 0; <bb 3>: D.2243 = (unsigned int) i << 2; (p.0.4 + D.2243)->a = (int) ((p.0.3 + D.2243)->b + 1.0e+0); i = i + 1; if (i != 1000) goto <bb 3>; else goto <bb 4>; <bb 4>: i.43 = 0; <bb 5>: D.2245 = (unsigned int) i.43 << 2; if ((float) (p.0.4 + D.2245)->a != (p.0.3 + D.2245)->b + 1.0e+0) goto <bb 6>; else goto <bb 7>; <bb 6>: abort (); <bb 7>: i.43 = i.43 + 1; if (i.43 != 1000) goto <bb 5>; else goto <bb 8>; <bb 8>: return 0; }