Bug 49642 - constant part of a macro not optimized away as expected due to splitter
Summary: constant part of a macro not optimized away as expected due to splitter
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.6.1
: P3 normal
Target Milestone: 4.7.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-05 12:40 UTC by marcus
Modified: 2012-01-18 21:13 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-07-05 12:59:02


Attachments
ehca_mrmw.i (683 bytes, text/plain)
2011-07-05 12:41 UTC, marcus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description marcus 2011-07-05 12:40:21 UTC
my Linux kernel builds on gcc 4.6 pcc64 fail with:

ERROR: ".____ilog2_NaN" [drivers/infiniband/hw/ehca/ib_ehca.ko] undefined!

This comes from include/linux/log2.h which uses a large macro with builtin_constant_p() to optimize constant ilog2 calls.

I have reduced it to the attached testcase.

$ gcc -m64 -O2 -fno-inline-functions-called-once -c ehca_mrmw.i ; objdump -dr ehca_mrmw.o |grep NaN
                        1a8: R_PPC64_REL24      ____ilog2_NaN
                        1cc: R_PPC64_REL24      ____ilog2_NaN
$ 

It should not report NaN as that is in a if (__builtin_constant_p(shca->hca_cap_mr_pgsize)) expression.
Comment 1 marcus 2011-07-05 12:41:05 UTC
Created attachment 24690 [details]
ehca_mrmw.i

gcc -m64 -O2 -fno-inline-functions-called-once -c ehca_mrmw.i ; objdump -dr ehca_mrmw.o |grep NaN

should not report:
                        1a8: R_PPC64_REL24      ____ilog2_NaN
Comment 2 marcus 2011-07-05 12:42:28 UTC
looking at the assembly, both x() and y() call the assembler functions,
just the static function is still emitted with
0000000000000000 <.ehca_get_max_hwpage_size.part.0>:

name. This instance could probably be safely deleted.
Comment 3 Richard Biener 2011-07-05 12:59:02 UTC
Confirmed.

Honza - we split a __builtin_constant_p guarded section away, not killing off
the not needed constant case as we process final optimizations in the wrong
order (thus we don't see the function is unused soon enough).

I think it isn't a good idea to split away any code dominated by such
call.  The testcase is basically

int foo(int arg)
{
 if (__builtin_constant_p (arg))
   {
     if (arg == 10)
       return 1;
     return unreachable ();
   }
 return arg;
}

and we split it as

int foo (int arg)
{
  if (__builtin_constant_p (arg))
    return foo.part (arg);
  return arg;
}
Comment 4 Bill Schmidt 2012-01-06 17:09:01 UTC
I noticed today that this bug does not reproduce on trunk, though it still does on the 4_6 branch.  Does anyone know if this was intentionally fixed but perhaps not backported into 4.6?
Comment 5 Bill Schmidt 2012-01-07 00:13:10 UTC
This was "solved" (or became dormant) with revision 171450 on trunk:

2011-03-25  Richard Guenther  <rguenther@suse.de>

	* passes.c (init_optimization_passes): Add FRE pass after
	early SRA.
Comment 6 Richard Biener 2012-01-09 12:10:50 UTC
Fixed for 4.7.
Comment 7 Bill Schmidt 2012-01-09 21:57:57 UTC
I should note that the problem still persists in 4.7 when -fno-tree-fre is specified.

For 4.6, I am working on a solution along the lines Richi outlined above.  We may want to consider putting that in 4.7 as well for the -fno-tree-fre case.
Comment 8 Bill Schmidt 2012-01-11 16:52:13 UTC
Author: wschmidt
Date: Wed Jan 11 16:52:03 2012
New Revision: 183101

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183101
Log:
gcc:

2012-01-11  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	PR tree-optimization/49642
	* ipa-split.c (forbidden_dominators): New variable.
	(check_forbidden_calls): New function.
	(dominated_by_forbidden): Likewise.
	(consider_split): Check for forbidden dominators.
	(execute_split_functions): Initialize and free forbidden
	dominators info; call check_forbidden_calls.

gcc/testsuite:

2012-01-11  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	PR tree-optimization/49642
	* gcc.dg/tree-ssa/pr49642-1.c: New test.
	* gcc.dg/tree-ssa/pr49642-2.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr49642-1.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr49642-2.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/ipa-split.c
    trunk/gcc/testsuite/ChangeLog
Comment 9 Bill Schmidt 2012-01-11 22:37:33 UTC
Author: wschmidt
Date: Wed Jan 11 22:37:26 2012
New Revision: 183110

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183110
Log:
gcc:

2012-01-11  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	PR tree-optimization/49642
	* ipa-split.c (forbidden_dominators): New variable.
	(check_forbidden_calls): New function.
	(dominated_by_forbidden): Likewise.
	(consider_split): Check for forbidden dominators.
	(execute_split_functions): Initialize and free forbidden
	dominators info; call check_forbidden_calls.

gcc/testsuite:

2012-01-11  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	PR tree-optimization/49642
	* gcc.dg/tree-ssa/pr49642.c: New test.


Added:
    branches/ibm/gcc-4_6-branch/gcc/testsuite/gcc.dg/tree-ssa/pr49642.c
Modified:
    branches/ibm/gcc-4_6-branch/gcc/ChangeLog.ibm
    branches/ibm/gcc-4_6-branch/gcc/ipa-split.c
    branches/ibm/gcc-4_6-branch/gcc/testsuite/ChangeLog.ibm
Comment 10 Bill Schmidt 2012-01-18 19:28:23 UTC
Author: wschmidt
Date: Wed Jan 18 19:28:19 2012
New Revision: 183284

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183284
Log:
gcc:

2012-01-11  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	PR tree-optimization/49642
	* ipa-split.c (forbidden_dominators): New variable.
	(check_forbidden_calls): New function.
	(dominated_by_forbidden): Likewise.
	(consider_split): Check for forbidden dominators.
	(execute_split_functions): Initialize and free forbidden
	dominators info; call check_forbidden_calls.

gcc/testsuite:

2012-01-11  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>

	PR tree-optimization/49642
	* gcc.dg/tree-ssa/pr49642.c: New test.


Added:
    branches/gcc-4_6-branch/gcc/testsuite/gcc.dg/tree-ssa/pr49642.c
Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/ipa-split.c
    branches/gcc-4_6-branch/gcc/testsuite/ChangeLog
Comment 11 Bill Schmidt 2012-01-18 20:21:04 UTC
Fixed in 4.7, 4.6, ibm/4.6 = AT5.0.