From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15925 invoked by alias); 19 Jul 2011 12:08:53 -0000 Received: (qmail 15769 invoked by uid 22791); 19 Jul 2011 12:08:46 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,TW_TM X-Spam-Check-By: sourceware.org Received: from mail-yi0-f47.google.com (HELO mail-yi0-f47.google.com) (209.85.218.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 19 Jul 2011 12:08:11 +0000 Received: by yib18 with SMTP id 18so1938235yib.20 for ; Tue, 19 Jul 2011 05:08:10 -0700 (PDT) MIME-Version: 1.0 Received: by 10.150.67.21 with SMTP id p21mr2876553yba.273.1311077290737; Tue, 19 Jul 2011 05:08:10 -0700 (PDT) Received: by 10.150.205.2 with HTTP; Tue, 19 Jul 2011 05:08:10 -0700 (PDT) In-Reply-To: References: Date: Tue, 19 Jul 2011 12:24:00 -0000 Message-ID: Subject: Re: [patch tree-optimization]: [3 of 3]: Boolify compares & more From: Richard Guenther To: Kai Tietz Cc: GCC Patches Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-07/txt/msg01502.txt.bz2 On Fri, Jul 15, 2011 at 9:42 AM, Kai Tietz wrote: > Hello, > > This patch removes from tree-vrp the use of TRUTH-bitwise expression code= s. Also > it merges the handling for boolean compatible and non-boolean typed > bitwise-binary > expressions. > Additional it adds primitive checks for bitwise-not expression on > boolean-compatible > types. > In substitute_and_fold the scan-direction of statements within a BB is > controlled now > by its do_dce flag. =A0This provides better results in vrp-pass. > > ChangeLog gcc > > 2011-07-15 =A0Kai Tietz =A0 > > =A0 =A0 =A0 =A0* tree-ssa-propagate.c (substitute_and_fold): Use > =A0 =A0 =A0 =A0do_dce flag to deside, if BB's statements are scanned > =A0 =A0 =A0 =A0in last to first, or first to last order. > =A0 =A0 =A0 =A0* tree-vrp.c (extract_range_from_binary_expr): > =A0 =A0 =A0 =A0Remove TRUTH-binary checks. And unify bitwise-binary > =A0 =A0 =A0 =A0cases. > =A0 =A0 =A0 =A0(register_edge_assert_for_1): Add handling boolean-compati= ble > =A0 =A0 =A0 =A0typed BIT_IOR_EXPR and BIT_NOT_EXPR. > =A0 =A0 =A0 =A0(extract_range_from_unary_expr): Add support for 1-bit > =A0 =A0 =A0 =A0integral typed BIT_NOT_EXPR expression. > =A0 =A0 =A0 =A0(extract_range_from_assignment): Remove TRUTH-binary check= s. > =A0 =A0 =A0 =A0Add handling for 1-bit integral typed BIT_NOT_EXPR express= ion. > =A0 =A0 =A0 =A0(build_assert_expr_for): Likewise. > =A0 =A0 =A0 =A0(register_edge_assert_for_1): Likewise. > =A0 =A0 =A0 =A0(simplify_stmt_using_ranges): Likewise. > =A0 =A0 =A0 =A0(ssa_name_get_inner_ssa_name_p): New helper function. > =A0 =A0 =A0 =A0(ssa_name_get_cast_to_p): New helper function. > =A0 =A0 =A0 =A0(simplify_truth_ops_using_ranges): Handle prefixed > =A0 =A0 =A0 =A0cast instruction for result. =A0Remove TRUTH-binary checks. > =A0 =A0 =A0 =A0Add handling for 1-bit integral typed BIT_NOT_EXPR express= ion. > =A0 =A0 =A0 =A0and BIT_NOT_EXPR. > =A0 =A0 =A0 =A0 Add handling for one bit > > ChangeLog gcc/testsuite > > 2011-07-15 =A0Kai Tietz =A0 > > =A0 =A0 =A0 =A0* gcc.dg/tree-ssa/vrp47.c: Test no longer needs > =A0 =A0 =A0 =A0dom dump. > > Bootstrapped and regression tested for all standard languages (plus > Ada & Obj-C++) on x86_64-pc-linux-gnu. =A0Ok for apply? > > Regards, > Kai > > Index: gcc/gcc/testsuite/gcc.dg/tree-ssa/vrp47.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gcc.orig/gcc/testsuite/gcc.dg/tree-ssa/vrp47.c =A0 =A0 =A02011-07-13 > 12:57:46.869620200 +0200 > +++ gcc/gcc/testsuite/gcc.dg/tree-ssa/vrp47.c =A0 2011-07-13 > 22:29:53.221967000 +0200 > @@ -4,7 +4,7 @@ > =A0 =A0jumps when evaluating an && condition. =A0VRP is not able to optim= ize > =A0 =A0this. =A0*/ > =A0/* { dg-do compile { target { ! "mips*-*-* s390*-*-* =A0avr-*-* > mn10300-*-*" } } } */ > -/* { dg-options "-O2 -fdump-tree-vrp -fdump-tree-dom" } */ > +/* { dg-options "-O2 -fdump-tree-vrp" } */ > =A0/* { dg-options "-O2 -fdump-tree-vrp -fdump-tree-dom -march=3Di586" { > target { i?86-*-* && ilp32 } } } */ > > =A0int h(int x, int y) > @@ -36,13 +36,10 @@ int f(int x) > =A0 =A00 or 1. =A0*/ > =A0/* { dg-final { scan-tree-dump-times "\[xy\]\[^ \]* !=3D" 0 "vrp1" } }= */ > > -/* This one needs more copy propagation that only happens in dom1. =A0*/ > -/* { dg-final { scan-tree-dump-times "x\[^ \]* & y" 1 "dom1" } } */ > -/* { dg-final { scan-tree-dump-times "x\[^ \]* & y" 1 "vrp1" { xfail > *-*-* } } } */ > +/* { dg-final { scan-tree-dump-times "x\[^ \]* & y" 1 "vrp1" } } */ > > =A0/* These two are fully simplified by VRP. =A0*/ > =A0/* { dg-final { scan-tree-dump-times "x\[^ \]* \[|\] y" 1 "vrp1" } } */ > =A0/* { dg-final { scan-tree-dump-times "x\[^ \]* \\^ 1" 1 "vrp1" } } */ > > =A0/* { dg-final { cleanup-tree-dump "vrp\[0-9\]" } } */ > -/* { dg-final { cleanup-tree-dump "dom\[0-9\]" } } */ > Index: gcc/gcc/tree-ssa-propagate.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gcc.orig/gcc/tree-ssa-propagate.c =A0 2011-07-13 12:57:46.870620200 += 0200 > +++ gcc/gcc/tree-ssa-propagate.c =A0 =A0 =A0 =A02011-07-13 22:29:53.25397= 1100 +0200 > @@ -979,6 +979,9 @@ replace_phi_args_in (gimple phi, ssa_pro > > =A0 =A0DO_DCE is true if trivially dead stmts can be removed. > > + =A0 If DO_DCE is true, the statements within a BB are walked from > + =A0 last to first element. =A0Otherwise we scan from first to last elem= ent. > + > =A0 =A0Return TRUE when something changed. =A0*/ > > =A0bool > @@ -1059,9 +1062,10 @@ substitute_and_fold (ssa_prop_get_value_ > =A0 =A0 =A0 =A0for (i =3D gsi_start_phis (bb); !gsi_end_p (i); gsi_next (= &i)) > =A0 =A0 =A0 =A0 =A0replace_phi_args_in (gsi_stmt (i), get_value_fn); > > - =A0 =A0 =A0/* Propagate known values into stmts. =A0Do a backward walk = to expose > - =A0 =A0 =A0 =A0more trivially deletable stmts. =A0*/ > - =A0 =A0 =A0for (i =3D gsi_last_bb (bb); !gsi_end_p (i);) > + =A0 =A0 =A0/* Propagate known values into stmts. =A0Do a backward walk = if > + =A0 =A0 =A0 =A0 do_dce is true. In some case it exposes > + =A0 =A0 =A0 =A0more trivially deletable stmts to walk backward. =A0*/ > + =A0 =A0 =A0for (i =3D (do_dce ? gsi_last_bb (bb) : gsi_start_bb (bb)); > !gsi_end_p (i);) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 bool did_replace; > =A0 =A0 =A0 =A0 =A0gimple stmt =3D gsi_stmt (i); > @@ -1070,7 +1074,10 @@ substitute_and_fold (ssa_prop_get_value_ > =A0 =A0 =A0 =A0 =A0gimple_stmt_iterator oldi; > > =A0 =A0 =A0 =A0 =A0oldi =3D i; > - =A0 =A0 =A0 =A0 gsi_prev (&i); > + =A0 =A0 =A0 =A0 if (do_dce) > + =A0 =A0 =A0 =A0 =A0 gsi_prev (&i); > + =A0 =A0 =A0 =A0 else > + =A0 =A0 =A0 =A0 =A0 gsi_next (&i); > > =A0 =A0 =A0 =A0 =A0/* Ignore ASSERT_EXPRs. =A0They are used by VRP to gen= erate > =A0 =A0 =A0 =A0 =A0 =A0 range information for names and they are discarded The tree-ssa-propagate.c change is ok to apply separately. > Index: gcc/gcc/tree-vrp.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- gcc.orig/gcc/tree-vrp.c =A0 =A0 2011-07-13 22:25:14.690598100 +0200 > +++ gcc/gcc/tree-vrp.c =A02011-07-15 08:53:21.086266100 +0200 > @@ -2174,9 +2174,7 @@ extract_range_from_binary_expr (value_ra > =A0 =A0 =A0 && code !=3D MIN_EXPR > =A0 =A0 =A0 && code !=3D MAX_EXPR > =A0 =A0 =A0 && code !=3D BIT_AND_EXPR > - =A0 =A0 =A0&& code !=3D BIT_IOR_EXPR > - =A0 =A0 =A0&& code !=3D TRUTH_AND_EXPR > - =A0 =A0 =A0&& code !=3D TRUTH_OR_EXPR) > + =A0 =A0 =A0&& code !=3D BIT_IOR_EXPR) > =A0 =A0 { > =A0 =A0 =A0 /* We can still do constant propagation here. =A0*/ > =A0 =A0 =A0 tree const_op0 =3D op_with_constant_singleton_value_range (op= 0); > @@ -2231,8 +2229,7 @@ extract_range_from_binary_expr (value_ra > =A0 =A0 =A0divisions. =A0TODO, we may be able to derive anti-ranges in > =A0 =A0 =A0some cases. =A0*/ > =A0 if (code !=3D BIT_AND_EXPR > - =A0 =A0 =A0&& code !=3D TRUTH_AND_EXPR > - =A0 =A0 =A0&& code !=3D TRUTH_OR_EXPR > + =A0 =A0 =A0&& code !=3D BIT_IOR_EXPR > =A0 =A0 =A0 && code !=3D TRUNC_DIV_EXPR > =A0 =A0 =A0 && code !=3D FLOOR_DIV_EXPR > =A0 =A0 =A0 && code !=3D CEIL_DIV_EXPR > @@ -2291,6 +2288,8 @@ extract_range_from_binary_expr (value_ra > =A0 =A0 =A0 =A0 =A0else > =A0 =A0 =A0 =A0 =A0 =A0set_value_range_to_varying (vr); > =A0 =A0 =A0 =A0} > + =A0 =A0 =A0else if (code =3D=3D BIT_IOR_EXPR) > + =A0 =A0 =A0 =A0set_value_range_to_varying (vr); Again, how do we arrive with a BIT_IOR_EXPR with pointer type here? We're not supposed to have that (well, in theory, nothing verifies that). > =A0 =A0 =A0 else > =A0 =A0 =A0 =A0gcc_unreachable (); > > @@ -2299,55 +2298,7 @@ extract_range_from_binary_expr (value_ra > > =A0 /* For integer ranges, apply the operation to each end of the > =A0 =A0 =A0range and see what we end up with. =A0*/ > - =A0if (code =3D=3D TRUTH_AND_EXPR > - =A0 =A0 =A0|| code =3D=3D TRUTH_OR_EXPR) > - =A0 =A0{ > - =A0 =A0 =A0/* If one of the operands is zero, we know that the whole > - =A0 =A0 =A0 =A0expression evaluates zero. =A0*/ > - =A0 =A0 =A0if (code =3D=3D TRUTH_AND_EXPR > - =A0 =A0 =A0 =A0 && ((vr0.type =3D=3D VR_RANGE > - =A0 =A0 =A0 =A0 =A0 =A0 =A0&& integer_zerop (vr0.min) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0&& integer_zerop (vr0.max)) > - =A0 =A0 =A0 =A0 =A0 =A0 || (vr1.type =3D=3D VR_RANGE > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && integer_zerop (vr1.min) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && integer_zerop (vr1.max)))) > - =A0 =A0 =A0 { > - =A0 =A0 =A0 =A0 type =3D VR_RANGE; > - =A0 =A0 =A0 =A0 min =3D max =3D build_int_cst (expr_type, 0); > - =A0 =A0 =A0 } > - =A0 =A0 =A0/* If one of the operands is one, we know that the whole > - =A0 =A0 =A0 =A0expression evaluates one. =A0*/ > - =A0 =A0 =A0else if (code =3D=3D TRUTH_OR_EXPR > - =A0 =A0 =A0 =A0 =A0 =A0 =A0&& ((vr0.type =3D=3D VR_RANGE > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && integer_onep (vr0.min) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && integer_onep (vr0.max)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0|| (vr1.type =3D=3D VR_RANGE > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& integer_onep (vr1.min) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& integer_onep (vr1.max)))) > - =A0 =A0 =A0 { > - =A0 =A0 =A0 =A0 type =3D VR_RANGE; > - =A0 =A0 =A0 =A0 min =3D max =3D build_int_cst (expr_type, 1); > - =A0 =A0 =A0 } > - =A0 =A0 =A0else if (vr0.type !=3D VR_VARYING > - =A0 =A0 =A0 =A0 =A0 =A0 =A0&& vr1.type !=3D VR_VARYING > - =A0 =A0 =A0 =A0 =A0 =A0 =A0&& vr0.type =3D=3D vr1.type > - =A0 =A0 =A0 =A0 =A0 =A0 =A0&& !symbolic_range_p (&vr0) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0&& !overflow_infinity_range_p (&vr0) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0&& !symbolic_range_p (&vr1) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0&& !overflow_infinity_range_p (&vr1)) > - =A0 =A0 =A0 { > - =A0 =A0 =A0 =A0 /* Boolean expressions cannot be folded with int_const_= binop. =A0*/ > - =A0 =A0 =A0 =A0 min =3D fold_binary (code, expr_type, vr0.min, vr1.min); > - =A0 =A0 =A0 =A0 max =3D fold_binary (code, expr_type, vr0.max, vr1.max); > - =A0 =A0 =A0 } > - =A0 =A0 =A0else > - =A0 =A0 =A0 { > - =A0 =A0 =A0 =A0 /* The result of a TRUTH_*_EXPR is always true or false= . =A0*/ > - =A0 =A0 =A0 =A0 set_value_range_to_truthvalue (vr, expr_type); > - =A0 =A0 =A0 =A0 return; > - =A0 =A0 =A0 } > - =A0 =A0} > - =A0else if (code =3D=3D PLUS_EXPR > + =A0if (code =3D=3D PLUS_EXPR > =A0 =A0 =A0 =A0 =A0 || code =3D=3D MIN_EXPR > =A0 =A0 =A0 =A0 =A0 || code =3D=3D MAX_EXPR) > =A0 =A0 { > @@ -2682,71 +2633,125 @@ extract_range_from_binary_expr (value_ra > =A0 =A0 =A0 double_int may_be_nonzero0, may_be_nonzero1; > =A0 =A0 =A0 double_int must_be_nonzero0, must_be_nonzero1; > > - =A0 =A0 =A0vr0_int_cst_singleton_p =3D range_int_cst_singleton_p (&vr0); > - =A0 =A0 =A0vr1_int_cst_singleton_p =3D range_int_cst_singleton_p (&vr1); > - =A0 =A0 =A0int_cst_range0 =3D zero_nonzero_bits_from_vr (&vr0, &may_be_= nonzero0, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 &must_be_nonzero0); > - =A0 =A0 =A0int_cst_range1 =3D zero_nonzero_bits_from_vr (&vr1, &may_be_= nonzero1, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 &must_be_nonzero1); > - > - =A0 =A0 =A0type =3D VR_RANGE; > - =A0 =A0 =A0if (vr0_int_cst_singleton_p && vr1_int_cst_singleton_p) > - =A0 =A0 =A0 min =3D max =3D int_const_binop (code, vr0.max, vr1.max); > - =A0 =A0 =A0else if (!int_cst_range0 && !int_cst_range1) > + =A0 =A0 =A0/* If one of the operands is zero, we know that the whole > + =A0 =A0 =A0 =A0expression evaluates zero. =A0*/ context diffs help ... now I have to wade through +- mess :/ > + =A0 =A0 =A0if (code =3D=3D BIT_AND_EXPR > + =A0 =A0 =A0 =A0 && ((vr0.type =3D=3D VR_RANGE > + =A0 =A0 =A0 =A0 =A0 =A0 =A0&& integer_zerop (vr0.min) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0&& integer_zerop (vr0.max)) > + =A0 =A0 =A0 =A0 =A0 =A0 || (vr1.type =3D=3D VR_RANGE > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && integer_zerop (vr1.min) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && integer_zerop (vr1.max)))) if you wrap all this in if (vr0_int_cst_singleton_p || vr1_int_cst_singleton_p) it becomes much simpler. > =A0 =A0 =A0 =A0{ > - =A0 =A0 =A0 =A0 set_value_range_to_varying (vr); > - =A0 =A0 =A0 =A0 return; > + =A0 =A0 =A0 =A0 type =3D VR_RANGE; > + =A0 =A0 =A0 =A0 min =3D max =3D build_int_cst (expr_type, 0); this can also be handled better via improving the existing if (vr0_int_cst_singleton_p && vr1_int_cst_singleton_p) min =3D max =3D int_const_binop (code, vr0.max, vr1.max); handling to include the 0 and all-1s cases for AND/IOR instead of trying to move the TRUTH_* code here. > =A0 =A0 =A0 =A0} > - =A0 =A0 =A0else if (code =3D=3D BIT_AND_EXPR) > + =A0 =A0 =A0/* If one of the operands has all bits set to one, we know > + =A0 =A0 =A0 =A0 that the whole expression evaluates to this one. =A0*/ > + =A0 =A0 =A0else if (code =3D=3D BIT_IOR_EXPR > + =A0 =A0 =A0 =A0 =A0 =A0 =A0&& (vr0.type =3D=3D VR_RANGE > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& integer_all_onesp (vr0.min) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& integer_all_onesp (vr0.max))) > =A0 =A0 =A0 =A0{ > - =A0 =A0 =A0 =A0 min =3D double_int_to_tree (expr_type, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dou= ble_int_and (must_be_nonzero0, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 must_be_nonzero1)); > - =A0 =A0 =A0 =A0 max =3D double_int_to_tree (expr_type, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dou= ble_int_and (may_be_nonzero0, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 may_be_nonzero1)); > - =A0 =A0 =A0 =A0 if (TREE_OVERFLOW (min) || tree_int_cst_sgn (min) < 0) > - =A0 =A0 =A0 =A0 =A0 min =3D NULL_TREE; > - =A0 =A0 =A0 =A0 if (TREE_OVERFLOW (max) || tree_int_cst_sgn (max) < 0) > - =A0 =A0 =A0 =A0 =A0 max =3D NULL_TREE; > - =A0 =A0 =A0 =A0 if (int_cst_range0 && tree_int_cst_sgn (vr0.min) >=3D 0) > - =A0 =A0 =A0 =A0 =A0 { > - =A0 =A0 =A0 =A0 =A0 =A0 if (min =3D=3D NULL_TREE) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 min =3D build_int_cst (expr_type, 0); > - =A0 =A0 =A0 =A0 =A0 =A0 if (max =3D=3D NULL_TREE || tree_int_cst_lt (vr= 0.max, max)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 max =3D vr0.max; > + =A0 =A0 =A0 =A0 type =3D VR_RANGE; > + =A0 =A0 =A0 =A0 min =3D max =3D fold_convert (expr_type, vr0.min); > + =A0 =A0 =A0 } > + =A0 =A0 =A0else if (code =3D=3D BIT_IOR_EXPR > + =A0 =A0 =A0 =A0 =A0 =A0 =A0&& (vr1.type =3D=3D VR_RANGE > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& integer_all_onesp (vr1.min) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& integer_all_onesp (vr1.max))) > + =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 type =3D VR_RANGE; > + =A0 =A0 =A0 =A0 min =3D max =3D fold_convert (expr_type, vr1.min); > + =A0 =A0 =A0 } > + =A0 =A0 =A0else if (TYPE_PRECISION (TREE_TYPE (op1)) =3D=3D 1) > + =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 if (vr0.type !=3D VR_VARYING > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& vr1.type !=3D VR_VARYING > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& vr0.type =3D=3D vr1.type > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& !symbolic_range_p (&vr0) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& !overflow_infinity_range_p (&vr0) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& !symbolic_range_p (&vr1) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0&& !overflow_infinity_range_p (&vr1)) > + =A0 =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 =A0 /* Boolean expressions cannot be folded with in= t_const_binop. =A0*/ > + =A0 =A0 =A0 =A0 =A0 =A0 min =3D fold_binary (code, expr_type, vr0.min, = vr1.min); > + =A0 =A0 =A0 =A0 =A0 =A0 max =3D fold_binary (code, expr_type, vr0.max, = vr1.max); > =A0 =A0 =A0 =A0 =A0 =A0} > - =A0 =A0 =A0 =A0 if (int_cst_range1 && tree_int_cst_sgn (vr1.min) >=3D 0) > + =A0 =A0 =A0 =A0 else > =A0 =A0 =A0 =A0 =A0 =A0{ > - =A0 =A0 =A0 =A0 =A0 =A0 if (min =3D=3D NULL_TREE) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 min =3D build_int_cst (expr_type, 0); > - =A0 =A0 =A0 =A0 =A0 =A0 if (max =3D=3D NULL_TREE || tree_int_cst_lt (vr= 1.max, max)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 max =3D vr1.max; > + =A0 =A0 =A0 =A0 =A0 =A0 set_value_range_to_varying (vr); > + =A0 =A0 =A0 =A0 =A0 =A0 return; > =A0 =A0 =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0} > - =A0 =A0 =A0else if (!int_cst_range0 > - =A0 =A0 =A0 =A0 =A0 =A0 =A0|| !int_cst_range1 > - =A0 =A0 =A0 =A0 =A0 =A0 =A0|| tree_int_cst_sgn (vr0.min) < 0 > - =A0 =A0 =A0 =A0 =A0 =A0 =A0|| tree_int_cst_sgn (vr1.min) < 0) > - =A0 =A0 =A0 { > - =A0 =A0 =A0 =A0 set_value_range_to_varying (vr); > - =A0 =A0 =A0 =A0 return; > - =A0 =A0 =A0 } > =A0 =A0 =A0 else > - =A0 =A0 =A0 { > - =A0 =A0 =A0 =A0 min =3D double_int_to_tree (expr_type, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dou= ble_int_ior (must_be_nonzero0, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 must_be_nonzero1)); > - =A0 =A0 =A0 =A0 max =3D double_int_to_tree (expr_type, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 dou= ble_int_ior (may_be_nonzero0, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 may_be_nonzero1)); > - =A0 =A0 =A0 =A0 if (TREE_OVERFLOW (min) || tree_int_cst_sgn (min) < 0) > - =A0 =A0 =A0 =A0 =A0 min =3D vr0.min; > + =A0 =A0 =A0 =A0{ > + =A0 =A0 =A0 =A0 vr0_int_cst_singleton_p =3D range_int_cst_singleton_p (= &vr0); > + =A0 =A0 =A0 =A0 vr1_int_cst_singleton_p =3D range_int_cst_singleton_p (= &vr1); > + =A0 =A0 =A0 =A0 int_cst_range0 =3D zero_nonzero_bits_from_vr (&vr0, &ma= y_be_nonzero0, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 &must_be_nonzero0); > + =A0 =A0 =A0 =A0 int_cst_range1 =3D zero_nonzero_bits_from_vr (&vr1, &ma= y_be_nonzero1, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 &must_be_nonzero1); > + > + =A0 =A0 =A0 =A0 type =3D VR_RANGE; > + =A0 =A0 =A0 =A0 if (vr0_int_cst_singleton_p && vr1_int_cst_singleton_p) > + =A0 =A0 =A0 =A0 =A0 min =3D max =3D int_const_binop (code, vr0.max, vr1= .max); > + =A0 =A0 =A0 =A0 else if (!int_cst_range0 && !int_cst_range1) > + =A0 =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 =A0 set_value_range_to_varying (vr); > + =A0 =A0 =A0 =A0 =A0 =A0 return; > + =A0 =A0 =A0 =A0 =A0 } > + =A0 =A0 =A0 =A0 else if (code =3D=3D BIT_AND_EXPR) > + =A0 =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 =A0 min =3D double_int_to_tree (expr_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 double_int_and (must_be_nonzero0, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 must_be_nonzero1)); > + =A0 =A0 =A0 =A0 =A0 =A0 max =3D double_int_to_tree (expr_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 double_int_and (may_be_nonzero0, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 may_be_nonzero1)); > + =A0 =A0 =A0 =A0 =A0 =A0 if (TREE_OVERFLOW (min) || tree_int_cst_sgn (mi= n) < 0) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 min =3D NULL_TREE; > + =A0 =A0 =A0 =A0 =A0 =A0 if (TREE_OVERFLOW (max) || tree_int_cst_sgn (ma= x) < 0) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 max =3D NULL_TREE; > + =A0 =A0 =A0 =A0 =A0 =A0 if (int_cst_range0 && tree_int_cst_sgn (vr0.min= ) >=3D 0) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (min =3D=3D NULL_TREE) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 min =3D build_int_cst (expr_type, 0= ); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (max =3D=3D NULL_TREE || tree_int_cs= t_lt (vr0.max, max)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 max =3D vr0.max; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } > + =A0 =A0 =A0 =A0 =A0 =A0 if (int_cst_range1 && tree_int_cst_sgn (vr1.min= ) >=3D 0) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (min =3D=3D NULL_TREE) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 min =3D build_int_cst (expr_type, 0= ); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 if (max =3D=3D NULL_TREE || tree_int_cs= t_lt (vr1.max, max)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 max =3D vr1.max; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 } > + =A0 =A0 =A0 =A0 =A0 } > + =A0 =A0 =A0 =A0 else if (!int_cst_range0 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0|| !int_cst_range1 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0|| tree_int_cst_sgn (vr0.min) < 0 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0|| tree_int_cst_sgn (vr1.min) < 0) > + =A0 =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 =A0 set_value_range_to_varying (vr); > + =A0 =A0 =A0 =A0 =A0 =A0 return; > + =A0 =A0 =A0 =A0 =A0 } > =A0 =A0 =A0 =A0 =A0else > - =A0 =A0 =A0 =A0 =A0 min =3D vrp_int_const_binop (MAX_EXPR, min, vr0.min= ); > - =A0 =A0 =A0 =A0 if (TREE_OVERFLOW (max) || tree_int_cst_sgn (max) < 0) > - =A0 =A0 =A0 =A0 =A0 max =3D NULL_TREE; > - =A0 =A0 =A0 =A0 min =3D vrp_int_const_binop (MAX_EXPR, min, vr1.min); > + =A0 =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 =A0 min =3D double_int_to_tree (expr_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 double_int_ior (must_be_nonzero0, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 must_be_nonzero1)); > + =A0 =A0 =A0 =A0 =A0 =A0 max =3D double_int_to_tree (expr_type, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 double_int_ior (may_be_nonzero0, > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 may_be_nonzero1)); > + =A0 =A0 =A0 =A0 =A0 =A0 if (TREE_OVERFLOW (min) || tree_int_cst_sgn (mi= n) < 0) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 min =3D vr0.min; > + =A0 =A0 =A0 =A0 =A0 =A0 else > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 min =3D vrp_int_const_binop (MAX_EXPR, min,= vr0.min); > + =A0 =A0 =A0 =A0 =A0 =A0 if (TREE_OVERFLOW (max) || tree_int_cst_sgn (ma= x) < 0) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 max =3D NULL_TREE; > + =A0 =A0 =A0 =A0 =A0 =A0 min =3D vrp_int_const_binop (MAX_EXPR, min, vr1= .min); > + =A0 =A0 =A0 =A0 =A0 } > =A0 =A0 =A0 =A0} > =A0 =A0 } > =A0 else > @@ -2809,7 +2814,7 @@ extract_range_from_unary_expr (value_ran > =A0 =A0 =A0cannot easily determine a resulting range. =A0*/ > =A0 if (code =3D=3D FIX_TRUNC_EXPR > =A0 =A0 =A0 || code =3D=3D FLOAT_EXPR > - =A0 =A0 =A0|| code =3D=3D BIT_NOT_EXPR > + =A0 =A0 =A0|| (code =3D=3D BIT_NOT_EXPR && TYPE_PRECISION (type) !=3D 1) Huh? That doesn't look worthwhile. Please instead provide true support for BIT_NOT_EXPR, as a separate patch. > =A0 =A0 =A0 || code =3D=3D CONJ_EXPR) > =A0 =A0 { > =A0 =A0 =A0 /* We can still do constant propagation here. =A0*/ > @@ -3303,10 +3308,7 @@ extract_range_from_assignment (value_ran > =A0 =A0 extract_range_from_assert (vr, gimple_assign_rhs1 (stmt)); > =A0 else if (code =3D=3D SSA_NAME) > =A0 =A0 extract_range_from_ssa_name (vr, gimple_assign_rhs1 (stmt)); > - =A0else if (TREE_CODE_CLASS (code) =3D=3D tcc_binary > - =A0 =A0 =A0 =A0 =A0|| code =3D=3D TRUTH_AND_EXPR > - =A0 =A0 =A0 =A0 =A0|| code =3D=3D TRUTH_OR_EXPR > - =A0 =A0 =A0 =A0 =A0|| code =3D=3D TRUTH_XOR_EXPR) > + =A0else if (TREE_CODE_CLASS (code) =3D=3D tcc_binary) > =A0 =A0 extract_range_from_binary_expr (vr, gimple_assign_rhs_code (stmt), > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gi= mple_expr_type (stmt), > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0gi= mple_assign_rhs1 (stmt), > @@ -3976,7 +3978,9 @@ build_assert_expr_for (tree cond, tree v > =A0 =A0 =A0 tree a =3D build2 (ASSERT_EXPR, TREE_TYPE (v), v, cond); > =A0 =A0 =A0 assertion =3D gimple_build_assign (n, a); > =A0 =A0 } > - =A0else if (TREE_CODE (cond) =3D=3D TRUTH_NOT_EXPR) > + =A0else if (TREE_CODE (cond) =3D=3D TRUTH_NOT_EXPR > + =A0 =A0 =A0 =A0 =A0|| (TREE_CODE (cond) =3D=3D BIT_NOT_EXPR > + =A0 =A0 =A0 =A0 =A0 =A0 =A0&& TYPE_PRECISION (TREE_TYPE (cond)) =3D=3D = 1)) I dont' think we arrive with TRUTH_NOT_EXPR here either - look at the single caller please. > =A0 =A0 { > =A0 =A0 =A0 /* Given !V, build the assignment N =3D false. =A0*/ > =A0 =A0 =A0 tree op0 =3D TREE_OPERAND (cond, 0); > @@ -4519,11 +4523,9 @@ register_edge_assert_for_1 (tree op, enu > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0invert); > =A0 =A0 } > =A0 else if ((code =3D=3D NE_EXPR > - =A0 =A0 =A0 =A0 =A0 && (gimple_assign_rhs_code (op_def) =3D=3D TRUTH_AN= D_EXPR > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 || gimple_assign_rhs_code (op_def) =3D=3D B= IT_AND_EXPR)) > + =A0 =A0 =A0 =A0 =A0 && gimple_assign_rhs_code (op_def) =3D=3D BIT_AND_E= XPR) > =A0 =A0 =A0 =A0 =A0 || (code =3D=3D EQ_EXPR > - =A0 =A0 =A0 =A0 =A0 =A0 =A0&& (gimple_assign_rhs_code (op_def) =3D=3D T= RUTH_OR_EXPR > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0|| gimple_assign_rhs_code (op_def) = =3D=3D BIT_IOR_EXPR))) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0&& gimple_assign_rhs_code (op_def) =3D=3D BI= T_IOR_EXPR)) > =A0 =A0 { > =A0 =A0 =A0 /* Recurse on each operand. =A0*/ > =A0 =A0 =A0 retval |=3D register_edge_assert_for_1 (gimple_assign_rhs1 (o= p_def), > @@ -4531,7 +4533,9 @@ register_edge_assert_for_1 (tree op, enu > =A0 =A0 =A0 retval |=3D register_edge_assert_for_1 (gimple_assign_rhs2 (o= p_def), > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0code, e, bsi); > =A0 =A0 } > - =A0else if (gimple_assign_rhs_code (op_def) =3D=3D TRUTH_NOT_EXPR) > + =A0else if (gimple_assign_rhs_code (op_def) =3D=3D TRUTH_NOT_EXPR > + =A0 =A0 =A0 =A0 =A0|| (gimple_assign_rhs_code (op_def) =3D=3D BIT_NOT_E= XPR > + =A0 =A0 =A0 =A0 =A0 =A0 =A0&& TYPE_PRECISION (TREE_TYPE (op)) =3D=3D 1)) Now without the TRUTH_NOT_EXPR handling. Also elsewhere I guess. > =A0 =A0 { > =A0 =A0 =A0 /* Recurse, flipping CODE. =A0*/ > =A0 =A0 =A0 code =3D invert_tree_comparison (code, false); > @@ -4588,8 +4592,8 @@ register_edge_assert_for (tree name, edg > =A0 =A0 =A0the value zero or one, then we may be able to assert values > =A0 =A0 =A0for SSA_NAMEs which flow into COND. =A0*/ > > - =A0/* In the case of NAME =3D=3D 1 or NAME !=3D 0, for TRUTH_AND_EXPR d= efining > - =A0 =A0 statement of NAME we can assert both operands of the TRUTH_AND_= EXPR > + =A0/* In the case of NAME =3D=3D 1 or NAME !=3D 0, for BIT_AND_EXPR def= ining > + =A0 =A0 statement of NAME we can assert both operands of the BIT_AND_EX= PR > =A0 =A0 =A0have nonzero value. =A0*/ > =A0 if (((comp_code =3D=3D EQ_EXPR && integer_onep (val)) > =A0 =A0 =A0 =A0|| (comp_code =3D=3D NE_EXPR && integer_zerop (val)))) > @@ -4597,8 +4601,7 @@ register_edge_assert_for (tree name, edg > =A0 =A0 =A0 gimple def_stmt =3D SSA_NAME_DEF_STMT (name); > > =A0 =A0 =A0 if (is_gimple_assign (def_stmt) > - =A0 =A0 =A0 =A0 && (gimple_assign_rhs_code (def_stmt) =3D=3D TRUTH_AND_= EXPR > - =A0 =A0 =A0 =A0 =A0 =A0 || gimple_assign_rhs_code (def_stmt) =3D=3D BIT= _AND_EXPR)) > + =A0 =A0 =A0 =A0 && gimple_assign_rhs_code (def_stmt) =3D=3D BIT_AND_EXP= R) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0tree op0 =3D gimple_assign_rhs1 (def_stmt); > =A0 =A0 =A0 =A0 =A0tree op1 =3D gimple_assign_rhs2 (def_stmt); > @@ -4607,8 +4610,8 @@ register_edge_assert_for (tree name, edg > =A0 =A0 =A0 =A0} > =A0 =A0 } > > - =A0/* In the case of NAME =3D=3D 0 or NAME !=3D 1, for TRUTH_OR_EXPR de= fining > - =A0 =A0 statement of NAME we can assert both operands of the TRUTH_OR_E= XPR > + =A0/* In the case of NAME =3D=3D 0 or NAME !=3D 1, for BIT_IOR_EXPR def= ining > + =A0 =A0 statement of NAME we can assert both operands of the BIT_IOR_EX= PR > =A0 =A0 =A0have zero value. =A0*/ > =A0 if (((comp_code =3D=3D EQ_EXPR && integer_zerop (val)) > =A0 =A0 =A0 =A0|| (comp_code =3D=3D NE_EXPR && integer_onep (val)))) > @@ -4616,11 +4619,12 @@ register_edge_assert_for (tree name, edg > =A0 =A0 =A0 gimple def_stmt =3D SSA_NAME_DEF_STMT (name); > > =A0 =A0 =A0 if (is_gimple_assign (def_stmt) > - =A0 =A0 =A0 =A0 && (gimple_assign_rhs_code (def_stmt) =3D=3D TRUTH_OR_E= XPR > + =A0 =A0 =A0 =A0 && ((gimple_assign_rhs_code (def_stmt) =3D=3D BIT_IOR_E= XPR > + =A0 =A0 =A0 =A0 =A0 =A0 =A0&& TYPE_PRECISION (TREE_TYPE (name)) =3D=3D = 1) > =A0 =A0 =A0 =A0 =A0 =A0 =A0/* For BIT_IOR_EXPR only if NAME =3D=3D 0 both= operands have > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 necessarily zero value. =A0*/ The comment needs updating and the condition wants to be re-structured. > =A0 =A0 =A0 =A0 =A0 =A0 =A0|| (comp_code =3D=3D EQ_EXPR > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && (gimple_assign_rhs_code (def_stmt) = =3D=3D BIT_IOR_EXPR)))) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 && gimple_assign_rhs_code (def_stmt) = =3D=3D BIT_IOR_EXPR))) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0tree op0 =3D gimple_assign_rhs1 (def_stmt); > =A0 =A0 =A0 =A0 =A0tree op1 =3D gimple_assign_rhs2 (def_stmt); > @@ -6747,19 +6751,95 @@ varying: > =A0 return SSA_PROP_VARYING; > =A0} > > +/* Returns operand1 of ssa-name with SSA_NAME as code, Otherwise it > + =A0 returns NULL_TREE. =A0*/ > +static tree > +ssa_name_get_inner_ssa_name_p (tree op) > +{ > + =A0gimple stmt; > + > + =A0if (TREE_CODE (op) !=3D SSA_NAME > + =A0 =A0 =A0|| !is_gimple_assign (SSA_NAME_DEF_STMT (op))) > + =A0 =A0return NULL_TREE; > + =A0stmt =3D SSA_NAME_DEF_STMT (op); > + =A0if (gimple_assign_rhs_code (stmt) !=3D SSA_NAME) > + =A0 =A0return NULL_TREE; > + =A0return gimple_assign_rhs1 (stmt); > +} This and the following should be all a separate patch. Please. > +/* Returns operand of cast operation, if OP is a type-conversion. Otherw= ise > + =A0 return NULL_TREE. =A0*/ > +static tree > +ssa_name_get_cast_to_p (tree op) > +{ > + =A0gimple stmt; > + > + =A0if (TREE_CODE (op) !=3D SSA_NAME > + =A0 =A0 =A0|| !is_gimple_assign (SSA_NAME_DEF_STMT (op))) > + =A0 =A0return NULL_TREE; > + =A0stmt =3D SSA_NAME_DEF_STMT (op); > + =A0if (!CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (stmt))) > + =A0 =A0return NULL_TREE; > + =A0return gimple_assign_rhs1 (stmt); > +} > + > =A0/* Simplify boolean operations if the source is known > =A0 =A0to be already a boolean. =A0*/ > =A0static bool > =A0simplify_truth_ops_using_ranges (gimple_stmt_iterator *gsi, gimple stm= t) > =A0{ > =A0 enum tree_code rhs_code =3D gimple_assign_rhs_code (stmt); > + =A0gimple stmt2 =3D stmt; > =A0 tree val =3D NULL; > - =A0tree op0, op1; > + =A0tree op0, op1, cop0, cop1; > =A0 value_range_t *vr; > =A0 bool sop =3D false; > =A0 bool need_conversion; > + =A0location_t loc =3D gimple_location (stmt); > > =A0 op0 =3D gimple_assign_rhs1 (stmt); > + =A0op1 =3D NULL_TREE; > + > + =A0/* Handle cases with prefixed type-cast. =A0*/ What's a 'prefixed type-cast'? Isn't most of simplify_truth(!)_ops_using_ranges obsolete now? > + =A0if (CONVERT_EXPR_CODE_P (rhs_code) > + =A0 =A0 =A0&& INTEGRAL_TYPE_P (TREE_TYPE (op0)) > + =A0 =A0 =A0&& TREE_CODE (op0) =3D=3D SSA_NAME > + =A0 =A0 =A0&& is_gimple_assign (SSA_NAME_DEF_STMT (op0)) > + =A0 =A0 =A0&& INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_lhs (stmt)))) > + =A0 =A0{ > + =A0 =A0 =A0stmt2 =3D SSA_NAME_DEF_STMT (op0); > + =A0 =A0 =A0op0 =3D gimple_assign_rhs1 (stmt2); > + =A0 =A0 =A0if (!INTEGRAL_TYPE_P (TREE_TYPE (op0))) > + =A0 =A0 =A0 return false; > + =A0 =A0 =A0rhs_code =3D gimple_assign_rhs_code (stmt2); > + =A0 =A0 =A0if (rhs_code !=3D BIT_NOT_EXPR > + =A0 =A0 =A0 =A0 =A0&& rhs_code !=3D TRUTH_NOT_EXPR > + =A0 =A0 =A0 =A0 && rhs_code !=3D BIT_AND_EXPR > + =A0 =A0 =A0 =A0 && rhs_code !=3D BIT_IOR_EXPR > + =A0 =A0 =A0 =A0 && rhs_code !=3D BIT_XOR_EXPR > + =A0 =A0 =A0 =A0 && rhs_code !=3D NE_EXPR && rhs_code !=3D EQ_EXPR) > + =A0 =A0 =A0 return false; > + =A0 =A0 =A0if (rhs_code =3D=3D BIT_AND_EXPR || rhs_code =3D=3D BIT_IOR_= EXPR > + =A0 =A0 =A0 =A0 || rhs_code =3D=3D BIT_XOR_EXPR > + =A0 =A0 =A0 =A0 || rhs_code =3D=3D NE_EXPR || rhs_code =3D=3D EQ_EXPR) > + =A0 =A0 =A0 op1 =3D gimple_assign_rhs2 (stmt2); > + =A0 =A0 =A0if (gimple_has_location (stmt2)) > + =A0 =A0 =A0 =A0loc =3D gimple_location (stmt2); > + =A0 =A0} > + =A0else if (CONVERT_EXPR_CODE_P (rhs_code)) > + =A0 =A0return false; > + =A0else if (rhs_code =3D=3D BIT_AND_EXPR || rhs_code =3D=3D BIT_IOR_EXPR > + =A0 =A0 =A0|| rhs_code =3D=3D BIT_XOR_EXPR > + =A0 =A0 =A0|| rhs_code =3D=3D NE_EXPR || rhs_code =3D=3D EQ_EXPR) > + =A0 =A0op1 =3D gimple_assign_rhs2 (stmt); > + > + =A0/* ~X is only equivalent of !X, if type-precision is one and X has > + =A0 =A0 an integral type. =A0*/ > + =A0if (rhs_code =3D=3D BIT_NOT_EXPR > + =A0 =A0 =A0&& (!INTEGRAL_TYPE_P (TREE_TYPE (op0)) > + =A0 =A0 =A0 =A0 || TYPE_PRECISION (TREE_TYPE (op0)) !=3D 1)) > + =A0 =A0return false; > + > =A0 if (TYPE_PRECISION (TREE_TYPE (op0)) !=3D 1) > =A0 =A0 { > =A0 =A0 =A0 if (TREE_CODE (op0) !=3D SSA_NAME) > @@ -6775,22 +6855,100 @@ simplify_truth_ops_using_ranges (gimple_ > =A0 =A0 =A0 =A0 return false; > =A0 =A0 } > > - =A0if (rhs_code =3D=3D TRUTH_NOT_EXPR) > + =A0if (op1 && TREE_CODE (op1) !=3D INTEGER_CST > + =A0 =A0 =A0&& TYPE_PRECISION (TREE_TYPE (op1)) !=3D 1) > + =A0 =A0{ > + =A0 =A0 =A0vr =3D get_value_range (op1); > + =A0 =A0 =A0val =3D compare_range_with_value (GE_EXPR, vr, integer_zero_= node, &sop); > + =A0 =A0 =A0if (!val || !integer_onep (val)) > + =A0 =A0 =A0 return false; > + > + =A0 =A0 =A0val =3D compare_range_with_value (LE_EXPR, vr, integer_one_n= ode, &sop); > + =A0 =A0 =A0if (!val || !integer_onep (val)) > + =A0 =A0 =A0 return false; > + =A0 =A0} > + > + =A0need_conversion =3D > + =A0 =A0!useless_type_conversion_p (TREE_TYPE (gimple_assign_lhs (stmt)), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TREE_TYPE (= op0)); > + > + =A0/* As comparisons X !=3D 0 getting folded by prior pass to (bool) X, > + =A0 =A0 but X =3D=3D 0 might be not folded for none boolean type of X > + =A0 =A0 to (bool) (X ^ 1). > + =A0 =A0 So for bitwise-binary operations we have three cases to handle: > + =A0 =A0 a) ((bool) X) op ((bool) Y) > + =A0 =A0 b) ((bool) X) op (Y =3D=3D 0) OR (X =3D=3D 0) op ((bool) Y) > + =A0 =A0 c) (X =3D=3D 0) op (Y =3D=3D 0) > + =A0 =A0 The later two cases can't be handled for now, as vr tables > + =A0 =A0 would need to be adjusted. =A0*/ > + =A0if (need_conversion > + =A0 =A0 =A0&& (rhs_code =3D=3D BIT_XOR_EXPR > + =A0 =A0 =A0 =A0 || rhs_code =3D=3D BIT_AND_EXPR > + =A0 =A0 =A0 =A0 || rhs_code =3D=3D BIT_IOR_EXPR) > + =A0 =A0 =A0&& TREE_CODE (op1) =3D=3D SSA_NAME && TREE_CODE (op0) =3D=3D= SSA_NAME) > + =A0 =A0{ > + =A0 =A0 =A0cop0 =3D ssa_name_get_cast_to_p (op0); > + =A0 =A0 =A0cop1 =3D ssa_name_get_cast_to_p (op1); > + =A0 =A0 =A0if (!cop0 || !cop1) > + =A0 =A0 =A0 =A0/* We would need an new statment for cases b and c, and = we can't > + =A0 =A0 =A0 =A0 =A0 due vr table, so bail out. =A0*/ > + =A0 =A0 =A0 =A0return false; > + > + =A0 =A0 =A0if (!INTEGRAL_TYPE_P (TREE_TYPE (cop0)) > + =A0 =A0 =A0 =A0 || !types_compatible_p (TREE_TYPE (cop0), TREE_TYPE (co= p1))) > + =A0 =A0 =A0 return false; > + =A0 =A0 =A0need_conversion =3D > + =A0 =A0 =A0 !useless_type_conversion_p (TREE_TYPE (gimple_assign_lhs (s= tmt)), > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 TRE= E_TYPE (cop0)); > + =A0 =A0 =A0if (need_conversion) > + =A0 =A0 =A0 return false; > + =A0 =A0 =A0op0 =3D cop0; > + =A0 =A0 =A0op1 =3D cop1; > + > + =A0 =A0 =A0/* We need to re-check if value ranges for new operands > + =A0 =A0 =A0 =A0 for 1-bit precision/range. =A0*/ > + =A0 =A0 =A0if (TYPE_PRECISION (TREE_TYPE (op0)) !=3D 1) > + =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 if (TREE_CODE (op0) !=3D SSA_NAME) > + =A0 =A0 =A0 =A0 =A0 return false; > + =A0 =A0 =A0 =A0 vr =3D get_value_range (op0); > + > + =A0 =A0 =A0 =A0 val =3D compare_range_with_value (GE_EXPR, vr, integer_= zero_node, &sop); > + =A0 =A0 =A0 =A0 if (!val || !integer_onep (val)) > + =A0 =A0 =A0 =A0 =A0 return false; > + > + =A0 =A0 =A0 =A0 val =3D compare_range_with_value (LE_EXPR, vr, integer_= one_node, &sop); > + =A0 =A0 =A0 =A0 if (!val || !integer_onep (val)) > + =A0 =A0 =A0 =A0 =A0 return false; > + =A0 =A0 =A0 } > + > + =A0 =A0 =A0if (op1 && TYPE_PRECISION (TREE_TYPE (op1)) !=3D 1) > + =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 vr =3D get_value_range (op1); > + =A0 =A0 =A0 =A0 val =3D compare_range_with_value (GE_EXPR, vr, integer_= zero_node, &sop); > + =A0 =A0 =A0 =A0 if (!val || !integer_onep (val)) > + =A0 =A0 =A0 =A0 =A0 return false; > + > + =A0 =A0 =A0 =A0 val =3D compare_range_with_value (LE_EXPR, vr, integer_= one_node, &sop); > + =A0 =A0 =A0 =A0 if (!val || !integer_onep (val)) > + =A0 =A0 =A0 =A0 =A0 return false; > + =A0 =A0 =A0 } > + =A0 =A0} > + =A0else if (rhs_code =3D=3D TRUTH_NOT_EXPR > + =A0 =A0 =A0 =A0 =A0|| rhs_code =3D=3D BIT_NOT_EXPR) > =A0 =A0 { > =A0 =A0 =A0 rhs_code =3D NE_EXPR; > =A0 =A0 =A0 op1 =3D build_int_cst (TREE_TYPE (op0), 1); > =A0 =A0 } > =A0 else > =A0 =A0 { > - =A0 =A0 =A0op1 =3D gimple_assign_rhs2 (stmt); > - > =A0 =A0 =A0 /* Reduce number of cases to handle. =A0*/ > =A0 =A0 =A0 if (is_gimple_min_invariant (op1)) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0 /* Exclude anything that should have been already fol= ded. =A0*/ > =A0 =A0 =A0 =A0 =A0if (rhs_code !=3D EQ_EXPR > =A0 =A0 =A0 =A0 =A0 =A0 =A0&& rhs_code !=3D NE_EXPR > - =A0 =A0 =A0 =A0 =A0 =A0 && rhs_code !=3D TRUTH_XOR_EXPR) > + =A0 =A0 =A0 =A0 =A0 =A0 && rhs_code !=3D BIT_XOR_EXPR) > =A0 =A0 =A0 =A0 =A0 =A0return false; > > =A0 =A0 =A0 =A0 =A0if (!integer_zerop (op1) > @@ -6810,18 +6968,6 @@ simplify_truth_ops_using_ranges (gimple_ > =A0 =A0 =A0 =A0 =A0/* Punt on A =3D=3D B as there is no BIT_XNOR_EXPR. = =A0*/ > =A0 =A0 =A0 =A0 =A0if (rhs_code =3D=3D EQ_EXPR) > =A0 =A0 =A0 =A0 =A0 =A0return false; > - > - =A0 =A0 =A0 =A0 if (TYPE_PRECISION (TREE_TYPE (op1)) !=3D 1) > - =A0 =A0 =A0 =A0 =A0 { > - =A0 =A0 =A0 =A0 =A0 =A0 vr =3D get_value_range (op1); > - =A0 =A0 =A0 =A0 =A0 =A0 val =3D compare_range_with_value (GE_EXPR, vr, = integer_zero_node, &sop); > - =A0 =A0 =A0 =A0 =A0 =A0 if (!val || !integer_onep (val)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false; > - > - =A0 =A0 =A0 =A0 =A0 =A0 val =3D compare_range_with_value (LE_EXPR, vr, = integer_one_node, &sop); > - =A0 =A0 =A0 =A0 =A0 =A0 if (!val || !integer_onep (val)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 return false; > - =A0 =A0 =A0 =A0 =A0 } > =A0 =A0 =A0 =A0} > =A0 =A0 } > > @@ -6834,11 +6980,8 @@ simplify_truth_ops_using_ranges (gimple_ > =A0 =A0 =A0 else > =A0 =A0 =A0 =A0location =3D gimple_location (stmt); > > - =A0 =A0 =A0if (rhs_code =3D=3D TRUTH_AND_EXPR || rhs_code =3D=3D TRUTH_= OR_EXPR) > - =A0 =A0 =A0 =A0warning_at (location, OPT_Wstrict_overflow, > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 _("assuming signed overflow does no= t occur when " > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "simplifying && or || to & or |= ")); > - =A0 =A0 =A0else > + =A0 =A0 =A0if (rhs_code !=3D BIT_AND_EXPR && rhs_code !=3D BIT_IOR_EXPR > + =A0 =A0 =A0 =A0 && rhs_code !=3D BIT_XOR_EXPR) > =A0 =A0 =A0 =A0 warning_at (location, OPT_Wstrict_overflow, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0_("assuming signed overflow does n= ot occur when " > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"simplifying =3D=3D, !=3D or != to identity or ^")); > @@ -6856,19 +6999,17 @@ simplify_truth_ops_using_ranges (gimple_ > > =A0 switch (rhs_code) > =A0 =A0 { > - =A0 =A0case TRUTH_AND_EXPR: > - =A0 =A0 =A0rhs_code =3D BIT_AND_EXPR; > - =A0 =A0 =A0break; > - =A0 =A0case TRUTH_OR_EXPR: > - =A0 =A0 =A0rhs_code =3D BIT_IOR_EXPR; > + =A0 =A0case BIT_AND_EXPR: > + =A0 =A0case BIT_IOR_EXPR: > =A0 =A0 =A0 break; > - =A0 =A0case TRUTH_XOR_EXPR: > + =A0 =A0case BIT_XOR_EXPR: > =A0 =A0 case NE_EXPR: > =A0 =A0 =A0 if (integer_zerop (op1)) > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0 =A0gimple_assign_set_rhs_with_ops (gsi, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0need_conversion ? NOP_EXPR : SSA_NAME, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0op0, NULL); > + =A0 =A0 =A0 =A0 gimple_set_location (stmt, loc); > =A0 =A0 =A0 =A0 =A0update_stmt (gsi_stmt (*gsi)); > =A0 =A0 =A0 =A0 =A0return true; > =A0 =A0 =A0 =A0} > @@ -6879,10 +7020,20 @@ simplify_truth_ops_using_ranges (gimple_ > =A0 =A0 =A0 gcc_unreachable (); > =A0 =A0 } > > + =A0/* We can't insert here new expression as otherwise > + =A0 =A0 tracked vr tables getting out of bounds. =A0*/ > =A0 if (need_conversion) > =A0 =A0 return false; > > + =A0/* Reduce here SSA_NAME -> SSA_NAME. =A0*/ > + =A0while ((cop0 =3D ssa_name_get_inner_ssa_name_p (op0)) !=3D NULL_TREE) > + =A0 =A0op0 =3D cop0; > + > + =A0while ((cop1 =3D ssa_name_get_inner_ssa_name_p (op1)) !=3D NULL_TREE) > + =A0 =A0op1 =3D cop1; > + ?? > =A0 gimple_assign_set_rhs_with_ops (gsi, rhs_code, op0, op1); > + =A0gimple_set_location (stmt, loc); > =A0 update_stmt (gsi_stmt (*gsi)); > =A0 return true; Well, at least previously the function was readable and now it looks like spaghetti. > =A0} > @@ -7417,10 +7568,8 @@ simplify_stmt_using_ranges (gimple_stmt_ > =A0 =A0 =A0 =A0{ > =A0 =A0 =A0 =A0case EQ_EXPR: > =A0 =A0 =A0 =A0case NE_EXPR: > + =A0 =A0 =A0 case BIT_NOT_EXPR: > =A0 =A0 =A0 =A0case TRUTH_NOT_EXPR: > - =A0 =A0 =A0 case TRUTH_AND_EXPR: > - =A0 =A0 =A0 case TRUTH_OR_EXPR: > - =A0 =A0 =A0 =A0case TRUTH_XOR_EXPR: > =A0 =A0 =A0 =A0 =A0 /* Transform EQ_EXPR, NE_EXPR, TRUTH_NOT_EXPR into BI= T_XOR_EXPR > =A0 =A0 =A0 =A0 =A0 =A0 or identity if the RHS is zero or one, and the LH= S are known > =A0 =A0 =A0 =A0 =A0 =A0 to be boolean values. =A0Transform all TRUTH_*_EX= PR into > @@ -7452,13 +7601,21 @@ simplify_stmt_using_ranges (gimple_stmt_ > =A0 =A0 =A0 =A0 =A0 =A0 if all the bits being cleared are already cleared= or > =A0 =A0 =A0 =A0 =A0 =A0 all the bits being set are already set. =A0*/ > =A0 =A0 =A0 =A0 =A0if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))) > - =A0 =A0 =A0 =A0 =A0 return simplify_bit_ops_using_ranges (gsi, stmt); > + =A0 =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 =A0 if (simplify_truth_ops_using_ranges (gsi, stmt)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return true; > + =A0 =A0 =A0 =A0 =A0 =A0 return simplify_bit_ops_using_ranges (gsi, stmt= ); > + =A0 =A0 =A0 =A0 =A0 } > =A0 =A0 =A0 =A0 =A0break; > > =A0 =A0 =A0 =A0CASE_CONVERT: > =A0 =A0 =A0 =A0 =A0if (TREE_CODE (rhs1) =3D=3D SSA_NAME > =A0 =A0 =A0 =A0 =A0 =A0 =A0&& INTEGRAL_TYPE_P (TREE_TYPE (rhs1))) > - =A0 =A0 =A0 =A0 =A0 return simplify_conversion_using_ranges (stmt); > + =A0 =A0 =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 =A0 =A0 if (simplify_truth_ops_using_ranges (gsi, stmt)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 return true; > + =A0 =A0 =A0 =A0 =A0 =A0 return simplify_conversion_using_ranges (stmt); > + =A0 =A0 =A0 =A0 =A0 } > =A0 =A0 =A0 =A0 =A0break; > > =A0 =A0 =A0 =A0default: >