User account creation filtered due to spam.

Bug 46639 - [5/6 Regression] Missing optimization due to function splitting and redundant conditionals
Summary: [5/6 Regression] Missing optimization due to function splitting and redundant...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.6.0
: P2 normal
Target Milestone: 5.5
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
: 48880 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-11-24 09:06 UTC by Dmitry Gorbachev
Modified: 2017-02-08 19:56 UTC (History)
8 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2010-11-24 12:18:23


Attachments
testcase (203 bytes, text/plain)
2010-11-24 09:06 UTC, Dmitry Gorbachev
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Gorbachev 2010-11-24 09:06:01 UTC
Created attachment 22507 [details]
testcase

gcc -O2 pr46639.c

/tmp/ccJzJXqb.o: In function `bar.part.0':
pr46639.c:(.text+0x30): undefined reference to `link_error'
Comment 1 Richard Biener 2010-11-24 12:18:23 UTC
Hm, confirmed.  We don't clean up redundant conditionals before function
splitting:

  if (n_3(D) > 1023)
    goto <bb 9>;
  else
    goto <bb 3>;

  if (n_3(D) > 1023)
    goto <bb 4>;
  else
    goto <bb 7>;

and fnsplit considers splitting after the first one to be most beneficial.
And we don't inline it back together because
 Not inlining into bar:--param large-stack-frame-growth limit reached.
even though the original stack frame size is zero.

We didn't make the call in main direct either (ipa-reference runs too late
for that).

In the end this of course asks for more early optimizations.
Comment 2 Jakub Jelinek 2010-11-24 16:17:02 UTC
Well, scheduling one VRP pass could be expensive though and only VRP and DOM are currently able to optimize these redundant tests away.

Perhaps if for the body of partially inlined functions we kept somewhere the inlined test or at least its VRP properties, so that VRP pass could use them...

