From patchwork Wed Jan 31 11:49:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1893437 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=M7hPy5mM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TQ0hH3YYHz23g7 for ; Wed, 31 Jan 2024 22:49:50 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 18723385802D for ; Wed, 31 Jan 2024 11:49:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 5C53C3858415 for ; Wed, 31 Jan 2024 11:49:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C53C3858415 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 5C53C3858415 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::631 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706701765; cv=none; b=AQO2mjp+bYIyp0roStWI80UFti6mWP+22t12Ol8BW5jp9CqCTdvxOtwgT4ghvMCSrQdPqk/jlXWGoyp/W9/k035yaeUZnhfFIB4upH4SOsOCiasfv8ooeahvCvCxc5ak/RCyQmmCq1ewES1JYm/PNm+iAIn8Q+IpwuH4h3Yv85M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706701765; c=relaxed/simple; bh=cAm+7/CEEz5w1h+ikdvK2Kk/YhhOOwnv1ZlfVi1gk8w=; h=DKIM-Signature:Message-ID:Date:MIME-Version:From:Subject:To; b=q5nX1RfGfjyZm6AQgrWHrVuqWFPQwLlapKJuYHy580wst6jl3kAIvfIZ9y2rmstcOovof/knJcbkniivieFwFELwSCkmkfJjbq8lRSdxDDFJqdvXViSIvgCtsmfUGkkI/9Uhd0U0qi8oM4GBD/XAJUe0CeZqS61geG6aop6Y8OM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x631.google.com with SMTP id a640c23a62f3a-a36597a3104so121111566b.2 for ; Wed, 31 Jan 2024 03:49:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706701761; x=1707306561; 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=de9ECoYBTr9pcDMgtdIwKa9XouiCcGzKaYFX4tR81o4=; b=M7hPy5mMnsUyBeOUJFXL/Dom/F6bY0GT/iy2hsrzjF7GOyHmvy2ZEC4D9DJYNmsBKG JURnzPHqrd8WAp3W3yjK8AD/P4Mxv23bnXAeCb+kbSjkxGwmMeXQ511hNLff9RB6OB/B N8SoS45G47PexMbiOXFKdhRszH/wxkdsHv5SoHknYZVRZlGBv4lLW+tuUu3zwZqtcMM2 EdXUerZjp1dIWZLmdMJ9n/rX0pUJVpzvOFaVs2CJBuLDKY7KQRE2pwI+LSlnHxnJZCsq i3iRrSx2dDMnO5dcxWwAWWhLXjtFbGlRjG6GqjlJXuZTf+wdt0neGX7qhmk2aWqrkEPz BH8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706701761; x=1707306561; 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=de9ECoYBTr9pcDMgtdIwKa9XouiCcGzKaYFX4tR81o4=; b=Q0t/2DQZl28ylYg2KpAdKyvvDCMVWn6SZ8UTX2xilDQZ+ypERBnM7dDbpXfqg+Tfbd nRFbZzycVucf+fESXl2gY9smWCOKo2AGXIaFF/hy3PqyheXF3DfNXyTGrSn/qBMWnuL7 7TjWJDTXBk7KJKz7kY3x7SeRLYTsAv+k3gl23sR2xzXZbHO0W8tX2J///bT3aYwIDKtv qZnYcu99b5E9Ft8W80I2nnENTXN9CSSqWk3ir5vVOKor9uBE7Aw/o+Okjb+WIRXrDD0N f/PdBk5t17IbtBlcALn1z5zhUOOhUkzuUJfHbhfcKjqD0gFyL/6YNzQVP+3dy9gewUew Rfgw== X-Gm-Message-State: AOJu0YzuRjLs/riw+W+WxNJHKDZEbQt/SZUIC7FUcOAOByXLiGkrE8m7 JrPXz7SZOzfT8e0//S018c0pFkxd8HwkSFZXyLER3C5waAlxoSmGrB4U+G74 X-Google-Smtp-Source: AGHT+IEW2OObVe7kwrdzfl1cjzNMVVdJk88exuOSZt3HJ06tPcQIlXJG7zb/Y88ZLdRxUGEyTo8ZCg== X-Received: by 2002:a17:906:c2c2:b0:a31:3f4f:bea7 with SMTP id ch2-20020a170906c2c200b00a313f4fbea7mr899341ejb.39.1706701761141; Wed, 31 Jan 2024 03:49:21 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCUpo6aDWF69l4rwyYhPrijqTLuoHosb+BnlYKIXYuVFGhXMn2Y9qd0BDr2ETyeLOcVf1bD9HRXrqInz5/zn3z8VCGa5SAs9Bw== 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 rs10-20020a170907036a00b00a316a652c6csm6099832ejb.70.2024.01.31.03.49.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 Jan 2024 03:49:20 -0800 (PST) Message-ID: <8bcdf719-97ac-4a7c-bcd9-f04d28c345a0@gmail.com> Date: Wed, 31 Jan 2024 12:49:20 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: rdapp.gcc@gmail.com, Tamar Christina Content-Language: en-US From: Robin Dapp Subject: [PATCH] match: Fix vcond into conditional op folding [PR113607]. To: gcc-patches X-Spam-Status: No, score=-8.9 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, WEIRD_PORT 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, in PR113607 we see an invalid fold of _429 = .COND_SHL (mask_patt_205.47_276, vect_cst__262, vect_cst__262, { 0, ... }); vect_prephitmp_129.51_282 = _429; vect_iftmp.55_287 = VEC_COND_EXPR ; to Applying pattern match.pd:9607, gimple-match-10.cc:3817 gimple_simplified to vect_iftmp.55_287 = .COND_SHL (mask_patt_205.47_276, vect_cst__262, vect_cst__262, { 0, ... }); where we essentially use COND_SHL's else instead of VEC_COND_EXPR's. This patch adjusts the corresponding match.pd pattern and makes it only match when the else values are the same. That, however, causes the exact test case to fail which this pattern was introduced for. XFAIL it for now. Bootstrapped and regtested on x86. Regtested on riscv. aarch64 is still running. Regards Robin gcc/ChangeLog: PR middle-end/113607 * match.pd: Make sure else values match when folding a vec_cond into a conditional operation. gcc/testsuite/ChangeLog: * gcc.target/aarch64/sve/pre_cond_share_1.c: XFAIL. * gcc.target/riscv/rvv/autovec/pr113607-run.c: New test. * gcc.target/riscv/rvv/autovec/pr113607.c: New test. --- gcc/match.pd | 8 +-- .../gcc.target/aarch64/sve/pre_cond_share_1.c | 2 +- .../riscv/rvv/autovec/pr113607-run.c | 4 ++ .../gcc.target/riscv/rvv/autovec/pr113607.c | 49 +++++++++++++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr113607-run.c create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr113607.c diff --git a/gcc/match.pd b/gcc/match.pd index e42ecaf9ec7..7c391a8fe20 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -9592,18 +9592,18 @@ and, /* Detect simplification for vector condition folding where - c = mask1 ? (masked_op mask2 a b) : b + c = mask1 ? (masked_op mask2 a b els) : els into - c = masked_op (mask1 & mask2) a b + c = masked_op (mask1 & mask2) a b els where the operation can be partially applied to one operand. */ (for cond_op (COND_BINARY) (simplify (vec_cond @0 - (cond_op:s @1 @2 @3 @4) @3) + (cond_op:s @1 @2 @3 @4) @4) (cond_op (bit_and @1 @0) @2 @3 @4))) /* And same for ternary expressions. */ @@ -9611,7 +9611,7 @@ and, (for cond_op (COND_TERNARY) (simplify (vec_cond @0 - (cond_op:s @1 @2 @3 @4 @5) @4) + (cond_op:s @1 @2 @3 @4 @5) @5) (cond_op (bit_and @1 @0) @2 @3 @4 @5))) /* For pointers @0 and @2 and nonnegative constant offset @1, look for diff --git a/gcc/testsuite/gcc.target/aarch64/sve/pre_cond_share_1.c b/gcc/testsuite/gcc.target/aarch64/sve/pre_cond_share_1.c index b51d0f298ea..e4f754d739c 100644 --- a/gcc/testsuite/gcc.target/aarch64/sve/pre_cond_share_1.c +++ b/gcc/testsuite/gcc.target/aarch64/sve/pre_cond_share_1.c @@ -129,4 +129,4 @@ fasten_main(size_t group, size_t ntypes, size_t nposes, size_t natlig, size_t na } /* { dg-final { scan-tree-dump-times {\.COND_MUL} 1 "optimized" } } */ -/* { dg-final { scan-tree-dump-times {\.VCOND} 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-times {\.VCOND} 1 "optimized" { xfail *-*-* } } } */ diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr113607-run.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr113607-run.c new file mode 100644 index 00000000000..06074767ce5 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr113607-run.c @@ -0,0 +1,4 @@ +/* { dg-do run { target { riscv_v && rv64 } } } */ +/* { dg-options "-O3 -march=rv64gcv -mabi=lp64d -fdump-tree-optimized" } */ + +#include "pr113607.c" diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr113607.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr113607.c new file mode 100644 index 00000000000..70a93665497 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr113607.c @@ -0,0 +1,49 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -march=rv64gcv -mabi=lp64d -fdump-tree-optimized" } */ + +struct { + signed b; +} c, d = {6}; + +short e, f; +int g[1000]; +signed char h; +int i, j; +long k, l; + +long m(long n, long o) { + if (n < 1 && o == 0) + return 0; + return n; +} + +static int p() { + long q = 0; + int a = 0; + for (; e < 2; e += 1) + g[e * 7 + 1] = -1; + for (; h < 1; h += 1) { + k = g[8] || f; + l = m(g[f * 7 + 1], k); + a = l; + j = a < 0 || g[f * 7 + 1] < 0 || g[f * 7 + 1] >= 32 ? a : a << g[f * 7 + 1]; + if (j) + ++q; + } + if (q) + c = d; + return i; +} + +int main() { + p(); + if (c.b != 6) + __builtin_abort (); +} + +/* We must not fold VEC_COND_EXPR into COND_SHL. + Therefore, make sure that we still have 2/4 VCOND_MASKs with real else + value. */ + +/* { dg-final { scan-tree-dump-times { = \.VCOND_MASK.\([a-z0-9\._]+, [a-z0-9\._\{\}, ]+, [0-9\.\{\},]+\);} 0 "optimized" } } */ +/* { dg-final { scan-tree-dump-times { = \.VCOND_MASK.\([a-z0-9\._]+, [a-z0-9\._\{\}, ]+, [a-z0-9\._]+\);} 4 "optimized" } } */