From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1011) id EFB58385840D; Thu, 13 Jan 2022 18:52:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFB58385840D MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Macleod To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-6558] Add relation to unsigned right shift. X-Act-Checkin: gcc X-Git-Author: Andrew MacLeod X-Git-Refname: refs/heads/master X-Git-Oldrev: 0b8464365b15ac108cd1d00d5bc56d229c1340de X-Git-Newrev: 27e4260166950b784fe270ba4f0cae9a66faf1c4 Message-Id: <20220113185214.EFB58385840D@sourceware.org> Date: Thu, 13 Jan 2022 18:52:14 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Jan 2022 18:52:15 -0000 https://gcc.gnu.org/g:27e4260166950b784fe270ba4f0cae9a66faf1c4 commit r12-6558-g27e4260166950b784fe270ba4f0cae9a66faf1c4 Author: Andrew MacLeod Date: Wed Jan 12 13:28:55 2022 -0500 Add relation to unsigned right shift. If the first operand and the shift value of a right shift operation are both >= 0, then we know the LHS of the operation is <= the first operand. PR tree-optimization/96707 gcc/ * range-op.cc (operator_rshift::lhs_op1_relation): New. gcc/testsuite/ * g++.dg/pr96707.C: New. Diff: --- gcc/range-op.cc | 16 ++++++++++++++++ gcc/testsuite/g++.dg/pr96707.C | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index a4f6e9eba29..19bdf30911a 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -1941,9 +1941,25 @@ public: const irange &lhs, const irange &op2, relation_kind rel = VREL_NONE) const; + virtual enum tree_code lhs_op1_relation (const irange &lhs, + const irange &op1, + const irange &op2) const; } op_rshift; +enum tree_code +operator_rshift::lhs_op1_relation (const irange &lhs ATTRIBUTE_UNUSED, + const irange &op1, + const irange &op2) const +{ + // If both operands range are >= 0, then the LHS <= op1. + if (!op1.undefined_p () && !op2.undefined_p () + && wi::ge_p (op1.lower_bound (), 0, TYPE_SIGN (op1.type ())) + && wi::ge_p (op2.lower_bound (), 0, TYPE_SIGN (op2.type ()))) + return LE_EXPR; + return VREL_NONE; +} + bool operator_lshift::fold_range (irange &r, tree type, const irange &op1, diff --git a/gcc/testsuite/g++.dg/pr96707.C b/gcc/testsuite/g++.dg/pr96707.C new file mode 100644 index 00000000000..2653fe3d043 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr96707.C @@ -0,0 +1,10 @@ +/* { dg-do compile} */ +/* { dg-options "-O2 -fdump-tree-evrp" } */ + +bool f(unsigned x, unsigned y) +{ + return (x >> y) <= x; +} + +/* { dg-final { scan-tree-dump "return 1" "evrp" } } */ +