From patchwork Fri Apr 21 20:34:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1772115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=oS9UIY92; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Q35qz0M4hz23rW for ; Sat, 22 Apr 2023 06:35:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E702385701A for ; Fri, 21 Apr 2023 20:35:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E702385701A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682109308; bh=uEVW30JJZq0pzzoNyjZG231r24O4QOV506zE/GFFZ7w=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=oS9UIY92U/80K7ITdofkIR/nq/8oQvKaM5LXHgkZldHz4ODA28ZDGveA8ngKMoiR9 UsAxBk4GhOa46jcM0J49P6YOMzjulqkZtcitQgB+4eqYy0eePaXhvUF/pGnk1tOLfH 6r6t1xSsxb47a6haOmsg7EEt3vW8rDLZRJwuwNS4= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 7D7B33857351 for ; Fri, 21 Apr 2023 20:34:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7D7B33857351 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-343-srBb3W-6PTuQMzwNRwchaw-1; Fri, 21 Apr 2023 16:34:46 -0400 X-MC-Unique: srBb3W-6PTuQMzwNRwchaw-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-5efc80e8485so32733076d6.0 for ; Fri, 21 Apr 2023 13:34:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682109285; x=1684701285; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=j1teLe8UUkyQxgH3ugu4t3Nqp1XD+olWRIZA5VQkbik=; b=UPrpQggz18hMLOi0e5g//GVt3IHsnRUn2gAwwOOxKUx0pSvFiYmcOsi33Kz4Sza3lH DSkwBfoZUGKaUXcZyezOi6Ev8N9fa19t73bUpZe9Kq926Kjhib0K+OV8TIjICLHFzdUh O+pImzbSw6SHcTMqz6IUsJxr1nGOYWt5OOPb5SJLYNvei2RdIjtYHZ8ZwWYnqz+wf3nX lqiG8O6NAVnrWIbzfiZIFiXCaeT4ABj1tFz73Ln2wTaqDfJf9Om+p/pkvQBpNRLNNGiF 6qpJ3q3yoalYyosCL3vER+mlAtaPkmi3QhdNK6GJnVOqvUlgkmSREwHPTI1AroYmTeOw BIcA== X-Gm-Message-State: AAQBX9dlF7YdQe3K67qA4+iD3f2T5E9s7Etmi9ubfNUNbnAJQohk1t6n g8/ju3PEkkCkqWNWF/xjzv3oh03ZEEL/9uzsUpwvzvWY0hONxYOCDfaD2QZ2zdurjbniMH4Diae LKdPfItJxSMSEvg+ccW0HNr7hGcelfg0dW2LTVYRZ5vp6gk4V3ImS++WOfr2cOxt78YbAgLeSgW qYPA== X-Received: by 2002:a05:6214:2aad:b0:5e6:3da1:70fd with SMTP id js13-20020a0562142aad00b005e63da170fdmr9803800qvb.25.1682109285361; Fri, 21 Apr 2023 13:34:45 -0700 (PDT) X-Google-Smtp-Source: AKy350a7e3NmSugEA6wLItxVixsIJTwn7PsMRlQ6fULbiYq0FSYQsans8ErutnUaRRQJq2xPpNEIuw== X-Received: by 2002:a05:6214:2aad:b0:5e6:3da1:70fd with SMTP id js13-20020a0562142aad00b005e63da170fdmr9803777qvb.25.1682109285001; Fri, 21 Apr 2023 13:34:45 -0700 (PDT) Received: from ?IPV6:2607:fea8:51dd:1100::345b? ([2607:fea8:51dd:1100::345b]) by smtp.gmail.com with ESMTPSA id f23-20020a0caa97000000b005dd8b9345absm1404912qvb.67.2023.04.21.13.34.44 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 Apr 2023 13:34:44 -0700 (PDT) Message-ID: <5da330c4-2918-10df-b315-17307067d2bf@redhat.com> Date: Fri, 21 Apr 2023 16:34:43 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 To: gcc-patches Subject: [COMMITTED] PR tree-optimization/109546 - Do not fold ADDR_EXPR conditions leading to builtin_unreachable early. X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.3 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_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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" We cant represent ADDR_EXPR in ranges, so when we are processing builtin_unreachable() we should not be removing comparisons that utilize ADDR_EXPR during the early phases, or we lose some important information. It was just an oversight that we think its a comparison to a representable constant. Bootstrapped on x86_64-pc-linux-gnu with no regressions.  pushed. This would also be suitable for the next GCC13 release when the branch is open. Andrew commit 0afefd11e25a05dd4f8a8624e8fb046d9c85686a Author: Andrew MacLeod Date: Fri Apr 21 15:03:43 2023 -0400 Do not fold ADDR_EXPR conditions leading to builtin_unreachable early. Ranges can not represent &var globally yet, so we cannot fold these expressions early or we lose the __builtin_unreachable information. PR tree-optimization/109546 gcc/ * tree-vrp.cc (remove_unreachable::remove_and_update_globals): Do not fold conditions with ADDR_EXPR early. gcc/testsuite/ * gcc.dg/pr109546.c: New. diff --git a/gcc/testsuite/gcc.dg/pr109546.c b/gcc/testsuite/gcc.dg/pr109546.c new file mode 100644 index 00000000000..ba8af0f31fa --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr109546.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-optimized" } */ + +void foo(void); +static int a, c; +static int *b = &a; +static int **d = &b; +void assert_fail() __attribute__((__noreturn__)); +int main() { + int *e = *d; + if (e == &a || e == &c); + else { + __builtin_unreachable(); + assert_fail(); + } + if (e == &a || e == &c); + else + foo(); +} + +/* { dg-final { scan-tree-dump-not "assert_fail" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "foo" "optimized" } } */ + + diff --git a/gcc/tree-vrp.cc b/gcc/tree-vrp.cc index f4d484526c7..9b870640e23 100644 --- a/gcc/tree-vrp.cc +++ b/gcc/tree-vrp.cc @@ -150,7 +150,9 @@ remove_unreachable::remove_and_update_globals (bool final_p) // If this is already a constant condition, don't look either if (!lhs_p && !rhs_p) continue; - + // Do not remove addresses early. ie if (x == &y) + if (!final_p && lhs_p && TREE_CODE (gimple_cond_rhs (s)) == ADDR_EXPR) + continue; bool dominate_exit_p = true; FOR_EACH_GORI_EXPORT_NAME (m_ranger.gori (), e->src, name) {