I wonder why in this case partial inlining does something, shouldn't
x > 1023 be predicted with the default predictors unlikely (thus the body be likely)?
Comment 3 Dmitry Gorbachev 2011-02-17 17:02:20 UTC
I can't reproduce this bug now.
Comment 4 Dmitry Gorbachev 2011-02-27 19:56:55 UTC
Still fails with GCC version 4.6.0 20110226.
Comment 5 Jan Hubicka 2011-02-28 09:25:28 UTC
There is no predictor predicting x > 1023 as unlikely, there is not much you can easilly guess here ;(
Comment 6 Jakub Jelinek 2011-03-25 19:52:52 UTC
GCC 4.6.0 is being released, adjusting target milestone.
Comment 7 Jakub Jelinek 2011-05-05 10:56:28 UTC
*** Bug 48880 has been marked as a duplicate of this bug. ***
Comment 8 Jakub Jelinek 2011-05-05 11:03:23 UTC
Another testcase:
http://gcc.gnu.org/bugzilla/attachment.cgi?id=24188
Richard suggests running pass_vrp_early instead of (or in addition to) pass_ccp with some more expensive parts of VRP disabled.
Comment 9 Jakub Jelinek 2011-06-27 12:33:04 UTC
GCC 4.6.1 is being released.
Comment 10 Jakub Jelinek 2011-10-26 17:13:49 UTC
GCC 4.6.2 is being released.
Comment 11 Jakub Jelinek 2012-03-01 14:38:59 UTC
GCC 4.6.3 is being released.
Comment 12 Jakub Jelinek 2013-04-12 15:16:14 UTC
GCC 4.6.4 has been released and the branch has been closed.
Comment 13 Jeffrey A. Law 2014-01-23 07:08:31 UTC
Another approach would be to do some minimal redundancy elimination as part of the into-ssa pass.  Having done it before, I know it's pretty easy.
Comment 14 Richard Biener 2014-06-12 13:43:07 UTC
The 4.7 branch is being closed, moving target milestone to 4.8.4.
Comment 15 Jakub Jelinek 2014-12-19 13:26:25 UTC
GCC 4.8.4 has been released.
Comment 16 Richard Biener 2015-06-23 08:15:45 UTC
The gcc-4_8-branch is being closed, re-targeting regressions to 4.9.3.
Comment 17 Jakub Jelinek 2015-06-26 19:53:03 UTC
GCC 4.9.3 has been released.
Comment 18 Richard Biener 2016-08-03 10:49:01 UTC
GCC 4.9 branch is being closed
Comment 19 Jeffrey A. Law 2016-11-17 16:09:46 UTC
Early FRE picks this up in gcc-7.
Comment 20 ctice 2017-02-08 19:56:00 UTC
Author: ctice
Date: Wed Feb  8 19:55:28 2017
New Revision: 245284

URL: https://gcc.gnu.org/viewcvs?rev=245284&root=gcc&view=rev
Log:
2017-02-08  Caroline Tice <cmtice@google.com>

        Fix PR 46639
	in gcc:
	* passes.def: Add pass_early_vrp; move pass_profile to before new pass.
	* tree-pass.h: Add extern decl for make_pass_early_vrp.
	* tree-vrp.c: New file global variable, is_early_vrp (boolean).
	(extract_range_basic):  Add test for is_early_vrp before updating
	built-in constants -- don't update during early_vrp pass.
	(check_array_ref): Retrn immediately if is_early_vrp is true.
	(execute_vrp): Add boolean parameter to indicate early pass or not;
	set is_early_pass to value of parameter.
	(pass_data_early_vrp): New pass_data struct.
	(pass_vrp::execute): Call execute_vrp with false -- not early pass.
	(class pass_early_vrp): New gimple_opt_pass class.
	(make_pass_early_vrp): New function.

	in testsuite:
	
	* testsuite/gcc.dg/tree-prof/lipo/val-prof-5_0.c: xfail test.  It is
	no longer a correct test with the new pass.
	* testsuite/gcc.dg/tree-prof/val-prof-5.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/20030709-2.c: Change test to reflect new
	(correct) code due to patch changes.
	* testsuite/gcc.dg/tree-ssa/20040305-1.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr20702.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr21086.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp02.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp07.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp08.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp55.c: Ditto.
	* testsuite/gcc.dg/vect/slp-perm-7.c: Ditto.
	* testsuite/gcc.dg/fold-compare-2.c: Update to scan correct pass.
	* testsuite/gcc.dg/tree-ssa/pr20318.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr20657.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr21001.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr21090.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr21294.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr21458.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr21559.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr21563.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr22117.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr23744.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr25382.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr37508.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr49039.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr58480.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/pr59597.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/ssa-dom-thread-2.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/ssa-vrp-thread-1.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp01.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp03.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp04.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp06.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp09.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp16.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp17.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp18.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp19.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp20.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp23.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp24.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp25.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp33.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp34.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp46.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp56.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp58.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp67.c: Ditto.
	* testsuite/gcc.dg/tree-ssa/vrp87.c: Ditto.


Modified:
    branches/google/gcc-4_9-mobile/gcc/passes.def
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/fold-compare-2.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-prof/lipo/val-prof-5_0.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-prof/val-prof-5.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/20030709-2.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/20040305-1.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr20318.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr20657.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr20702.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr21001.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr21086.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr21090.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr21294.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr21458.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr21559.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr21563.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr22117.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr23744.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr25382.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr37508.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr49039.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr58480.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/pr59597.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/ssa-dom-thread-2.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/ssa-vrp-thread-1.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp01.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp02.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp03.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp04.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp06.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp07.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp08.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp09.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp16.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp17.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp18.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp19.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp20.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp23.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp24.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp25.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp33.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp34.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp46.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp55.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp56.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp58.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp67.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/tree-ssa/vrp87.c
    branches/google/gcc-4_9-mobile/gcc/testsuite/gcc.dg/vect/slp-perm-7.c
    branches/google/gcc-4_9-mobile/gcc/tree-pass.h
    branches/google/gcc-4_9-mobile/gcc/tree-vrp.c