From patchwork Tue Jul 4 07:06:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 115584 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp1026357vqx; Tue, 4 Jul 2023 00:07:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlHXyB5or0/XvhD2fvXLyj9raNrWSmLcqEfQoiUam9LQFAt52EIBJq+6nH0Z8Ud90uM4XFWl X-Received: by 2002:a17:907:212e:b0:990:8807:8f86 with SMTP id qo14-20020a170907212e00b0099088078f86mr9182610ejb.38.1688454449605; Tue, 04 Jul 2023 00:07:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688454449; cv=none; d=google.com; s=arc-20160816; b=ewbIQqcS9FTvMflCdnU6awECvG/OWc+sfQRKVkYtjGvAlSHOTLZIoPC8+b1jgnNYcw UvuvK/9a74RO1ULwf/hR79If0yrnMogiC5lP7Uhwwan2+BsgnKlSCB77IKaAjSeqWscI 2vBhABpxFALvrtOSZSTq4iELVD0uypoPlV9PkRRUH1FkQr9kphf+IsQpyqt3Lqjy9v9C oByWCS3xmab1y4bpETYYEHGIB/e1KgjqbR01hf0vGqc5j+rP5HZUl230bfN3N4ia7sk/ wzCLAJpEPMiuhN2os79X2aiPaI2WL/nm3lEJ92r8ZnWCdQRFP0/LqFJCZknfHtHkT3s+ dn4g== 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=iW0tf0XS+zIKCPCoLT900XtogPGOaNyBv5O3Z3zARNQ=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=baukUWLc7hcS5rAQ/whUWXgXlvSy97k7UAZFoXjux0gN0U9Ozsb0ejzwcpxtdHzjXM tAt6L2swTofXZhpZT8t7evJYcW5cBGR4CsLSukoFRhqCPHhZ/c7qLdo+g7cEykid9qAs tooKkY6TZ/BI0A+BKAZ9SKsxYXtA2bqnw2kCVrk/U69S5PLSjV0jPA+y3xDKE3UZm47T AllDTSqBR7oX42fFh16Yx4s81fvYI+nCb+xuJ+j0XQsnoJ7Luhso7a5EtexiCfEHDju2 7NomQw6YB07MmtmWfLF8PQQLJEIaIZ5IzBJrgxt/yIC/nnj5Uohmhd+WgVZUK/vC+Lf8 W5Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=M1qHPIin; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i1-20020a17090639c100b009931f44c716si3726118eje.219.2023.07.04.00.07.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jul 2023 00:07:29 -0700 (PDT) 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=M1qHPIin; 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 82C0D3858409 for ; Tue, 4 Jul 2023 07:07:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82C0D3858409 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688454448; bh=iW0tf0XS+zIKCPCoLT900XtogPGOaNyBv5O3Z3zARNQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=M1qHPIin34CZGg6TWSIndhzBD5aMBCH1UORWIYj99Fcbd5TK4B6kCjr848T/orppT QGs/0haA5PMNz+rj8LZI0ic6V1F3svi+IIiEZJdRaUreGCmVEF6LkGaV/2zKgyfXPv Uq6766zl6kcxxd98eDF/XCtuwxXsK8hXo65V1xhA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id 1066B3858D35 for ; Tue, 4 Jul 2023 07:06:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1066B3858D35 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 40EF1224D4 for ; Tue, 4 Jul 2023 07:06:44 +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 2BAA92C141 for ; Tue, 4 Jul 2023 07:06:44 +0000 (UTC) Date: Tue, 4 Jul 2023 07:06:44 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH][v2] middle-end/110495 - avoid associating constants with (VL) vectors User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 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, 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: 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: <20230704070728.82C0D3858409@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770472812972892493?= X-GMAIL-MSGID: =?utf-8?q?1770472812972892493?= When trying to associate (v + INT_MAX) + INT_MAX we are using the TREE_OVERFLOW bit to check for correctness. That isn't working for VECTOR_CSTs and it can't in general when one considers VL vectors. It looks like it should work for COMPLEX_CSTs but I didn't try to single out _Complex int in this change. The following makes sure that for vectors we use the fallback of using unsigned arithmetic when associating the above to v + (INT_MAX + INT_MAX). Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR middle-end/110495 * tree.h (TREE_OVERFLOW): Do not mention VECTOR_CSTs since we do not set TREE_OVERFLOW on those since the introduction of VL vectors. * match.pd (x +- CST +- CST): For VECTOR_CST do not look at TREE_OVERFLOW to determine validity of association. * gcc.dg/tree-ssa/addadd-2.c: Amend. * gcc.dg/tree-ssa/forwprop-27.c: Adjust. --- gcc/match.pd | 28 +++++++++++---------- gcc/testsuite/gcc.dg/tree-ssa/addadd-2.c | 1 + gcc/testsuite/gcc.dg/tree-ssa/forwprop-27.c | 4 ++- gcc/tree.h | 2 +- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index f09583bbcac..861b7dfcddd 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3025,19 +3025,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (with { tree cst = const_binop (outer_op == inner_op ? PLUS_EXPR : MINUS_EXPR, type, @1, @2); } - (if (cst && !TREE_OVERFLOW (cst)) - (inner_op @0 { cst; } ) - /* X+INT_MAX+1 is X-INT_MIN. */ - (if (INTEGRAL_TYPE_P (type) && cst - && wi::to_wide (cst) == wi::min_value (type)) - (neg_inner_op @0 { wide_int_to_tree (type, wi::to_wide (cst)); }) - /* Last resort, use some unsigned type. */ - (with { tree utype = unsigned_type_for (type); } - (if (utype) - (view_convert (inner_op - (view_convert:utype @0) - (view_convert:utype - { drop_tree_overflow (cst); })))))))))))))) + (if (cst) + (if (INTEGRAL_TYPE_P (type) && !TREE_OVERFLOW (cst)) + (inner_op @0 { cst; } ) + /* X+INT_MAX+1 is X-INT_MIN. */ + (if (INTEGRAL_TYPE_P (type) + && wi::to_wide (cst) == wi::min_value (type)) + (neg_inner_op @0 { wide_int_to_tree (type, wi::to_wide (cst)); }) + /* Last resort, use some unsigned type. */ + (with { tree utype = unsigned_type_for (type); } + (if (utype) + (view_convert (inner_op + (view_convert:utype @0) + (view_convert:utype + { TREE_OVERFLOW (cst) + ? drop_tree_overflow (cst) : cst; }))))))))))))))) /* (CST1 - A) +- CST2 -> CST3 - A */ (for outer_op (plus minus) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/addadd-2.c b/gcc/testsuite/gcc.dg/tree-ssa/addadd-2.c index 39aa032c9b1..8c05911f473 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/addadd-2.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/addadd-2.c @@ -12,4 +12,5 @@ void k(S*x){ *x = (S)(y + __INT_MAX__); } +/* { dg-final { scan-tree-dump "4294967294" "optimized" { target int32plus } } } */ /* { dg-final { scan-tree-dump-not "2147483647" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-27.c b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-27.c index 9775a4c6367..6c71a4fc81c 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/forwprop-27.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/forwprop-27.c @@ -33,7 +33,9 @@ void i (V *v1, V *v2){ *v2 = (c1-*v2)+c2; } -/* { dg-final { scan-tree-dump-not "\\\+" "forwprop1"} } */ +/* { dg-final { scan-tree-dump-times "\\\+" 1 "forwprop1"} } */ /* { dg-final { scan-tree-dump "{ 0, 4 }" "forwprop1"} } */ /* { dg-final { scan-tree-dump "{ 37, -5 }" "forwprop1"} } */ +/* { dg-final { scan-tree-dump "{ 27, 23 }" "forwprop1"} } */ +/* { dg-final { scan-tree-dump "{ 37, 3 }" "forwprop1"} } */ diff --git a/gcc/tree.h b/gcc/tree.h index f11c758afb9..bedbbb0bcc0 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -824,7 +824,7 @@ extern void omp_clause_range_check_failed (const_tree, const char *, int, #define TYPE_REF_CAN_ALIAS_ALL(NODE) \ (PTR_OR_REF_CHECK (NODE)->base.static_flag) -/* In an INTEGER_CST, REAL_CST, COMPLEX_CST, or VECTOR_CST, this means +/* In an INTEGER_CST, REAL_CST, or COMPLEX_CST, this means there was an overflow in folding. */ #define TREE_OVERFLOW(NODE) (CST_CHECK (NODE)->base.public_flag)