This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Question about inlining and strict_aliasing


Hello.

I've been working on a patch that would cope with target and optimization (read PerFunction)
in a proper way. I came to following test-case (slightly modified ./gcc/testsuite/gcc.c-torture/execute/alias-1.c):

int val;

int *ptr = &val;
float *ptr2 = &val;

static
__attribute__((always_inline, optimize ("-fno-strict-aliasing")))
typepun ()
{
  *ptr2=0;
}

main()
{
  *ptr=1;
  typepun ();
  if (*ptr)
    __builtin_abort ();
}

$ gcc -O2 /tmp/always-inline.c -fdump-tree-all-details && ./a.out
Aborted (core dumped)

Problem is that einline does:

  Inlining typepun into main (always_inline).
   Estimating body: typepun/3
   Known to be false: not inlined
   size:2 time:2
Dropping flag_strict_aliasing on main:4 <<---- here is strict_aliasing drop
		Accounting size:2.00, time:2.00 on predicate:(true)

However fre1 does not still check for flag_strict_aliasing. Is it bug or not?
I did an experimental fix, but I guess there will me multiple places where the 
flag is checked.

Second question:
Current ipa-inline.c code contains question sophisticated check_{match,maybe_up,maybe_down} and
it's following by:

      /* When user added an attribute to the callee honor it.  */
      else if (lookup_attribute ("optimize", DECL_ATTRIBUTES (callee->decl))
	       && opts_for_fn (caller->decl) != opts_for_fn (callee->decl))
	{
	  e->inline_failed = CIF_OPTIMIZATION_MISMATCH;
	  inlinable = false;
	}

I think it's very strict, as when one uses __attribute__((optimize)) with a param that matches with
command line arguments, it will return false. What if we remove the hunk?

Thanks,
Martin
diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c
index 871fa121fd0..da38e4fab69 100644
--- a/gcc/tree-ssa-alias.c
+++ b/gcc/tree-ssa-alias.c
@@ -986,7 +986,7 @@ ncr_compar (const void *field1_, const void *field2_)
 static bool
 nonoverlapping_component_refs_p (const_tree x, const_tree y)
 {
-  if (!flag_strict_aliasing
+  if (!opts_for_fn (current_function_decl)->x_flag_strict_aliasing
       || !x || !y
       || TREE_CODE (x) != COMPONENT_REF
       || TREE_CODE (y) != COMPONENT_REF)
@@ -1167,7 +1167,7 @@ indirect_ref_may_alias_decl_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
     return false;
 
   /* Disambiguations that rely on strict aliasing rules follow.  */
-  if (!flag_strict_aliasing || !tbaa_p)
+  if (!opts_for_fn (current_function_decl)->x_flag_strict_aliasing || !tbaa_p)
     return true;
 
   ptrtype1 = TREE_TYPE (TREE_OPERAND (base1, 1));
@@ -1334,7 +1334,7 @@ indirect_refs_may_alias_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
     return false;
 
   /* Disambiguations that rely on strict aliasing rules follow.  */
-  if (!flag_strict_aliasing || !tbaa_p)
+  if (!opts_for_fn (current_function_decl)->x_flag_strict_aliasing || !tbaa_p)
     return true;
 
   ptrtype1 = TREE_TYPE (TREE_OPERAND (base1, 1));
@@ -1508,7 +1508,7 @@ refs_may_alias_p_1 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
 
   /* First defer to TBAA if possible.  */
   if (tbaa_p
-      && flag_strict_aliasing
+      && opts_for_fn (current_function_decl)->x_flag_strict_aliasing
       && !alias_sets_conflict_p (ao_ref_alias_set (ref1),
 				 ao_ref_alias_set (ref2)))
     return false;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]