This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR79201 (half-way)
- From: Richard Biener <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 24 Apr 2017 10:54:22 +0200 (CEST)
- Subject: [PATCH] Fix PR79201 (half-way)
- Authentication-results: sourceware.org; auth=none
One issue in PR79201 is that we don't sink pure/const calls which is
what the following simple patch fixes.
Bootstrap and regtest running on x86_64-unknown-linux-gnu.
Richard.
2017-04-24 Richard Biener <rguenther@suse.de>
PR tree-optimization/79201
* tree-ssa-sink.c (statement_sink_location): Handle calls.
* gcc.dg/tree-ssa/ssa-sink-16.c: New testcase.
Index: gcc/tree-ssa-sink.c
===================================================================
*** gcc/tree-ssa-sink.c (revision 247091)
--- gcc/tree-ssa-sink.c (working copy)
*************** statement_sink_location (gimple *stmt, b
*** 256,263 ****
*zero_uses_p = false;
! /* We only can sink assignments. */
! if (!is_gimple_assign (stmt))
return false;
/* We only can sink stmts with a single definition. */
--- 257,268 ----
*zero_uses_p = false;
! /* We only can sink assignments and non-looping const/pure calls. */
! int cf;
! if (!is_gimple_assign (stmt)
! && (!is_gimple_call (stmt)
! || !((cf = gimple_call_flags (stmt)) & (ECF_CONST|ECF_PURE))
! || (cf & ECF_LOOPING_CONST_OR_PURE)))
return false;
/* We only can sink stmts with a single definition. */
Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-16.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-16.c (nonexistent)
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-16.c (working copy)
***************
*** 0 ****
--- 1,14 ----
+ /* { dg-do compile } */
+ /* Note PRE rotates the loop and blocks the sinking opportunity. */
+ /* { dg-options "-O2 -fno-tree-pre -fdump-tree-sink -fdump-tree-optimized" } */
+
+ int f(int n)
+ {
+ int i,j=0;
+ for (i = 0; i < 31; i++)
+ j = __builtin_ffs(i);
+ return j;
+ }
+
+ /* { dg-final { scan-tree-dump "Sinking j_. = __builtin_ffs" "sink" } } */
+ /* { dg-final { scan-tree-dump "return 2;" "optimized" } } */