diff mbox

[PR,54409] Remapping inlining predicates fix

Message ID 20120830221857.GE3395@virgil.arch.suse.de
State New
Headers show

Commit Message

Martin Jambor Aug. 30, 2012, 10:18 p.m. UTC
Hi,

this patch fixes PR 54409.  The condition for dealing with offset maps
when remapping predicates which I have added recently was wrong,
fortunately a subsequent assert caught this.  We cannot shift stuff by
an offset when it is passed by value.

Conversely, the condition was unnecessarily restrictive, we can still
happily use non-aggregate and by-value conditions when offset map is
negative, that only means that by-ref stuff is not guaranteed to
survive.

Bootstrapped and tested on x86_64-linux.  OK for trunk?

Thanks,

Martin



2012-08-30  Martin Jambor  <mjambor@suse.cz>

	PR middle-end/54409
	* ipa-inline-analysis.c (remap_predicate): Fix the offset_map
	checking condition.

	* gcc/testsuite/gcc.dg/torture/pr54409.c: New test.

Comments

Jan Hubicka Aug. 31, 2012, 8:49 a.m. UTC | #1
> Hi,
> 
> this patch fixes PR 54409.  The condition for dealing with offset maps
> when remapping predicates which I have added recently was wrong,
> fortunately a subsequent assert caught this.  We cannot shift stuff by
> an offset when it is passed by value.
> 
> Conversely, the condition was unnecessarily restrictive, we can still
> happily use non-aggregate and by-value conditions when offset map is
> negative, that only means that by-ref stuff is not guaranteed to
> survive.

Yeah, I wondered about this ;)
> 
> Bootstrapped and tested on x86_64-linux.  OK for trunk?
> 
> Thanks,
> 
> Martin
> 
> 
> 
> 2012-08-30  Martin Jambor  <mjambor@suse.cz>
> 
> 	PR middle-end/54409
> 	* ipa-inline-analysis.c (remap_predicate): Fix the offset_map
> 	checking condition.
> 
> 	* gcc/testsuite/gcc.dg/torture/pr54409.c: New test.

OK,
thanks
Honza
diff mbox

Patch

Index: src/gcc/ipa-inline-analysis.c
===================================================================
--- src.orig/gcc/ipa-inline-analysis.c
+++ src/gcc/ipa-inline-analysis.c
@@ -2811,8 +2811,11 @@  remap_predicate (struct inline_summary *
 		 if (!operand_map
 		     || (int)VEC_length (int, operand_map) <= c->operand_num
 		     || VEC_index (int, operand_map, c->operand_num) == -1
-		     || (!c->agg_contents
-			 && VEC_index (int, offset_map, c->operand_num) != 0)
+		     /* TODO: For non-aggregate conditions, adding an offset is
+			basically an arithmetic jump function processing which
+			we should support in future.  */
+		     || ((!c->agg_contents || !c->by_ref)
+			 && VEC_index (int, offset_map, c->operand_num) > 0)
 		     || (c->agg_contents && c->by_ref
 			 && VEC_index (int, offset_map, c->operand_num) < 0))
 		   cond_predicate = true_predicate ();
Index: src/gcc/testsuite/gcc.dg/torture/pr54409.c
===================================================================
--- /dev/null
+++ src/gcc/testsuite/gcc.dg/torture/pr54409.c
@@ -0,0 +1,28 @@ 
+/* { dg-do compile } */
+
+int b;
+
+struct S
+{
+  char *p;
+  struct {
+  } s;
+  int a;
+};
+
+static _Bool
+fn2 (int *p1)
+{
+  if (b)
+    {
+      struct S *c = (struct S *) &p1;
+      return c->a;
+    }
+}
+
+_Bool
+fn3 (struct S *p1)
+{
+  if (fn2 ((int *) &p1->s))
+    return 0;
+}