From patchwork Mon Jul 12 18:37:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1504160 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=gFj/CC5h; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.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 4GNsvz3bQyz9sRK for ; Tue, 13 Jul 2021 04:38:06 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 135B93894C09 for ; Mon, 12 Jul 2021 18:38:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 135B93894C09 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1626115084; bh=Y7Ck+GUB7pw43ztzaRGH1FoPFZ8NM//u9A3xKoqCNhc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=gFj/CC5h6fagd/ZFeHfbHjLAVe7mbTZAO+AzggtRIpl8Vwa9IB0IQrF72h5BPV174 JrMSWmE/Z3yA7AibscRNUL/b4b+uLLiqdfjLKGsw1UFRYIwcMAfaaE5MA9E8xfIvMZ G+us3+cFYuUrNQ4NqAw4hXBJ0dbFTBjtAQhV25qU= 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 96C37389440E for ; Mon, 12 Jul 2021 18:37:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 96C37389440E Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-266-isXjiFtfOQuCObe8UZemQw-1; Mon, 12 Jul 2021 14:37:35 -0400 X-MC-Unique: isXjiFtfOQuCObe8UZemQw-1 Received: by mail-qt1-f200.google.com with SMTP id t15-20020a05622a180fb029024f88c5e9b0so11852495qtc.17 for ; Mon, 12 Jul 2021 11:37:35 -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=Y7Ck+GUB7pw43ztzaRGH1FoPFZ8NM//u9A3xKoqCNhc=; b=TUczqiEOY3qQHlxxjSgCszhneruAh2zzHG1cGN7YtoTvDpooWg/mL8nOjGaUh4P/zL vsICVTBZC2kplrHffydKLUagE8w8m7f6/vWEikIfjoDjJtO6Uan02cT6LIsw8AiEBS8i N5ja4kfWentU5cFgjypXw5oIWRdNnYvqw8gMLhHWTDOxZRZN+/looqlf9tOtm1MdgRc1 ML4YuiUccyODTvliXJqaI4mlhjMRMg7EYadr130AH1conn7MC4vecihncmUHSOAh4KUP kT7NctkeXtrkXcDVcyYa3NpcCiB0Zo723hj13bnqvCKgWzkWP4o5AulJ/4qjcfwRb0am 2w+g== X-Gm-Message-State: AOAM533mGMuG3EDeMFcwVo2ANE1LIdEHdAn0PTIBpYVfmcsujTfi0MX+ kwl6XeQ05u8+oHhPaZVER9y8nG1K69MUPhLCjigPNA4XEYtnfvX+zLQB9KLOn7tJnQanryGS7zO ZGDtdKpFOqM4O+txm5g== X-Received: by 2002:a0c:c603:: with SMTP id v3mr452504qvi.19.1626115054885; Mon, 12 Jul 2021 11:37:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNnIVdqD6BCdeZcaaWqxCaB+Uq7FJB3vgI8ehAPvN1cNZApxLMFXY/rUXwt3Em0lmCQal/0A== X-Received: by 2002:a0c:c603:: with SMTP id v3mr452495qvi.19.1626115054708; Mon, 12 Jul 2021 11:37:34 -0700 (PDT) Received: from [192.168.0.102] ([104.219.122.163]) by smtp.gmail.com with ESMTPSA id j27sm6671914qkl.76.2021.07.12.11.37.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 Jul 2021 11:37:34 -0700 (PDT) To: gcc-patches Subject: [COMMITTED] tree-optimization/101335 - Do not register a cast as an equivalence. Message-ID: Date: Mon, 12 Jul 2021 14:37:32 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.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.4 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_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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" Registering an equivalence between objects of the same size in a cast can cause other registered relations to be incorrect. Detailed in the PR.  This was an older attempt to solve a problem which has since been resolved by recomputation in the GORI engine. Bootstrapped on  x86_64-pc-linux-gnu with no regressions. Pushed. Andrew commit a1539b797a06e03b08e1f1de28ad0d19a3956616 Author: Andrew MacLeod Date: Mon Jul 12 11:38:17 2021 -0400 Do not register a cast as an equivalence. Registering an equivalence between objects of the same size in a cast can cause other relations to be incorrect. gcc/ PR tree-optimization/101335 * range-op.cc (operator_cast::lhs_op1_relation): Delete. gcc/testsuite/ * gcc.dg/tree-ssa/pr101335.c: New. diff --git a/gcc/range-op.cc b/gcc/range-op.cc index f8e4c6d4e49..08000465fd9 100644 --- a/gcc/range-op.cc +++ b/gcc/range-op.cc @@ -2159,10 +2159,6 @@ 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, @@ -2171,27 +2167,6 @@ 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 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr101335.c b/gcc/testsuite/gcc.dg/tree-ssa/pr101335.c new file mode 100644 index 00000000000..921362c2954 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr101335.c @@ -0,0 +1,17 @@ +/* { dg-do run } */ +/* { dg-options "-O2" } */ + +unsigned a = 0xFFFFFFFF; +int b; +int main() +{ + int c = ~a; + unsigned d = c - 10; + if (d > c) + c = 20; + b = -(c | 0); + if (b > -8) + __builtin_abort (); + return 0; +} +