But how can a function outside of the file use "p" here after
struct_reorg optmization. It isn't correct.
p = malloc (N * sizeof (str_t));
for (i = 0; i < N; i++)
p[i].a = p[i].b + 1;
foo(); <-- Assume foo() in another file access p here. It will
either access uninitialized memory chunk (D.2215), or access two split
substructures, then make the first allocated memory useless.
-----Original Message-----
From: Kenneth Zadeck [mailto:[EMAIL PROTECTED]
Sent: 01 May 2008 15:09
To: Bingfeng Mei
Cc: Olga Golovanevsky; [email protected]
Subject: Re: Redundant malloc in structure optimization?
(testsuite/gcc.dg/struct/wo_prof_global_var.c)
Bingfeng Mei wrote:
> Olga,
> Yes, I agree the "p" is global. But how p is going to be accessed if
> another file uses p? D.2215 represents the original "p", but it is
not
> initialized as "p.0.4" and "p.0.3" do. It won't be correct if other
file
> tried to use it. Am I right?
>
> Cheers,
> Bingfeng
>
>
I would be surprised if we could remove a dead malloc (assuming that we
could determine that p was dead, which is another issue). It would not
be hard to add this but p is the hardest problem.
kenny
>> 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;
>>
>
> -----Original Message-----
> From: Olga Golovanevsky [mailto:[EMAIL PROTECTED]
> Sent: 01 May 2008 13:19
> To: Bingfeng Mei
> Cc: [email protected]; Kenneth Zadeck
> Subject: Re: Redundant malloc in structure optimization?
> (testsuite/gcc.dg/struct/wo_prof_global_var.c)
>
>
>
> [EMAIL PROTECTED] wrote on 28/04/2008 12:36:44:
>
>
>> 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.
>>
>
> I think that p is global, and in my understanding right now we have no
> whole
> program dead code elimination optimization in gcc, but may be I am
> wrong.
>
> Kenny?
>
> Olga
>
>
>> 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;
>>
>> }
>>
>>
>>
>>
>>
>
>
>
>