From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id 802653858D1E for ; Mon, 15 Jan 2024 15:23:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 802653858D1E 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 802653858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::136 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705332216; cv=none; b=qsHF/PFXacK0y8p4zNwHkpuO+fvZNgf8mkQ2V0vaO71XKSofaOSxW4BqH56XbZnk2XIl16N5qwjDOQMI27HrH8/R7HRgf0gJcEInXnBMTgOC1Y3rArT3IFMqGL74yMUY6cD6RcLj55CmsBZj091leDs7qFRdSUX4J/nUyiLG+KE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705332216; c=relaxed/simple; bh=b4hDjgOYR+sNeT/Hdx/NSZpHrhlaZBN1KMgzNkOtKsE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Zst4mF++rfFW21oP9+vfKCzu1s6SVfK+vi6CCz9S/Ul8IJJmUMd6DmQKBNzCuO7I+yD/ky6pBrNXnWR9pzcMaIAscb+CNngrlF3KY7TudAOW1NLMMxrbehjWwYj+tZXCREiS9Y52PlfD53EZxHWk46XUVL5EGT6KhuHuDcTVW0Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-50e7ddd999bso9705214e87.1 for ; Mon, 15 Jan 2024 07:23:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705332213; x=1705937013; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:cc:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=30NTT9Rhp8wWDKp/A7oMP+yMH9Lth9pNZJey28QIeUw=; b=DAsXjKNXm6cRvHyfHzgZilDzm4ZmyO2KaoSDS35DVLXOlUbQiaYwdnVnpPuEbx4nJ5 Buto5CL+2mGFqn62TIXwZorCf9TjAzf4D+adoVUy34L91UcTVEdOqhg2Bv6RsCWp6Rzu HqRL5WGDX3Uae3v36X5ueSDIVDlTZIB0vI52RMRXfIf77Ns9WwKRIx371SXeSQTHY4eL MY3DEpj+JjdIcZAQnEKb/w1kaXzADYqepoIAJ43rewBjCK+ZrF6CfmNJsLMppptN7yHe jBlhtkixPNhIjckaEpkTT0PcVPlf0v2dhg4DDiXpsDfEVADl/sQTCbI2pX70RwH+Ftie 86QQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705332213; x=1705937013; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:cc:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=30NTT9Rhp8wWDKp/A7oMP+yMH9Lth9pNZJey28QIeUw=; b=A3wFAl6SG/UQ9nlh1TYbNXeJPvH80xDOgSZHEfWFPOq1OMt56ghqWXi/QK5i9cMZrg /F9BQW1ls5BYIL68c7jPOStjOH/Np5x8+x9S/rKeb0ZeZDB+k8M0PEc19KwOJkYTxpKE IgGVXFT+HRnX13F4ezp3poZjv5Rcr8EfF7/QxK8wbkxOQlDLpV73WtzcfFUheWWAvc+j nAJqG3XsYfu2P/XYZttC58SVH+qyofqPzk95MG+09bYwScTFcecHELHVFz2y/qyGsYml qiUqofXF9VVIBsVwdjd8Gk0WQuTnxdiZoojA79FzflRWKpoa6Y56J8KhtQtpEuqPFoyd CGOw== X-Gm-Message-State: AOJu0YzttM6/c9QX0o3pqQtvtkczQRDK/Ao0MlEeumPvS2xVnI25AvPg 2F83qnLlUA+dzo29dEWpgOY= X-Google-Smtp-Source: AGHT+IH85qpL8BPljGVUJeQ3VbYMHaJf+Ub2SehFIQshM5ZCXjmXV4ynvcMYWSK8QuuUHyjrNpddSA== X-Received: by 2002:a05:6512:10cd:b0:50e:2bfe:ef43 with SMTP id k13-20020a05651210cd00b0050e2bfeef43mr3110935lfg.115.1705332212630; Mon, 15 Jan 2024 07:23:32 -0800 (PST) Received: from [192.168.1.23] (ip-149-172-150-237.um42.pools.vodafone-ip.de. [149.172.150.237]) by smtp.gmail.com with ESMTPSA id hy7-20020a1709068a6700b00a280944f775sm5378875ejc.153.2024.01.15.07.23.31 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Jan 2024 07:23:32 -0800 (PST) Message-ID: <7b8d117c-c01a-49d4-9f50-c7e2bfa34ba1@gmail.com> Date: Mon, 15 Jan 2024 16:23:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: rdapp.gcc@gmail.com Subject: Re: [PATCH] fold-const: Handle AND, IOR, XOR with stepped vectors [PR112971]. Content-Language: en-US To: Andrew Pinski , Richard Biener , "juzhe.zhong@rivai.ai" , gcc-patches , "pan2.li" , Richard Biener , richard.sandiford@arm.com References: <097AABD6596FB0C3+2023121906491281154423@rivai.ai> <92p02r8p-46rq-s976-5r8p-s87q0q763465@fhfr.qr> <6FD0A43E2F3E9BD9+202312191735136921653@rivai.ai> From: Robin Dapp In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_MANYTO,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 List-Id: I gave it another shot now by introducing a separate function as Richard suggested. It's probably not at the location he intended. The way I read the discussion there hasn't been any consensus on how (or rather where) to properly tackle the problem. Any other ideas still? Regards Robin Found in PR112971 this patch adds folding support for bitwise operations of const duplicate zero/one vectors with 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 be folded to {0, 0, 0, ...}. gcc/ChangeLog: PR middle-end/112971 * fold-const.cc (simplify_const_binop): New function for binop simplification of two constant vectors when element-wise handling is not necessary. (const_binop): Call new function. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/pr112971.c: New test. --- gcc/fold-const.cc | 31 +++++++++++++++++++ .../gcc.target/riscv/rvv/autovec/pr112971.c | 18 +++++++++++ 2 files changed, 49 insertions(+) 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 385e4a69ab3..2ef425aec0f 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -1343,6 +1343,29 @@ distributes_over_addition_p (tree_code op, int opno) } } +/* OP is the INDEXth operand to CODE (counting from zero) and OTHER_OP + is the other operand. Try to use the value of OP to simplify the + operation in one step, without having to process individual elements. */ +static tree +simplify_const_binop (tree_code code, tree op, tree other_op, + int index ATTRIBUTE_UNUSED) +{ + /* AND, IOR as well as XOR with a zerop can be simplified directly. */ + if (TREE_CODE (op) == VECTOR_CST && TREE_CODE (other_op) == VECTOR_CST) + { + if (integer_zerop (other_op)) + { + if (code == BIT_IOR_EXPR || code == BIT_XOR_EXPR) + return op; + else if (code == BIT_AND_EXPR) + return other_op; + } + } + + return NULL_TREE; +} + + /* Combine two constants ARG1 and ARG2 under operation CODE to produce a new constant. We assume ARG1 and ARG2 have the same data type, or at least are the same kind of constant and the same machine mode. Return zero if @@ -1646,6 +1669,14 @@ const_binop (enum tree_code code, tree arg1, tree arg2) return build_complex (type, real, imag); } + tree simplified; + if ((simplified = simplify_const_binop (code, arg1, arg2, 0))) + return simplified; + + if (commutative_tree_code (code) + && (simplified = simplify_const_binop (code, arg2, arg1, 1))) + return simplified; + if (TREE_CODE (arg1) == VECTOR_CST && TREE_CODE (arg2) == VECTOR_CST && known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg1)), 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); + } + } +} -- 2.43.0