From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id 6DD3F3858D38 for ; Mon, 11 Sep 2023 20:35:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6DD3F3858D38 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-52c9be5e6f0so5879581a12.1 for ; Mon, 11 Sep 2023 13:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694464521; x=1695069321; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:cc:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=ns4eAsK8vCxdJ6piKeXo7Eczkd63zKGDzuB8/HQVZ7k=; b=XCpNQiz7pCyGieLw0K59UIavWwMxizpcdkKyv+5mZXddzVd48M44gHKKslfMUoIrET 2zEMvc5LGb/yc3r7i3uSpKRSdNv1qYQ9urowLOxQFFNVxXCrvM4dIY52Y0yIrrJuqCjk HW67G6iJBOMAZKFTtgbG3nOBf4kVhkOrGf9X59uWMMUXKeeQcPgGnqy0NJL6NSc0Gadm G2D9Osh4tVBRWUEh9NmfjH8be8EAU7jbh2Pm5I/tSkMjTnU0KGQ9Ryre8ODLIhOvs+8b LPEefBpGdTWclDO8gCvHi3Upnw0RV00h+D+9Zz2oGEy+NcWDC2jiC4D6awcFeyqXcscH VV5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694464521; x=1695069321; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:cc:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ns4eAsK8vCxdJ6piKeXo7Eczkd63zKGDzuB8/HQVZ7k=; b=CLt96y49h3f5E7WlX+EssTJj0wHd+wrtiofEmFhbupDqmKvoMrWiwdFsbxvsLVgExU EaditKzuuLctePPPtlGd1FY0lhMZ9l0uP6dscidmestycsKQrlsxWDbMysYlLkDArN5j LtWCIj+s899k+FwA9usWIKh9L1C1aybndvtwvPraF+fAjieP8VYuR8vm12FeMHQSRc7m 0SYfp95qZOWCG7Q0kjiyix7jjy4/SE/fA3IEszRjpTQ5s+Kjikv+lYgMPzJmGZIQuk7r qd+rcnKlvOhd3q5JEkjp5nf6F9ZPw6TjMFkQlAFBpgHKspJ3UNWCNOlwB4S9TW1IjS0c A2aQ== X-Gm-Message-State: AOJu0YyCCG4PY+39QvYjuBhZ8FGz5pgCG+23SeTvbneRZzivRIcE8UKE vB1B5A1DQwGP6gF1qyEOsJECXsbqGVsv/w== X-Google-Smtp-Source: AGHT+IGsss0OPXKSyPTrS0spMJWSRPFin71nlVk4ud33WxFjqsF3pMrmhIlu4TSFEhVCE+f8EIq1OA== X-Received: by 2002:a17:906:d9:b0:9a1:ecb5:732e with SMTP id 25-20020a17090600d900b009a1ecb5732emr10211603eji.71.1694464520588; Mon, 11 Sep 2023 13:35:20 -0700 (PDT) Received: from [192.168.1.24] (ip-046-005-130-086.um12.pools.vodafone-ip.de. [46.5.130.86]) by smtp.gmail.com with ESMTPSA id v14-20020a170906338e00b00992b1c93279sm5779438eja.110.2023.09.11.13.35.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Sep 2023 13:35:20 -0700 (PDT) Message-ID: <4afb967d-96ea-7e74-1a35-c86aa5a5ffa6@gmail.com> Date: Mon, 11 Sep 2023 22:35:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cc: rdapp.gcc@gmail.com, "richard.sandiford" Subject: Re: [PATCH] gimple-match: Do not try UNCOND optimization with COND_LEN. To: gcc-patches References: <4b77e155-0936-67d6-ab2d-ae7ef49bfde0@gmail.com> Content-Language: en-US From: Robin Dapp In-Reply-To: <4b77e155-0936-67d6-ab2d-ae7ef49bfde0@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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 List-Id: Hi, as Juzhe noticed in gcc.dg/pr92301.c there was still something missing in the last patch. The attached v2 makes sure we always have a COND_LEN operation before returning true and initializes len and bias even if they are unused. Bootstrapped and regtested on aarch64 and x86. Regards Robin Subject: [PATCH v2] gimple-match: Do not try UNCOND optimization with COND_LEN. On riscv we mis-optimize conditional (length) operations into unconditional operations e.g. in slp-reduc-7.c and gcc.dg/pr92301.c. This patch prevents optimizing e.g. COND_LEN_ADD ({-1, ... }, a, 0, c, len, bias) unconditionally into just "a". Currently, we assume that COND_LEN operations can be optimized similarly to COND operations. As the length is part of the mask (and usually not compile-time constant), we must not perform any optimization that relies on just the mask being "true". This patch ensures that we still have a COND_LEN pattern after optimization. gcc/ChangeLog: PR target/111311 * gimple-match-exports.cc (maybe_resimplify_conditional_op): Check for length masking. (try_conditional_simplification): Check that the result is still length masked. --- gcc/gimple-match-exports.cc | 38 ++++++++++++++++++++++++++++++------- gcc/gimple-match.h | 3 ++- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/gcc/gimple-match-exports.cc b/gcc/gimple-match-exports.cc index b36027b0bad..d41de98a3d3 100644 --- a/gcc/gimple-match-exports.cc +++ b/gcc/gimple-match-exports.cc @@ -262,7 +262,8 @@ maybe_resimplify_conditional_op (gimple_seq *seq, gimple_match_op *res_op, if (!res_op->cond.cond) return false; - if (!res_op->cond.else_value + if (!res_op->cond.len + && !res_op->cond.else_value && res_op->code.is_tree_code ()) { /* The "else" value doesn't matter. If the "then" value is a @@ -301,9 +302,12 @@ maybe_resimplify_conditional_op (gimple_seq *seq, gimple_match_op *res_op, /* If the "then" value is a gimple value and the "else" value matters, create a VEC_COND_EXPR between them, then see if it can be further - simplified. */ + simplified. + Don't do this if we have a COND_LEN_ as that would make us lose the + length masking. */ gimple_match_op new_op; - if (res_op->cond.else_value + if (!res_op->cond.len + && res_op->cond.else_value && VECTOR_TYPE_P (res_op->type) && gimple_simplified_result_is_gimple_val (res_op)) { @@ -314,7 +318,7 @@ maybe_resimplify_conditional_op (gimple_seq *seq, gimple_match_op *res_op, return gimple_resimplify3 (seq, res_op, valueize); } - /* Otherwise try rewriting the operation as an IFN_COND_* call. + /* Otherwise try rewriting the operation as an IFN_COND_(LEN_)* call. Again, this isn't a simplification in itself, since it's what RES_OP already described. */ if (convert_conditional_op (res_op, &new_op)) @@ -386,9 +390,29 @@ try_conditional_simplification (internal_fn ifn, gimple_match_op *res_op, default: gcc_unreachable (); } - *res_op = cond_op; - maybe_resimplify_conditional_op (seq, res_op, valueize); - return true; + + if (len) + { + /* If we had a COND_LEN before we need to ensure that it stays that + way. */ + gimple_match_op old_op = *res_op; + *res_op = cond_op; + maybe_resimplify_conditional_op (seq, res_op, valueize); + + auto cfn = combined_fn (res_op->code); + if (internal_fn_p (cfn) + && internal_fn_len_index (as_internal_fn (cfn)) != -1) + return true; + + *res_op = old_op; + return false; + } + else + { + *res_op = cond_op; + maybe_resimplify_conditional_op (seq, res_op, valueize); + return true; + } } /* Helper for the autogenerated code, valueize OP. */ diff --git a/gcc/gimple-match.h b/gcc/gimple-match.h index bec3ff42e3e..d192b7dae3e 100644 --- a/gcc/gimple-match.h +++ b/gcc/gimple-match.h @@ -56,7 +56,8 @@ public: inline gimple_match_cond::gimple_match_cond (tree cond_in, tree else_value_in) - : cond (cond_in), else_value (else_value_in) + : cond (cond_in), else_value (else_value_in), len (NULL_TREE), + bias (NULL_TREE) { } -- 2.41.0