aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2017-04-03 12:22:22 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2017-04-03 12:22:22 +0000
commitfff80893baad08414ee4332655f4ed5f557ae73a (patch)
treec393e51a8f85766a92462266c85a8b6bbb3e0794 /gcc
parent0be1d23cc32369d48c93a795a07d4fa037f14d5c (diff)
downloadgcc-fff80893baad08414ee4332655f4ed5f557ae73a.zip
gcc-fff80893baad08414ee4332655f4ed5f557ae73a.tar.gz
gcc-fff80893baad08414ee4332655f4ed5f557ae73a.tar.bz2
re PR tree-optimization/80275 (Poor (but valid) code generated by optimizer passing optimizer list to function)
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. From-SVN: r246648
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/fold-const.c18
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/opt/pr80275.C16
4 files changed, 45 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 89b3d0d..30daa0d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+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.
+
2017-04-03 Eric Botcazou <ebotcazou@adacore.com>
* tree-nested.c (get_descriptor_type): Make sure that the alignment of
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index fb54ffa..7c05e0f 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -14341,6 +14341,24 @@ split_address_to_core_and_offset (tree exp,
&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;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c0fc1eb..55d4f44 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-04-03 Richard Biener <rguenther@suse.de>
+
+ PR tree-optimization/80275
+ * g++.dg/opt/pr80275.C: New testcase.
+
2017-04-03 Dominik Vogt <vogt@linux.vnet.ibm.com>
PR testsuite/79356
diff --git a/gcc/testsuite/g++.dg/opt/pr80275.C b/gcc/testsuite/g++.dg/opt/pr80275.C
new file mode 100644
index 0000000..7296a07
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr80275.C
@@ -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" } }