From patchwork Thu Feb 16 07:29:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 57891 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp159690wrn; Wed, 15 Feb 2023 23:31:34 -0800 (PST) X-Google-Smtp-Source: AK7set+dK+fLuyuXZZFTyf0cWvZhX5pdYiCgAVZDo6PFWVW4kzc0Sz4xp2oGMF+EfqwvVjY0rOkC X-Received: by 2002:a17:906:d978:b0:878:7a0e:5730 with SMTP id rp24-20020a170906d97800b008787a0e5730mr5539577ejb.56.1676532694245; Wed, 15 Feb 2023 23:31:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676532694; cv=none; d=google.com; s=arc-20160816; b=H/9gZeWWpFxyXNGmvhYhJCOWnaUq+UGfK3vHMY4BoUanI3b3ZUALUX0T16qoBlHT2u d4yRQhfq51DdJyWWGsW+SEm8RRcFsbxxSo6L829XZmla/14G0wgA2BpXH6NSlIi5ONdR Pcni/ruiHLbbaFxBVyPHpnc3mf09ZRhNnJw1MuLPVntWfJ/HCCtoGSz1wSn4N22x6es1 GFBfa3OIPQfaBCR9kyYN0vhddKOkQsdVNyPv6tIV88F5XFxlUwvIzHZpbCAaFx32zlWT L3AK/8bURsXT/KRYzrCuyr5T33BZSgijY69HIgUN9YCev8/clOBIeLPPJyO/IzYAJX7M QdWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=mKKryAytpSb0hKjsby2MgBnJPgAiVBiS7nSth+AVb84=; b=B/sNyU432ne45/FVGrDSMSNEPgYWwAafwR9PIwXWT8K5BLqLbtq/ONFka+idMg9ppA 3i/8c78mIW1OlKTvj9FMRdQs9CJIARj8OicrXVW5KWL4xxh6OF1ggNJ6uNrMIRTgT0Xq XIEqCeR0Z1xMiq2aSZtlBI1ceKyCfPFz5x4NleGoupYYV6nOHv0OcenP9rtoYyrHYkWa qqBnui6YDzqnoSb2i8dLBWRxxoT/He/WDNR30k4vsb4HCsVJt+Khi1b8t5dHPp4+gupH W0yzCS6c/z2gqBFp97cy4SYE1YJrGBKS7GJGq/R/PFe7gGUh9z2qRVPnWCmljovQH/K6 wHdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iOwbBFG4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 13-20020a170906028d00b008b13afdbdefsi1498933ejf.822.2023.02.15.23.31.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Feb 2023 23:31:34 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iOwbBFG4; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D6E73858022 for ; Thu, 16 Feb 2023 07:31:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D6E73858022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676532693; bh=mKKryAytpSb0hKjsby2MgBnJPgAiVBiS7nSth+AVb84=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=iOwbBFG4f4VQO+4y7T3NiQPxqQzbXcCOilCTjj8qSR+fw+hRQP/3G06zcFUKWhYci 52XPfzwTc4wDQ/nwjFPXQDUaTFgX5UJCHkwuu3otUFJ447MmTLg1RvlcRW6dZAwthC Gj460qvrmpQNmBWNstnH9xJ2uJOkg2ihy4CJ+tj0= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id DAE233858D33 for ; Thu, 16 Feb 2023 07:29:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DAE233858D33 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 0DF0E200B0 for ; Thu, 16 Feb 2023 07:29:28 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 01D402C142 for ; Thu, 16 Feb 2023 07:29:27 +0000 (UTC) Date: Thu, 16 Feb 2023 07:29:26 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/108791 - checking ICE with sloppy ADDR_EXPR User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230216073133.4D6E73858022@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757971946411394149?= X-GMAIL-MSGID: =?utf-8?q?1757971946411394149?= The following fixes a checking ICE by choosing a more appropriate type for an ADDR_EXPR built by forwprop. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/108791 * tree-ssa-forwprop.cc (optimize_vector_load): Build the ADDR_EXPR of a TARGET_MEM_REF using a more meaningful type. * gcc.dg/torture/pr108791.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr108791.c | 9 +++++++++ gcc/tree-ssa-forwprop.cc | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr108791.c diff --git a/gcc/testsuite/gcc.dg/torture/pr108791.c b/gcc/testsuite/gcc.dg/torture/pr108791.c new file mode 100644 index 00000000000..c1c1cb22aad --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr108791.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ + +int f (int *a(), int *b, int *c, int *d) +{ + int s = 0; + for (int *i = (int *)a; i < b; ++i, ++c) + s += *c * d[*i]; + return s; +} diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc index 0841a739fe1..03fe0a3f6df 100644 --- a/gcc/tree-ssa-forwprop.cc +++ b/gcc/tree-ssa-forwprop.cc @@ -3299,7 +3299,8 @@ optimize_vector_load (gimple_stmt_iterator *gsi) { if (TREE_CODE (TREE_OPERAND (load_rhs, 0)) == ADDR_EXPR) mark_addressable (TREE_OPERAND (TREE_OPERAND (load_rhs, 0), 0)); - tree tem = make_ssa_name (TREE_TYPE (TREE_OPERAND (load_rhs, 0))); + tree ptrtype = build_pointer_type (TREE_TYPE (load_rhs)); + tree tem = make_ssa_name (ptrtype); gimple *new_stmt = gimple_build_assign (tem, build1 (ADDR_EXPR, TREE_TYPE (tem), unshare_expr (load_rhs)));