[tree-optimization/71947] Avoid unwanted propagations

Jeff Law law@redhat.com
Wed Oct 19 16:33:00 GMT 2016


On 10/12/2016 09:00 AM, Georg-Johann Lay wrote:
> On 10.10.2016 23:06, Jeff Law wrote:
>>
>>
>> So if we have an equality conditional between A & B, we record into our
>> const/copy tables A = B and B = A.
>>
>> This helps us discover some of the more obscure equivalences. But it also
>> creates problems with an expression like
>>
>> A ^ B
>>
>> Where we might cprop the first operand generating
>>
>> B ^ B
>>
>> Then the second generating
>>
>> B ^ A
>>
>> ANd we've lost the folding opportunity.  At first I'd tried folding
>> after each
>> propagation step, but that turns into a bit of a nightmare because of
>> changes
>> in the underlying structure of the gimple statement and cycles that
>> may develop
>> if we re-build the operand cache after folding.
>>
>> This approach is simpler and should catch all these cases for binary
>> operators.  We just track the last copy propagated argument and refuse to
>> ping-pong propagations.
>>
>> It fixes the tests from 71947 and 77647 without regressing
>> (obviously). I've
>> included an xfailed test for a more complex situation that we don't
>> currently
>> handle (would require backtracking from the equality comparison
>> through the
>> logicals that feed the equality comparison).
>>
>> Bootstrapped and regression tested on x86_64.  Applied to the trunk.
>>
>> commit 6223e6e425b6de916f0330b9dbe5698765d4a73c
>> Author: law <law@138bc75d-0d04-0410-961f-82ee72b054a4>
>> Date:   Mon Oct 10 20:40:59 2016 +0000
>>
>>             PR tree-optimization/71947
>>         * tree-ssa-dom.c (cprop_into_stmt): Avoid replacing A with B,
>> then
>>         B with A within a single statement.
>>
>>         PR tree-optimization/71947
>>         * gcc.dg/tree-ssa/pr71947-1.c: New test.
>>         * gcc.dg/tree-ssa/pr71947-2.c: New test.
>>         * gcc.dg/tree-ssa/pr71947-3.c: New test.
>>         * gcc.dg/tree-ssa/pr71947-4.c: New test.
>>         * gcc.dg/tree-ssa/pr71947-5.c: New test.
>>         * gcc.dg/tree-ssa/pr71947-6.c: New test.
>>
>>     git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@240947
>> 138bc75d-0d04-0410-961f-82ee72b054a4
>>
>> diff --git a/gcc/ChangeLog b/gcc/ChangeLog
>> index 1738bc7..16e25bf 100644
>> --- a/gcc/ChangeLog
>> +++ b/gcc/ChangeLog
>> @@ -1,3 +1,9 @@
>> +2016-10-10  Jeff Law  <law@redhat.com>
>> +
>> +        PR tree-optimization/71947
>> +    * tree-ssa-dom.c (cprop_into_stmt): Avoid replacing A with B, then
>> +    B with A within a single statement.
>> +
>>  2016-10-10  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
>>
>>      PR tree-optimization/77824
>> diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
>> index 04966cf..e31bcc6 100644
>> --- a/gcc/testsuite/ChangeLog
>> +++ b/gcc/testsuite/ChangeLog
>> @@ -1,3 +1,13 @@
>> +2016-10-10  Jeff Law  <law@redhat.com>
>> +
>> +    PR tree-optimization/71947
>> +    * gcc.dg/tree-ssa/pr71947-1.c: New test.
>> +    * gcc.dg/tree-ssa/pr71947-2.c: New test.
>> +    * gcc.dg/tree-ssa/pr71947-3.c: New test.
>> +    * gcc.dg/tree-ssa/pr71947-4.c: New test.
>> +    * gcc.dg/tree-ssa/pr71947-5.c: New test.
>> +    * gcc.dg/tree-ssa/pr71947-6.c: New test.
>> +
>>  2016-10-10  Thomas Koenig  <tkoenig@gcc.gnu.org>
>>
>>      PR fortran/77915
>> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71947-1.c
>> b/gcc/testsuite/gcc.dg/tree-ssa/pr71947-1.c
>> new file mode 100644
>> index 0000000..b033495
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71947-1.c
>> @@ -0,0 +1,19 @@
>> +/* { dg-do compile } */
>> +/* { dg-options "-O2 -fno-tree-vrp -fdump-tree-dom-details" } */
>> +
>> +
>> +int f(int x, int y)
>> +{
>> +   int ret;
>> +
>> +   if (x == y)
>> +     ret = x ^ y;
>> +   else
>> +     ret = 1;
>> +
>> +   return ret;
>> +}
>> +
>> +/* { dg-final { scan-tree-dump "Folded to: ret_\[0-9\]+ = 0;"  "dom2"
>> } } */
>> +
>> +
>> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71947-2.c
>> b/gcc/testsuite/gcc.dg/tree-ssa/pr71947-2.c
>> new file mode 100644
>> index 0000000..de8f88b
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71947-2.c
>> @@ -0,0 +1,16 @@
>> +/* { dg-do compile } */
>> +/* { dg-options "-O2 -fno-tree-vrp -fdump-tree-dom-details" } */
>> +
>> +
>> +int f(int x, int y)
>> +{
>> +  int ret;
>> +  if (x == y)
>> +    ret = x - y;
>> +  else
>> +    ret = 1;
>> +
>> +  return ret;
>> +}
>> +
>> +/* { dg-final { scan-tree-dump "Folded to: ret_\[0-9\]+ = 0;"  "dom2"
>> } } */
>> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71947-3.c
>> b/gcc/testsuite/gcc.dg/tree-ssa/pr71947-3.c
>> new file mode 100644
>> index 0000000..e79847f
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71947-3.c
>> @@ -0,0 +1,12 @@
>> +/* { dg-do compile } */
>> +/* { dg-options "-O2 -fno-tree-vrp -fdump-tree-dom-details" } */
>> +
>> +int f(int x, int y)
>> +{
>> +  int ret = 10;
>> +  if (x == y)
>> +    ret = x  -  y;
>> +  return ret;
>> +}
>> +
>> +/* { dg-final { scan-tree-dump "Folded to: ret_\[0-9\]+ = 0;"  "dom2"
>> } } */
>> diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71947-4.c
>> b/gcc/testsuite/gcc.dg/tree-ssa/pr71947-4.c
>> new file mode 100644
>> index 0000000..a881f0d
>> --- /dev/null
>> +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71947-4.c
>> @@ -0,0 +1,22 @@
>> +/* { dg-do compile } */
>> +/* { dg-options "-O2 -fno-tree-vrp -fdump-tree-dom-details" } */
>> +
>> +
>> +
>> +static inline long load(long *p)
>> +{
>> +        long ret;
>> +        asm ("movq      %1,%0\n\t" : "=r" (ret) : "m" (*p));
>
>
> Hi, shouldn't this test be restricted to target machines that understand
> MOVQ?
>
> Same issue for gcc.dg/tree-ssa/pr71947-5.c below.
It shouldn't actually matter -- we compile to assembly, but never try to 
assemble the resulting code.  One could replace the movq with anything.

The test actually verifies simplification of the return statement in 
"foo". In one test it should be 2*ret and the other 0.  In neither case 
should it load *mem again.

jeff
>



More information about the Gcc-patches mailing list