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; }
Confirmed, the problem is that VRP folds a > 63 and then props that into temp && temp1 but does not prop after that.
I should note that this only happens for targets whos BRANCH_COST is semi high.
I've got a preliminary patch.
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
Just checked in a patch.