From patchwork Mon Dec 18 19:50:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 180638 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp1491518dyi; Mon, 18 Dec 2023 11:50:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IE27qpzRiV4yPBEQNdV8/TmegBoRJKjSY9opcU9aqOTHfrfVaLZsYdFWzsHZmL8MV6ufK77 X-Received: by 2002:a0d:e812:0:b0:5e4:b85c:565 with SMTP id r18-20020a0de812000000b005e4b85c0565mr4579245ywe.90.1702929045694; Mon, 18 Dec 2023 11:50:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702929045; cv=pass; d=google.com; s=arc-20160816; b=c6p45g9y3FKMOzC5ziPZoWp4r3FXE0ZmIlOch15zWwh8sMSB4mrSXP3d/mX29H+uu1 kpMTRjCQENQQJhsediyQmm4ubttMytObq5d2nwXx6lMuRmZrrnQpYSbe0ofGsiG0nwLY 7ZY01+DaF2P/OWodc7hXvetIsqPQNPS4kieHGsnsGDfYOWJeQsLyfG4a7fxHgfHkopHA XO+ZJaIqIsQcH/+uFKGB7OMUx2VLyNQ2lbUqsMQ1p7F1L+t+P3gJ/uSOSAbHkULp+w7l wd2dswl94ITEHwbA6idl7bpTMCeucjq0qpRztF8aXirHqdWN9+7SerRvosvkGOiEfaxg 1L5Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding:to :subject:from:content-language:cc:user-agent:mime-version:date :message-id:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=7hShGguMYIwj5wn7lo14MM/y3Wj+PHDNRheQxhVyflw=; fh=JWUl0s5pgo0pdO8htbLn5UqYk3AP83fMDotyfKZ0YAs=; b=ucOuGlJ//TLfphTBC+hZa0rwB3P0yvbwd5BUMZ/P1kBgG6zOvn6aTmc/1pQ006S4i7 UkL1KW7YfBaHl6v2EKTApDYG/pmoq0geAHOwx7ZIvwZLAD2gUxt9yawzfB3e7VUNu7qV FuvSoImBbXh84CIu1qH2q8LN0Vg+LrOEVvXf/MQfepKSHtO4Mc9PtxoPltN1Dqgn2eyD H0jgxTXm6iKVlwVnDOm/C7HwBx4i2GbDaIrPnzhUfCPf/CgS/hNzYZ8tpGjKAPAjbd80 ahIpdTkkptUZwBRghFxyRpIzuYEcZ3xu1KrI1mZIVpEpluFhOd6isRNLcf9I2Mt+x26s B78Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Z8XYyz0w; arc=pass (i=1); 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fi3-20020a05622a58c300b004237f64dec8si15910047qtb.528.2023.12.18.11.50.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 11:50:45 -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=@gmail.com header.s=20230601 header.b=Z8XYyz0w; arc=pass (i=1); 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E09E385BADA for ; Mon, 18 Dec 2023 19:50:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 57098385803E for ; Mon, 18 Dec 2023 19:50:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 57098385803E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 57098385803E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::429 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702929015; cv=none; b=SC8hY2Ojp1u6KbJ6Xspn9HN4cHmi/1d0Uu7DFS3cpJJt3ol1DalqPsKO356eeYXWvo2dYecV7p/5EyAYHtTIDt8NuDmSZFzsF7Wh6PhdKYWNUaM3APx0YhlpEM7yl8Ztr/0QdgH6pSPFsUFovMSq26GzQENFqn1kGEuNnLAmZp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702929015; c=relaxed/simple; bh=iBKlp4lYbBwBC1BWMUvtyI8ODk3nJpy60AGVwHMQ7dE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=fez587oJtRqdU0y1VNwjZg/WTLzE9JC5D4JkFexiZbckbyp2nLGDsFaAcZFpTb4SGtPtQHIpChXaNL9APN5Jxxp3E6WWs9iRPw6N0KzGeIC3tSSLlc7PD+heQkLghWN8MJ7J0Dh1AmSVRS8eF4SObkTUVnpRtf8ZKz+78L54Zms= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-3366e78d872so801743f8f.3 for ; Mon, 18 Dec 2023 11:50:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702929011; x=1703533811; darn=gcc.gnu.org; h=content-transfer-encoding:to:subject:from:content-language:cc :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=7hShGguMYIwj5wn7lo14MM/y3Wj+PHDNRheQxhVyflw=; b=Z8XYyz0wSUQzV962Rg69iLQaWFeyZyzcwmj8jakfeooaVD1MNjj4ngq6SQ08oaYNdm xCV9c//+no0ZExD3zdNxvnzeIGdYzzkf2CnhLwfQf6AZOQTxdqDKj0BLA/MYq2VKfMlP ukUu4Dc4h/POvvI5i/FHBLRN/mU6I2APiWY+kWN031cbBr/6VB6Nt+otKxEdJh8JEA1x LZotNe0DKm32iJVN8SFbQcZY0G5cYDzuMIKp8AxhwTBljZKPC3JACKagKD8JEEuftT/1 sv3xB4JAncq3OOXL3UloAFk/ji2iX5r7eVnero8fiwXU8ROvbNOmt132jqflDSBNUZU/ Y8wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702929011; x=1703533811; h=content-transfer-encoding:to:subject:from:content-language:cc :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=7hShGguMYIwj5wn7lo14MM/y3Wj+PHDNRheQxhVyflw=; b=ExOqqoNQU6um3qG/hPrumhMrO9roasQA2DRKw7n9gy988jLJgvNEdosMfQ5TOQMu7B PkHnjWGmJ93m0LmtH8yfqmr1tY9w/mK0f7UlfoQSy4jPJwMBQTx6igr1zApkOwGgQIeo oGUImkrLgL9+58NnPPnebtQm5Ssml8lCz75R12fPxCUjqmXvyD7wgYiKA+WGqanueowI XZvPtmi1Ui0ItBUyLlVjUZUPe0Zs3e9w+QRj9Pa4i2atizWWYDVCllJomiIC6nhfAkCr Dsms1YzyoSs9yJ6/71ZKDEshb7klsXYC0hdaOPiQgCLctRqnatnv+TWDPXD+BwLKsIRY NoJg== X-Gm-Message-State: AOJu0YzVrz3SPYMYjmsYRsbWpWpTfxgOpl+UdCvQ8wKmmfhAkpWebKvN BhKlhVX7Mm6AuzXAzOl2BlRqIAIr7dE= X-Received: by 2002:a5d:4d11:0:b0:336:4450:c901 with SMTP id z17-20020a5d4d11000000b003364450c901mr2129178wrt.74.1702929010972; Mon, 18 Dec 2023 11:50:10 -0800 (PST) Received: from [192.168.1.24] (ip-149-172-150-237.um42.pools.vodafone-ip.de. [149.172.150.237]) by smtp.gmail.com with ESMTPSA id d5-20020a5d5385000000b0033662cf5e51sm5532170wrv.93.2023.12.18.11.50.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Dec 2023 11:50:10 -0800 (PST) Message-ID: Date: Mon, 18 Dec 2023 20:50:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: rdapp.gcc@gmail.com, "Li, Pan2" , "juzhe.zhong@rivai.ai" Content-Language: en-US From: Robin Dapp Subject: [PATCH] fold-const: Handle AND, IOR, XOR with stepped vectors [PR112971]. To: gcc-patches X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785650527147783397 X-GMAIL-MSGID: 1785650527147783397 Hi, found in PR112971, this patch adds folding support for bitwise operations of const duplicate zero vectors and stepped vectors. On riscv we have the situation that a folding would perpetually continue without simplifying because e.g. {0, 0, 0, ...} & {7, 6, 5, ...} would not fold to {0, 0, 0, ...}. Bootstrapped and regtested on x86 and aarch64, regtested on riscv. I won't be available to respond quickly until next year. Pan or Juzhe, as discussed, feel free to continue with possible revisions. Regards Robin gcc/ChangeLog: PR middle-end/112971 * fold-const.cc (const_binop): Handle zerop@1 AND/IOR/XOR VECT_CST_STEPPED_P@2 gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/pr112971.c: New test. --- gcc/fold-const.cc | 14 +++++++++++++- .../gcc.target/riscv/rvv/autovec/pr112971.c | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112971.c diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index f5d68ac323a..43ed097bf5c 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -1653,8 +1653,20 @@ const_binop (enum tree_code code, tree arg1, tree arg2) { tree type = TREE_TYPE (arg1); bool step_ok_p; + + /* AND, IOR as well as XOR with a zerop can be handled directly. */ if (VECTOR_CST_STEPPED_P (arg1) - && VECTOR_CST_STEPPED_P (arg2)) + && VECTOR_CST_DUPLICATE_P (arg2) + && integer_zerop (VECTOR_CST_ELT (arg2, 0))) + step_ok_p = code == BIT_AND_EXPR || code == BIT_IOR_EXPR + || code == BIT_XOR_EXPR; + else if (VECTOR_CST_STEPPED_P (arg2) + && VECTOR_CST_DUPLICATE_P (arg1) + && integer_zerop (VECTOR_CST_ELT (arg1, 0))) + step_ok_p = code == BIT_AND_EXPR || code == BIT_IOR_EXPR + || code == BIT_XOR_EXPR; + else if (VECTOR_CST_STEPPED_P (arg1) + && VECTOR_CST_STEPPED_P (arg2)) /* We can operate directly on the encoding if: a3 - a2 == a2 - a1 && b3 - b2 == b2 - b1 diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112971.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112971.c new file mode 100644 index 00000000000..816ebd3c493 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112971.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvl256b -mabi=lp64d -O3 -fno-vect-cost-model" } */ + +int a; +short b[9]; +char c, d; +void e() { + d = 0; + for (;; d++) { + if (b[d]) + break; + a = 8; + for (; a >= 0; a--) { + char *f = &c; + *f &= d == (a & d); + } + } +}