From patchwork Thu Oct 22 00:19:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew MacLeod X-Patchwork-Id: 1385835 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org 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=mzXuISmV; 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 4CGp0021Wpz9sTL for ; Thu, 22 Oct 2020 11:19:44 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0BCA03851C24; Thu, 22 Oct 2020 00:19:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BCA03851C24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1603325982; bh=dW8dRhVuxBjOpR3hGnMg36vwp19loMo79COZnmIchhI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=mzXuISmVre+BAcxt2Watx5wss065fc33RR/dth+X5+W7K43ORqKQEg+i76dF9xb51 gNrKmZ3W4Prmwn7yksYGplgkkCSqSzBcIHhwZHXzd/SAH9Baa5vfG9OcF135eeWM3A q6q/L0c/lPbQwAoRkHxe/XGrfYcvI1Cc1BqPqDCo= 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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 707483857019 for ; Thu, 22 Oct 2020 00:19:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 707483857019 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-210-NMxHiTLVOWujPMTBs_hrzA-1; Wed, 21 Oct 2020 20:19:36 -0400 X-MC-Unique: NMxHiTLVOWujPMTBs_hrzA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B78A618A0737 for ; Thu, 22 Oct 2020 00:19:35 +0000 (UTC) Received: from [10.10.118.239] (ovpn-118-239.rdu2.redhat.com [10.10.118.239]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F1996EF44 for ; Thu, 22 Oct 2020 00:19:35 +0000 (UTC) To: gcc-patches Subject: [PATCH] Handle a_2= &b properly in range calculations. Message-ID: Date: Wed, 21 Oct 2020 20:19:34 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-12.8 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_H5, 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@gcc.gnu.org Sender: "Gcc-patches" Pick up the correct type for the RHS of  a_2 = &b. bootstrapped on  x86_64-pc-linux-gnu, no regressions, pushed. Andrew commit 966fdb2e12c0347aa3f9efaf5f4e1cd8237fa024 Author: Andrew MacLeod Date: Wed Oct 21 20:11:16 2020 -0400 Handle a_2= &b properly in range calculations. when processing assignments, we were using the type of b instead of type of &b when computing a range. This was usually filtered out by FRE. turning it off exposed it. gcc/ PR tree-optimization/97520 * gimple-range.cc (range_of_non_trivial_assignment): Handle x = &a by returning a non-zero range. gcc/testsuite/ * gcc.dg/pr97520.c: New. diff --git a/gcc/gimple-range.cc b/gcc/gimple-range.cc index c5520e0700b..267ebad757f 100644 --- a/gcc/gimple-range.cc +++ b/gcc/gimple-range.cc @@ -446,17 +446,31 @@ gimple_ranger::range_of_non_trivial_assignment (irange &r, gimple *stmt) return false; tree base = gimple_range_base_of_assignment (stmt); - if (base && TREE_CODE (base) == MEM_REF - && TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME) + if (base) { - int_range_max range1; - tree ssa = TREE_OPERAND (base, 0); - if (range_of_expr (range1, ssa, stmt)) + if (TREE_CODE (base) == MEM_REF) { - tree type = TREE_TYPE (ssa); - range_operator *op = range_op_handler (POINTER_PLUS_EXPR, type); - int_range<2> offset (TREE_OPERAND (base, 1), TREE_OPERAND (base, 1)); - op->fold_range (r, type, range1, offset); + if (TREE_CODE (TREE_OPERAND (base, 0)) == SSA_NAME) + { + int_range_max range1; + tree ssa = TREE_OPERAND (base, 0); + if (range_of_expr (range1, ssa, stmt)) + { + tree type = TREE_TYPE (ssa); + range_operator *op = range_op_handler (POINTER_PLUS_EXPR, + type); + int_range<2> offset (TREE_OPERAND (base, 1), + TREE_OPERAND (base, 1)); + op->fold_range (r, type, range1, offset); + return true; + } + } + return false; + } + if (gimple_assign_rhs_code (stmt) == ADDR_EXPR) + { + // Handle "= &a" and return non-zero. + r = range_nonzero (TREE_TYPE (gimple_assign_rhs1 (stmt))); return true; } } diff --git a/gcc/testsuite/gcc.dg/pr97520.c b/gcc/testsuite/gcc.dg/pr97520.c new file mode 100644 index 00000000000..9f665959138 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr97520.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-fre" } */ + +char a; +void b() { + char *c[5]; + char *d = &a; + &d; + *(c[4] = d); +} +int main() { return 0; }