From patchwork Tue Jun 22 13:19:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1495683 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=c9QFa+QN; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4G8Rv25YtHz9sS8 for ; Tue, 22 Jun 2021 23:24:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1DB643890439 for ; Tue, 22 Jun 2021 13:24:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1DB643890439 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1624368251; bh=NhfSq3hKXATJH4a8F7J/AL1y7CeJDgKFsZJsd9KhsN8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=c9QFa+QNZReY8ohu8MDHFAXQVLHwJsHEcaTCtaDu/+FhYBO+0/6cVaN1aiG8bmIAE 7IdutdnCc8/NBwIAnfi1BywNZS/QDlLYWn7KfqDGMZnrwQfQbv9sokGSQrxC4WiSYE mJ2Exsw46J7apCmPoh1av6c2YuwgwBVXnomfdl0w= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id DB3AF3890036 for ; Tue, 22 Jun 2021 13:19:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DB3AF3890036 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-106-O_F1unPWMXiTlRmmZqQgMQ-1; Tue, 22 Jun 2021 09:19:16 -0400 X-MC-Unique: O_F1unPWMXiTlRmmZqQgMQ-1 Received: by mail-qt1-f198.google.com with SMTP id a5-20020ac84d850000b029024998e61d00so10086996qtw.14 for ; Tue, 22 Jun 2021 06:19:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-language; bh=NhfSq3hKXATJH4a8F7J/AL1y7CeJDgKFsZJsd9KhsN8=; b=KCQLEzHECd6eAtLc8aSL6/iS6aroKSBtR1CG32R6nf34hEJEZsja4xxPmicKwK59xq uAfxbfa548RCFIplWFLYYemsDNMz8TBlwKFWaLT1Lmh6kQnS1plmtTxgFgkt7OEkAhD2 KGY02dY4S1QYK8h+c2Eynpng5oqwU+ht6mJxEPZj0Q/GX1Rnp5v4INa7zYDsFmVhuAEr GS77/YqoipsbJPvFLL4FY5pWul0M4eg3qRBO329OcyQ8dSM8HJfA2ZIjBP3HvzWmQy5p QqXLvrl+o2n4XSS4oUx9+gqQGYFp9iLUZU7MO2PlALIepbSyyPcqhcQC0DGcALH5mj7P FiYA== X-Gm-Message-State: AOAM531j5hxt8HF5+7p42J7qKJgFxpQ7p7cbmurrs44Var9jC1txME98 910mSLzOuxxVggxQrR68CMl6OwxtasTQzKlEsCnh+dyVFIbC31rIDWkYe2S6ZIE3s1BIB3i9sup naAQ1nPpBQ4oVx10mxQ== X-Received: by 2002:a37:7485:: with SMTP id p127mr4214693qkc.323.1624367956270; Tue, 22 Jun 2021 06:19:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNr9CBlpV3jjGiGqfRQk6NKA+1l7qrWMqXiL/5V9cjKxxgBKeZCs/NlW8pJDMqVbMv791yCA== X-Received: by 2002:a37:7485:: with SMTP id p127mr4214679qkc.323.1624367956118; Tue, 22 Jun 2021 06:19:16 -0700 (PDT) Received: from ?IPv6:2607:fea8:a241:4600:84d5:145a:ba5d:a5af? ([2607:fea8:a241:4600:84d5:145a:ba5d:a5af]) by smtp.gmail.com with ESMTPSA id y14sm4146091qkj.8.2021.06.22.06.19.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Jun 2021 06:19:14 -0700 (PDT) To: gcc-patches Subject: [COMMITTED 6/7] Add relation between LHS and op1 for casts and copies. Message-ID: <7a5d73c8-0638-5687-96cb-266cd4a1837b@redhat.com> Date: Tue, 22 Jun 2021 09:19:12 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-CA X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew MacLeod via Gcc-patches From: Andrew MacLeod Reply-To: Andrew MacLeod Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch provides basic relations between the LHS and OP1 for casts and copies. Copies are very straightforward,  LHS == OP1 always. Casts are a little trickier. If the RHS of the copy is of the same or lower precision as the LHS,  then we can consider them EQ_EXPR.  Otherwise, they are considered to have NO relation. There is a comment regarding exactly why this is the case in the implementation of operator_cast::lhs_op1_relation. Bootstraps on x86_64-pc-linux-gnu with no regressions.  Pushed. Andrew From 0f7ccc063a42407f91fa52a54cc480950a45e75c Mon Sep 17 00:00:00 2001 From: Andrew MacLeod Date: Thu, 17 Jun 2021 13:39:02 -0400 Subject: [PATCH 6/7] 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. --- 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, -- 2.17.2