diff mbox

[RFC,PR69708] IPA inline not working for function reference in static const struc

Message ID 56D4C069.8060200@linaro.org
State New
Headers show

Commit Message

Kugan Vivekanandarajah Feb. 29, 2016, 10:04 p.m. UTC
Hi,

As discussed in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69708 and 
corresponding mailing list discussion, IPA CP is not detecting  a 
jump-function with the sq function as value.


static int sq(int x) {
   return x * x;
}

static const F f = {sq};
...
dosomething (g(f, x));
...

I added a check at  determine_locally_known_aggregate_parts to detect 
this. This fixes the testcase and passes x86-64-linux-gnu lto bootstrap 
and regression testing with no new regression. Does this look sensible 
place to fix this?

Thanks,
Kugan

gcc/ChangeLog:



2016-03-01  Kugan Vivekanandarajah  <kuganv@linaro.org>



	* ipa-prop.c (determine_locally_known_aggregate_parts): Determine jump

	 function for static constant initialization.

Comments

Kugan Vivekanandarajah March 10, 2016, 10:18 p.m. UTC | #1
On 11/03/16 03:39, Martin Jambor wrote:
> Hi,

>

> On Tue, Mar 01, 2016 at 09:04:25AM +1100, kugan wrote:

>> Hi,

>>

>> As discussed in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69708 and

>> corresponding mailing list discussion, IPA CP is not detecting  a

>> jump-function with the sq function as value.

>>

>>

>

> sorry it took so long for me to look at this.  First, I have looked at

> your patch and found a number of issues (see comments below), but when

> I tried to fix them (see my patch below), I found out that using the

> aggregate jump functions is not the the best approach.  But let me

> start with the comments first:


Hi Martin,

Thanks for the explanation.

Kugan
diff mbox

Patch

diff --git a/gcc/ipa-prop.c b/gcc/ipa-prop.c
index 72c2fed..22da097 100644
--- a/gcc/ipa-prop.c
+++ b/gcc/ipa-prop.c
@@ -1562,6 +1562,57 @@  determine_locally_known_aggregate_parts (gcall *call, tree arg,
       jfunc->agg.by_ref = by_ref;
       build_agg_jump_func_from_list (list, const_count, arg_offset, jfunc);
     }
+  else if ((TREE_CODE (arg) == VAR_DECL)
+	   && is_global_var (arg))
+    {
+      /* PR69708:  Figure out aggregate jump-function with constant init
+	 value.  */
+      struct ipa_known_agg_contents_list *n, **p;
+      HOST_WIDE_INT offset = 0, size, max_size;
+      varpool_node *node = varpool_node::get (arg);
+      if (node
+	  && DECL_INITIAL (node->decl)
+	  && TREE_READONLY (node->decl)
+	  && TREE_CODE (DECL_INITIAL (node->decl)) == CONSTRUCTOR)
+	{
+	  tree exp = DECL_INITIAL (node->decl);
+	  unsigned HOST_WIDE_INT ix;
+	  tree field, val;
+	  bool reverse;
+	  FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (exp), ix, field, val)
+	    {
+	      bool already_there = false;
+	      if (!field)
+		break;
+	      get_ref_base_and_extent (field, &offset, &size,
+				       &max_size, &reverse);
+	      if (max_size == -1
+		  || max_size != size)
+		break;
+	      p = get_place_in_agg_contents_list (&list, offset, size,
+						  &already_there);
+	      if (!p)
+		break;
+	      n = XALLOCA (struct ipa_known_agg_contents_list);
+	      n->size = size;
+	      n->offset = offset;
+	      if (is_gimple_ip_invariant (val))
+		{
+		  n->constant = val;
+		  const_count++;
+		}
+	      else
+		n->constant = NULL_TREE;
+	      n->next = *p;
+	      *p = n;
+	    }
+	}
+      if (const_count)
+	{
+	  jfunc->agg.by_ref = by_ref;
+	  build_agg_jump_func_from_list (list, const_count, arg_offset, jfunc);
+	}
+    }
 }
 
 static tree