* [PATCH] Fix PR80275
@ 2017-04-03 9:16 Richard Biener
2017-04-04 5:34 ` Markus Trippelsdorf
0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2017-04-03 9:16 UTC (permalink / raw)
To: gcc-patches
The following extends split_address_to_core_and_offset to handle
POINTER_PLUS_EXPR to be able to simplify
(unsigned long) &MEM[(void *)&D.15512 + 12B] - (unsigned long) ((const int
*) &D.15512 + 4) which appears during niter analysis.
We seem to have various copies of similar code but refactoring didn't
seem appropriate at this stage so I went for the minimal fix.
Bootstrap and regtest running on x86_64-unknown-linux-gnu.
Richard.
2017-04-03 Richard Biener <rguenther@suse.de>
PR tree-optimization/80275
* fold-const.c (split_address_to_core_and_offset): Handle
POINTER_PLUS_EXPR.
* g++.dg/opt/pr80275.C: New testcase.
Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c (revision 246642)
+++ gcc/fold-const.c (working copy)
@@ -14341,6 +14341,24 @@ split_address_to_core_and_offset (tree e
&volatilep);
core = build_fold_addr_expr_loc (loc, core);
}
+ else if (TREE_CODE (exp) == POINTER_PLUS_EXPR)
+ {
+ core = TREE_OPERAND (exp, 0);
+ STRIP_NOPS (core);
+ *pbitpos = 0;
+ *poffset = TREE_OPERAND (exp, 1);
+ if (TREE_CODE (*poffset) == INTEGER_CST)
+ {
+ offset_int tem = wi::sext (wi::to_offset (*poffset),
+ TYPE_PRECISION (TREE_TYPE (*poffset)));
+ tem <<= LOG2_BITS_PER_UNIT;
+ if (wi::fits_shwi_p (tem))
+ {
+ *pbitpos = tem.to_shwi ();
+ *poffset = NULL_TREE;
+ }
+ }
+ }
else
{
core = exp;
Index: gcc/testsuite/g++.dg/opt/pr80275.C
===================================================================
--- gcc/testsuite/g++.dg/opt/pr80275.C (nonexistent)
+++ gcc/testsuite/g++.dg/opt/pr80275.C (working copy)
@@ -0,0 +1,16 @@
+// { dg-do compile { target c++14 } }
+// { dg-options "-O2 -fdump-tree-optimized" }
+
+#include <algorithm>
+
+int g()
+{
+ return 1234;
+}
+
+int f2()
+{
+ return std::min({1, g(), 4});
+}
+
+// { dg-final { scan-tree-dump "return 1;" "optimized" } }
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR80275
2017-04-03 9:16 [PATCH] Fix PR80275 Richard Biener
@ 2017-04-04 5:34 ` Markus Trippelsdorf
2017-04-04 6:22 ` Marc Glisse
0 siblings, 1 reply; 4+ messages in thread
From: Markus Trippelsdorf @ 2017-04-04 5:34 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc-patches
On 2017.04.03 at 11:16 +0200, Richard Biener wrote:
>
> The following extends split_address_to_core_and_offset to handle
> POINTER_PLUS_EXPR to be able to simplify
> (unsigned long) &MEM[(void *)&D.15512 + 12B] - (unsigned long) ((const int
> *) &D.15512 + 4) which appears during niter analysis.
>
> We seem to have various copies of similar code but refactoring didn't
> seem appropriate at this stage so I went for the minimal fix.
>
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
>
> Richard.
>
> 2017-04-03 Richard Biener <rguenther@suse.de>
>
> PR tree-optimization/80275
> * fold-const.c (split_address_to_core_and_offset): Handle
> POINTER_PLUS_EXPR.
>
> * g++.dg/opt/pr80275.C: New testcase.
>
> Index: gcc/fold-const.c
> ===================================================================
> --- gcc/fold-const.c (revision 246642)
> +++ gcc/fold-const.c (working copy)
> @@ -14341,6 +14341,24 @@ split_address_to_core_and_offset (tree e
> &volatilep);
> core = build_fold_addr_expr_loc (loc, core);
> }
> + else if (TREE_CODE (exp) == POINTER_PLUS_EXPR)
> + {
> + core = TREE_OPERAND (exp, 0);
> + STRIP_NOPS (core);
> + *pbitpos = 0;
> + *poffset = TREE_OPERAND (exp, 1);
> + if (TREE_CODE (*poffset) == INTEGER_CST)
> + {
> + offset_int tem = wi::sext (wi::to_offset (*poffset),
> + TYPE_PRECISION (TREE_TYPE (*poffset)));
> + tem <<= LOG2_BITS_PER_UNIT;
> + if (wi::fits_shwi_p (tem))
> + {
> + *pbitpos = tem.to_shwi ();
> + *poffset = NULL_TREE;
> + }
> + }
> + }
> else
> {
> core = exp;
> Index: gcc/testsuite/g++.dg/opt/pr80275.C
> ===================================================================
> --- gcc/testsuite/g++.dg/opt/pr80275.C (nonexistent)
> +++ gcc/testsuite/g++.dg/opt/pr80275.C (working copy)
> @@ -0,0 +1,16 @@
> +// { dg-do compile { target c++14 } }
> +// { dg-options "-O2 -fdump-tree-optimized" }
> +
> +#include <algorithm>
> +
> +int g()
> +{
> + return 1234;
> +}
> +
> +int f2()
> +{
> + return std::min({1, g(), 4});
> +}
> +
> +// { dg-final { scan-tree-dump "return 1;" "optimized" } }
The testcase fails with -fpic, e.g.:
https://gcc.gnu.org/ml/gcc-regression/2017-04/msg00002.html
So perhaps:
diff --git a/gcc/testsuite/g++.dg/opt/pr80275.C b/gcc/testsuite/g++.dg/opt/pr80275.C
index 7296a07fb2dd..7d625f2c7757 100644
--- a/gcc/testsuite/g++.dg/opt/pr80275.C
+++ b/gcc/testsuite/g++.dg/opt/pr80275.C
@@ -1,4 +1,4 @@
-// { dg-do compile { target c++14 } }
+// { dg-do compile { target c++14 && nonpic } }
// { dg-options "-O2 -fdump-tree-optimized" }
#include <algorithm>
--
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR80275
2017-04-04 5:34 ` Markus Trippelsdorf
@ 2017-04-04 6:22 ` Marc Glisse
2017-04-04 6:59 ` Richard Biener
0 siblings, 1 reply; 4+ messages in thread
From: Marc Glisse @ 2017-04-04 6:22 UTC (permalink / raw)
To: Markus Trippelsdorf; +Cc: Richard Biener, gcc-patches
On Tue, 4 Apr 2017, Markus Trippelsdorf wrote:
> On 2017.04.03 at 11:16 +0200, Richard Biener wrote:
>>
>> The following extends split_address_to_core_and_offset to handle
>> POINTER_PLUS_EXPR to be able to simplify
>> (unsigned long) &MEM[(void *)&D.15512 + 12B] - (unsigned long) ((const int
>> *) &D.15512 + 4) which appears during niter analysis.
>>
>> We seem to have various copies of similar code but refactoring didn't
>> seem appropriate at this stage so I went for the minimal fix.
>>
>> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
>>
>> Richard.
>>
>> 2017-04-03 Richard Biener <rguenther@suse.de>
>>
>> PR tree-optimization/80275
>> * fold-const.c (split_address_to_core_and_offset): Handle
>> POINTER_PLUS_EXPR.
>>
>> * g++.dg/opt/pr80275.C: New testcase.
>>
>> Index: gcc/fold-const.c
>> ===================================================================
>> --- gcc/fold-const.c (revision 246642)
>> +++ gcc/fold-const.c (working copy)
>> @@ -14341,6 +14341,24 @@ split_address_to_core_and_offset (tree e
>> &volatilep);
>> core = build_fold_addr_expr_loc (loc, core);
>> }
>> + else if (TREE_CODE (exp) == POINTER_PLUS_EXPR)
>> + {
>> + core = TREE_OPERAND (exp, 0);
>> + STRIP_NOPS (core);
>> + *pbitpos = 0;
>> + *poffset = TREE_OPERAND (exp, 1);
>> + if (TREE_CODE (*poffset) == INTEGER_CST)
>> + {
>> + offset_int tem = wi::sext (wi::to_offset (*poffset),
>> + TYPE_PRECISION (TREE_TYPE (*poffset)));
>> + tem <<= LOG2_BITS_PER_UNIT;
>> + if (wi::fits_shwi_p (tem))
>> + {
>> + *pbitpos = tem.to_shwi ();
>> + *poffset = NULL_TREE;
>> + }
>> + }
>> + }
>> else
>> {
>> core = exp;
>> Index: gcc/testsuite/g++.dg/opt/pr80275.C
>> ===================================================================
>> --- gcc/testsuite/g++.dg/opt/pr80275.C (nonexistent)
>> +++ gcc/testsuite/g++.dg/opt/pr80275.C (working copy)
>> @@ -0,0 +1,16 @@
>> +// { dg-do compile { target c++14 } }
>> +// { dg-options "-O2 -fdump-tree-optimized" }
>> +
>> +#include <algorithm>
>> +
>> +int g()
>> +{
>> + return 1234;
>> +}
>> +
>> +int f2()
>> +{
>> + return std::min({1, g(), 4});
>> +}
>> +
>> +// { dg-final { scan-tree-dump "return 1;" "optimized" } }
>
> The testcase fails with -fpic, e.g.:
> https://gcc.gnu.org/ml/gcc-regression/2017-04/msg00002.html
>
> So perhaps:
>
> diff --git a/gcc/testsuite/g++.dg/opt/pr80275.C b/gcc/testsuite/g++.dg/opt/pr80275.C
> index 7296a07fb2dd..7d625f2c7757 100644
> --- a/gcc/testsuite/g++.dg/opt/pr80275.C
> +++ b/gcc/testsuite/g++.dg/opt/pr80275.C
> @@ -1,4 +1,4 @@
> -// { dg-do compile { target c++14 } }
> +// { dg-do compile { target c++14 && nonpic } }
> // { dg-options "-O2 -fdump-tree-optimized" }
>
> #include <algorithm>
Making g static should work even with PIC.
--
Marc Glisse
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR80275
2017-04-04 6:22 ` Marc Glisse
@ 2017-04-04 6:59 ` Richard Biener
0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2017-04-04 6:59 UTC (permalink / raw)
To: gcc-patches; +Cc: Markus Trippelsdorf
On Tue, 4 Apr 2017, Marc Glisse wrote:
> On Tue, 4 Apr 2017, Markus Trippelsdorf wrote:
>
> > On 2017.04.03 at 11:16 +0200, Richard Biener wrote:
> > >
> > > The following extends split_address_to_core_and_offset to handle
> > > POINTER_PLUS_EXPR to be able to simplify
> > > (unsigned long) &MEM[(void *)&D.15512 + 12B] - (unsigned long) ((const int
> > > *) &D.15512 + 4) which appears during niter analysis.
> > >
> > > We seem to have various copies of similar code but refactoring didn't
> > > seem appropriate at this stage so I went for the minimal fix.
> > >
> > > Bootstrap and regtest running on x86_64-unknown-linux-gnu.
> > >
> > > Richard.
> > >
> > > 2017-04-03 Richard Biener <rguenther@suse.de>
> > >
> > > PR tree-optimization/80275
> > > * fold-const.c (split_address_to_core_and_offset): Handle
> > > POINTER_PLUS_EXPR.
> > >
> > > * g++.dg/opt/pr80275.C: New testcase.
> > >
> > > Index: gcc/fold-const.c
> > > ===================================================================
> > > --- gcc/fold-const.c (revision 246642)
> > > +++ gcc/fold-const.c (working copy)
> > > @@ -14341,6 +14341,24 @@ split_address_to_core_and_offset (tree e
> > > &volatilep);
> > > core = build_fold_addr_expr_loc (loc, core);
> > > }
> > > + else if (TREE_CODE (exp) == POINTER_PLUS_EXPR)
> > > + {
> > > + core = TREE_OPERAND (exp, 0);
> > > + STRIP_NOPS (core);
> > > + *pbitpos = 0;
> > > + *poffset = TREE_OPERAND (exp, 1);
> > > + if (TREE_CODE (*poffset) == INTEGER_CST)
> > > + {
> > > + offset_int tem = wi::sext (wi::to_offset (*poffset),
> > > + TYPE_PRECISION (TREE_TYPE (*poffset)));
> > > + tem <<= LOG2_BITS_PER_UNIT;
> > > + if (wi::fits_shwi_p (tem))
> > > + {
> > > + *pbitpos = tem.to_shwi ();
> > > + *poffset = NULL_TREE;
> > > + }
> > > + }
> > > + }
> > > else
> > > {
> > > core = exp;
> > > Index: gcc/testsuite/g++.dg/opt/pr80275.C
> > > ===================================================================
> > > --- gcc/testsuite/g++.dg/opt/pr80275.C (nonexistent)
> > > +++ gcc/testsuite/g++.dg/opt/pr80275.C (working copy)
> > > @@ -0,0 +1,16 @@
> > > +// { dg-do compile { target c++14 } }
> > > +// { dg-options "-O2 -fdump-tree-optimized" }
> > > +
> > > +#include <algorithm>
> > > +
> > > +int g()
> > > +{
> > > + return 1234;
> > > +}
> > > +
> > > +int f2()
> > > +{
> > > + return std::min({1, g(), 4});
> > > +}
> > > +
> > > +// { dg-final { scan-tree-dump "return 1;" "optimized" } }
> >
> > The testcase fails with -fpic, e.g.:
> > https://gcc.gnu.org/ml/gcc-regression/2017-04/msg00002.html
> >
> > So perhaps:
> >
> > diff --git a/gcc/testsuite/g++.dg/opt/pr80275.C
> > b/gcc/testsuite/g++.dg/opt/pr80275.C
> > index 7296a07fb2dd..7d625f2c7757 100644
> > --- a/gcc/testsuite/g++.dg/opt/pr80275.C
> > +++ b/gcc/testsuite/g++.dg/opt/pr80275.C
> > @@ -1,4 +1,4 @@
> > -// { dg-do compile { target c++14 } }
> > +// { dg-do compile { target c++14 && nonpic } }
> > // { dg-options "-O2 -fdump-tree-optimized" }
> >
> > #include <algorithm>
>
> Making g static should work even with PIC.
Tested on x86_64-unknown-linux-gnu, applied.
Richard.
2017-04-04 Richard Biener <rguenther@suse.de>
PR tree-optimization/80275
* g++.dg/opt/pr80275.C: Make g static.
Index: gcc/testsuite/g++.dg/opt/pr80275.C
===================================================================
--- gcc/testsuite/g++.dg/opt/pr80275.C (revision 246670)
+++ gcc/testsuite/g++.dg/opt/pr80275.C (working copy)
@@ -3,7 +3,7 @@
#include <algorithm>
-int g()
+static int g()
{
return 1234;
}
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-04-04 6:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-03 9:16 [PATCH] Fix PR80275 Richard Biener
2017-04-04 5:34 ` Markus Trippelsdorf
2017-04-04 6:22 ` Marc Glisse
2017-04-04 6:59 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).