[PR70920] transform (intptr_t) x eq/ne CST to x eq/ne (typeof x) cst

Prathamesh Kulkarni prathamesh.kulkarni@linaro.org
Thu Jul 28 12:51:00 GMT 2016


On 28 July 2016 at 15:58, Andreas Schwab <schwab@suse.de> wrote:
> On Mo, Jul 25 2016, Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> wrote:
>
>> diff --git a/gcc/testsuite/gcc.dg/pr70920-4.c b/gcc/testsuite/gcc.dg/pr70920-4.c
>> new file mode 100644
>> index 0000000..dedb895
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.dg/pr70920-4.c
>> @@ -0,0 +1,21 @@
>> +/* { dg-do compile } */
>> +/* { dg-options "-O2 -fdump-tree-ccp-details -Wno-int-to-pointer-cast" } */
>> +
>> +#include <stdint.h>
>> +
>> +void f1();
>> +void f2();
>> +
>> +void
>> +foo (int a)
>> +{
>> +  void *cst = 0;
>> +  if ((int *) a == cst)
>> +    {
>> +      f1 ();
>> +      if (a)
>> +     f2 ();
>> +    }
>> +}
>> +
>> +/* { dg-final { scan-tree-dump "gimple_simplified to if \\(_\[0-9\]* == 0\\)" "ccp1" } } */
>
> This fails on all ilp32 platforms.
Oops, sorry for the breakage.
With -m32, the pattern is applied during forwprop1 rather than ccp1.
I wonder though why ccp1 fails to fold the pattern with -m32 ?
Looking at the dumps:

without -m32:
input to ccp1 pass:
  <bb 2>:
  cst_4 = 0B;
  _1 = (long int) a_5(D);
  _2 = (void *) _1;
  if (cst_4 == _2)
    goto <bb 3>;
  else
    goto <bb 5>;

cc1 pass dump shows:
Substituting values and folding statements

Folding statement: _1 = (long int) a_5(D);
Not folded
Folding statement: _2 = (void *) _1;
Not folded
Folding statement: if (cst_4 == _2)
which is likely CONSTANT
Applying pattern match.pd:2537, gimple-match.c:6530
gimple_simplified to if (_1 == 0)
Folded into: if (_1 == 0)

with -m32:
input to ccp1 pass:
 <bb 2>:
  cst_3 = 0B;
  a.0_1 = (void *) a_4(D);
  if (cst_3 == a.0_1)
    goto <bb 3>;
  else
    goto <bb 5>;

ccp1 pass dump shows:
Substituting values and folding statements

Folding statement: a.0_1 = (void *) a_4(D);
Not folded
Folding statement: if (cst_3 == a.0_1)
which is likely CONSTANT
Folded into: if (a.0_1 == 0B)

I am not able to understand why it doesn't fold it to
if (a_4(D) == 0) ?
forwprop1 folds a.0_1 == 0B to a_4(D) == 0.

I suppose the test-case would need to scan ccp1 for non-ilp targets
and forwprop1 for
ilp targets. How do update the test-case to reflect this ?

Thanks,
Prathamesh
>
> Andreas.
>
> --
> Andreas Schwab, SUSE Labs, schwab@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."



More information about the Gcc-patches mailing list