On Sun, Nov 4, 2012 at 2:13 PM, Martin Jambor <mjam...@suse.cz> wrote:
> Hi,
>
> On Sat, Nov 03, 2012 at 09:01:53AM +0000, Yangyueming wrote:
>> Hi, all
>>
>> I do the research of min max instructions recently. I find it is related 
>> with phiopt.
>>
>> case1:
>> int foo(short a ,short b)
>> {
>>   if (a < b)
>>     a = b;
>>   return a;
>> }
>>
>> It is successed in pass phiopt1(-O2 with gcc 4.7.0). The MAX_EXPR can be 
>> generated.
>>
>> foo (short int a, short int b)
>> {
>>   int D.2094;
>>
>> <bb 2>:
>>   a_9 = MAX_EXPR <a_2(D), b_3(D)>;
>>   D.2094_5 = (int) a_9;
>>   return D.2094_5;
>>
>> }
>>
>> But when I do the test for a case with a little change, it is failed to 
>> generate MAX_EXPR in phiopt1.
>> The failed case2 :
>> int foo(short a ,short b)
>> {
>>   int c;
>>   if (a < b)
>>     a = b;
>>
>>   c = *(int *)&a;
>
> ehm, and just what do you expect the result of the above line to be?
>
>>   return c;
>> }
>>
>> I find it is because of the esra pass failed to generate PHI NODE.
>
> First and foremost, esra only deals with aggregate types and nothing
> in any of your examples is an aggregate, therefore esra does not touch
> your examples in any way.  Even though the a$0 temporary has a dollar
> sign in it, that does not mean it is created by SRA.  On my i686
> desktop the temporary is called a.0 and it is generated because in
> gimple all scalar loads and stores have to go through a variable in
> SSA form.
>
> Nevertheless, I can tell why there is no phi node for a. a has its
> address taken and therefore it is not in SSA form (as clearly visible
> in the first statements in bb 2 and bb 3).  Thus, no PHI nodes for a.
>

Why 'a' has no SSA form if it's address taken?
I didn't check the code, but I guess it may because 'a' value is not
directly used.

>> Dump of phifail.c.027t.esra:
>> foo (short int a, short int b)
>> {
>>   int c;
>>   short int a$0;
>>
>> <bb 2>:
>>   a$0_1 = a;
>>   if (a$0_1 < b_2(D))
>>     goto <bb 3>;
>>   else
>>     goto <bb 4>;
>>
>> <bb 3>:
>>   a = b_2(D);
>>
>> <bb 4>:
>>   c_4 = MEM[(int *)&a];
>>   c_5 = c_4;
>>   return c_5;
>>
>> }
>>
>> Why it is failed and if there's a way to make it work?
>
> I believe that the modified input has undefined semantics (sorry, I
> don't have time to verify this in the standard) and so no, there is no
> way to make it work.
>
> Martin



-- 
Thanks.
Handong

Reply via email to