From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1011) id 194343857C7F; Tue, 22 Jun 2021 13:17:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 194343857C7F 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-1724] Add relation between LHS and op1 for casts and copies. X-Act-Checkin: gcc X-Git-Author: Andrew MacLeod X-Git-Refname: refs/heads/master X-Git-Oldrev: ae6b830f31a47aca7ca24c4fea245c29214eef3a X-Git-Newrev: 0f7ccc063a42407f91fa52a54cc480950a45e75c Message-Id: <20210622131736.194343857C7F@sourceware.org> Date: Tue, 22 Jun 2021 13:17:36 +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: Tue, 22 Jun 2021 13:17:36 -0000 https://gcc.gnu.org/g:0f7ccc063a42407f91fa52a54cc480950a45e75c commit r12-1724-g0f7ccc063a42407f91fa52a54cc480950a45e75c Author: Andrew MacLeod Date: Thu Jun 17 13:39:02 2021 -0400 Add relation between LHS and op1 for casts and copies. * range-op.cc (operator_cast::lhs_op1_relation): New. (operator_identity::lhs_op1_relation): Mew. Diff: --- gcc/range-op.cc | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/gcc/range-op.cc b/gcc/range-op.cc index ec4816d69fa..92b314df9dd 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -2115,6 +2115,10 @@ 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; + private: bool truncating_cast_p (const irange &inner, const irange &outer) const; bool inside_domain_p (const wide_int &min, const wide_int &max, @@ -2123,6 +2127,27 @@ private: const irange &outer) const; } op_convert; +// Determine if there is a relationship between LHS and OP1. + +enum tree_code +operator_cast::lhs_op1_relation (const irange &lhs, + const irange &op1, + const irange &op2 ATTRIBUTE_UNUSED) const +{ + if (op1.undefined_p ()) + return VREL_NONE; + // We can't make larger types equivalent to smaller types because we can + // miss sign extensions in a chain of casts. + // u32 = 0xfffff + // s32 = (s32) u32 + // s64 = (s64) s32 + // we cant simply "convert" s64 = (s64)u32 or we get positive 0xffff + // value instead of sign extended negative value. + if (TYPE_PRECISION (lhs.type ()) == TYPE_PRECISION (op1.type ())) + return EQ_EXPR; + return VREL_NONE; +} + // Return TRUE if casting from INNER to OUTER is a truncating cast. inline bool @@ -3325,8 +3350,24 @@ 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_identity; +// Determine if there is a relationship between LHS and OP1. + +enum tree_code +operator_identity::lhs_op1_relation (const irange &lhs, + const irange &op1 ATTRIBUTE_UNUSED, + const irange &op2 ATTRIBUTE_UNUSED) const +{ + if (lhs.undefined_p ()) + return VREL_NONE; + // Simply a copy, so they are equivalent. + return EQ_EXPR; +} + bool operator_identity::fold_range (irange &r, tree type ATTRIBUTE_UNUSED, const irange &lh,