Bug 25485 - VRP misses an "if" with TRUTH_AND_EXPR statement that could be optimized away
Summary: VRP misses an "if" with TRUTH_AND_EXPR statement that could be optimized away
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.2.0
: P3 enhancement
Target Milestone: 4.2.0
Assignee: Kazu Hirata
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2005-12-18 19:06 UTC by Kazu Hirata
Modified: 2006-01-23 16:32 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-pc-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-12-18 19:18:37


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kazu Hirata 2005-12-18 19:06:24 UTC
Consider:

int
foo (int a, int b)
{
  if (a > 50)
    return 19;
  if (a > 63 && b < 50)
    return 17;
  return 31;
}

VRP does not optimize away the second "if" statement.

Here is the output from VRP.

foo (a, b)
{
  _Bool D.1662;
  _Bool D.1661;
  _Bool D.1660;
  int D.1659;

<bb 2>:
  if (a_2 > 50) goto <L4>; else goto <L1>;

<L1>:;
  D.1660_4 = 0;
  D.1661_6 = b_5 <= 49;
  D.1662_7 = 0;
  if (D.1662_7) goto <L2>; else goto <L4>;

<L2>:;

  # D.1659_1 = PHI <19(2), 17(4), 31(3)>;
<L4>:;
  return D.1659_1;

}
Comment 1 Andrew Pinski 2005-12-18 19:18:37 UTC
Confirmed, the problem is that VRP folds a > 63 and then props that into temp && temp1 but does not prop after that.
Comment 2 Andrew Pinski 2005-12-18 19:19:16 UTC
I should note that this only happens for targets whos BRANCH_COST is semi high.
Comment 3 Kazu Hirata 2005-12-19 00:01:37 UTC
I've got a preliminary patch.
Comment 4 Kazu Hirata 2006-01-14 15:42:17 UTC
Subject: Bug 25485

Author: kazu
Date: Sat Jan 14 15:42:11 2006
New Revision: 109704

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=109704
Log:
gcc/
	PR tree-optimization/25485
	* tree-vrp.c (extract_range_from_binary_expr): Handle cases
	where one of the operands of TRUTH_AND_EXPR and TRUTH_OR_EXPR
	is known to be false and true, respectively.

gcc/testsuite/
	PR tree-optimization/25485
	* gcc.dg/tree-ssa/pr25485.c: New.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr25485.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vrp.c

Comment 5 Kazu Hirata 2006-01-14 15:48:07 UTC
Just checked in a patch.