public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/109791 - expand &x + off for niter compute
@ 2023-05-25  8:59 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-05-25  8:59 UTC (permalink / raw)
  To: gcc-patches

The following makes expand_simple_operations expand POINTER_PLUS_EXPRs
with variable offset when the base is invariant.  That will allow
to simplify address differences to offset differences in some cases.
Note the patch doesn't follow the variable off chain as I don't have
a testcase showing that's beneficial.

Bootstrapped and tested on x86_64-unknown-linux-gnu.

I'm going to push this when the last patch in the series tests OK
and the testcase from PR109791 then can be added.

	PR tree-optimization/109791
	* tree-ssa-loop-niter.cc (expand_simple_operations): Expand &x + off.
---
 gcc/tree-ssa-loop-niter.cc | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-ssa-loop-niter.cc b/gcc/tree-ssa-loop-niter.cc
index 5d398b67e68..159fdc8fb85 100644
--- a/gcc/tree-ssa-loop-niter.cc
+++ b/gcc/tree-ssa-loop-niter.cc
@@ -2817,12 +2817,17 @@ expand_simple_operations (tree expr, tree stop, hash_map<tree, tree> &cache)
 	return expr;
       /* Fallthru.  */
     case POINTER_PLUS_EXPR:
-      /* And increments and decrements by a constant are simple.  */
+      /* And increments and decrements by a constant are simple.
+	 Also expand increments from an invariant base (but do not follow
+	 a variable offset).  */
       e1 = gimple_assign_rhs2 (stmt);
-      if (!is_gimple_min_invariant (e1))
+      if (is_gimple_min_invariant (e1))
+	ee = expand_simple_operations (e, stop, cache);
+      else if (is_gimple_min_invariant (e))
+	ee = e;
+      else
 	return expr;
 
-      ee = expand_simple_operations (e, stop, cache);
       return fold_build2 (code, TREE_TYPE (expr), ee, e1);
 
     default:
-- 
2.35.3

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-05-25  8:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-25  8:59 [PATCH] tree-optimization/109791 - expand &x + off for niter compute 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).