From patchwork Tue Nov 21 14:44:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 1866877 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=kiZ4TJC6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4SZRx344d5z1yRq for ; Wed, 22 Nov 2023 01:44:55 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4F1433858D3C for ; Tue, 21 Nov 2023 14:44:52 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 4670C3858D35 for ; Tue, 21 Nov 2023 14:44:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4670C3858D35 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 4670C3858D35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::529 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700577879; cv=none; b=V0FKX0/vkvU1CBGvTm5+R6T3ylv/ktGIZytCEcayNTltQfxiO4vXCn4OAzdYY9u9ewtrSopHaeDCoj9uhmBDa+qh9Tf0IODMLWh/GSnnbPCL8W1m6CWDEqkoeByNGWHiegProk0T28ymK9orHf98nNFtEHuVMX+k/FRjx/BonYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700577879; c=relaxed/simple; bh=tJ7C5SWmp7vfBE86L++C6FP5F70OPZFElFvLURoXarU=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=fB85g3NIUtAmjLwVuJXzNYnW7d3ZNfcS/VMD8/RnO2hPXSSGXc4lZg5NleN6y+bTx1uaX9KJqDn04YpX1oCB+WVsYTCNtDctv5NV4ZMxkKadzfnwEJwa9iOHmUom6RRGjf36LTbF2doGgdMiJM3B6YHW1CDtwMnYCo6DQCFUv0Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-543923af573so8241459a12.0 for ; Tue, 21 Nov 2023 06:44:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700577876; x=1701182676; darn=gcc.gnu.org; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=g0wa4BNmE2NubhlRoVHvI3Vsk0ZdOERCynLnZ2fLjqM=; b=kiZ4TJC6ga5uc0YB84kLDyKbxnrRziBdCzbca98xcbViWYIP1mKLyJ2LRVyaxb1PsG BUtOSTKi0rLIlMvPNK7Rtr2TX9yIDqexdQ3+MsdvimjPVeSS85qyRVj3uKrihxZyZVhz DiF3a0o1+OPeLKmwAJ9Q5yQBkbx2KITNObh/O41yUVCt4Vu8VLeE+tyzSPK08/7MusV9 Mm7OP2KyqaVSu52Qy9Q0qim5NOnVlLyiO0pRDN50U536zTVfKMeQu7OPf2U08uwOiQq9 T4veP0Q9qPi4oMo8nd0jX5OZ6nwStNP8wLx3ebf6LrMWpqdLrfxv8L086VSXFFrnhICi KoYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700577876; x=1701182676; h=content-transfer-encoding:subject:from:to:content-language:cc :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=g0wa4BNmE2NubhlRoVHvI3Vsk0ZdOERCynLnZ2fLjqM=; b=ve/nrK1At1X/jfTeMlO6MX6gw9N12ei+YnSNZLT1V/o0/muACFC3Dizp13jXQ9xNRM vQpwYrILXnJzmJJrs+QrzirqqG9tEQNOBszuztAj5kcZ2ZiZC1rOYancr8IETyvUfbXs c8tWRKKF7MuUiufCAHTl03CfyzvNyFG5QnNHd4Y8532a50LZ48g/bvLzAqDM61voF+tG 1WKTgzDpf3xsiA1lJnlIPrKqk0AuWrWFyagSSeeIv4mJCHZ8ITzW/zyFd6+1xf4kD2UW 8BGV5wDkLC0+75/ORSkTFEFHgk/4ixLl+9eLitXh3o36SUyWyboFUjfKAiElqTgGSZnQ j2TQ== X-Gm-Message-State: AOJu0YzQvYfaG8a5YMUuovT5z4IjyQPAGWv8VY+lptjlQP/Uhq6QDhnh 5VGMOfTDn4M7Enb3X6QelcMd3fkA/3E= X-Google-Smtp-Source: AGHT+IEQzsb5ro85s73kAB4w5jMt7oOkB9JOm730SiS3hGiDHJ7OVRf9VSrfcGjhhTGE/65m/HNpQg== X-Received: by 2002:a17:906:bf42:b0:9ad:a59f:331a with SMTP id ps2-20020a170906bf4200b009ada59f331amr9736178ejb.57.1700577875878; Tue, 21 Nov 2023 06:44:35 -0800 (PST) Received: from [192.168.1.23] (ip-046-223-203-173.um13.pools.vodafone-ip.de. [46.223.203.173]) by smtp.gmail.com with ESMTPSA id u2-20020a17090657c200b009fd77d78f7fsm2887299ejr.116.2023.11.21.06.44.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Nov 2023 06:44:35 -0800 (PST) Message-ID: <3dc56d83-69f9-48db-a062-4e399d9c419c@gmail.com> Date: Tue, 21 Nov 2023 15:44:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: rdapp.gcc@gmail.com, Tamar Christina Content-Language: en-US To: gcc-patches , Richard Biener From: Robin Dapp Subject: [PATCH] vect: Allow reduc_index != 1 for COND_OPs. X-Spam-Status: No, score=-9.3 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, in PR112406 Tamar found another problem with COND_OP reductions. I wrongly assumed that the reduction variable will always remain in operand 1, just as we create the COND_OP in ifcvt. But of course, addition being commutative, we are free to swap operand 1 and 2 and can end up with e.g. _ifc__60 = .COND_ADD (_2, _6, MADPictureC1_lsm.10_25, MADPictureC1_lsm.10_25); which does not pass the asserts I put in place. This patch removes this restriction and allows the reduction index to be 2 as well. Bootstrapped and regtested on aarch64 and regtested on riscv. x86 is still running. Regards Robin gcc/ChangeLog: PR middle-end/112406 * tree-vect-loop.cc (vectorize_fold_left_reduction): Allow reduction index != 1. (vect_transform_reduction): Handle reduction index != 1. gcc/testsuite/ChangeLog: * gcc.target/aarch64/pr112406-2.c: New test. --- gcc/testsuite/gcc.target/aarch64/pr112406-2.c | 20 +++++++++++++++++++ gcc/tree-vect-loop.cc | 15 +++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/pr112406-2.c diff --git a/gcc/testsuite/gcc.target/aarch64/pr112406-2.c b/gcc/testsuite/gcc.target/aarch64/pr112406-2.c new file mode 100644 index 00000000000..bb6e9cf7c70 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr112406-2.c @@ -0,0 +1,20 @@ +/* { dg-do compile { target { aarch64*-*-* } } } */ +/* { dg-options "-march=armv8-a+sve -Ofast" } */ + +double MADPictureC1; +extern int PictureRejected[]; +int PictureMAD_0, MADModelEstimator_n_windowSize_i, MADModelEstimator_n_windowSize_oneSampleQ; + +void MADModelEstimator_n_windowSize() { + int estimateX2 = 0; + for (; MADModelEstimator_n_windowSize_i; MADModelEstimator_n_windowSize_i++) { + if (MADModelEstimator_n_windowSize_oneSampleQ && + !PictureRejected[MADModelEstimator_n_windowSize_i]) + estimateX2 = 1; + if (!PictureRejected[MADModelEstimator_n_windowSize_i]) + MADPictureC1 += PictureMAD_0; + } + if (estimateX2) + for (;;) + ; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 58679e91c0a..044eacddf7e 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -7070,7 +7070,7 @@ vectorize_fold_left_reduction (loop_vec_info loop_vinfo, op0 = ops[1 - reduc_index]; else { - op0 = ops[2]; + op0 = ops[2 + (1 - reduc_index)]; opmask = ops[0]; gcc_assert (!slp_node); } @@ -8455,7 +8455,9 @@ vect_transform_reduction (loop_vec_info loop_vinfo, gcc_assert (code == IFN_COND_ADD || code == IFN_COND_SUB || code == IFN_COND_MUL || code == IFN_COND_AND || code == IFN_COND_IOR || code == IFN_COND_XOR); - gcc_assert (op.num_ops == 4 && (op.ops[1] == op.ops[3])); + gcc_assert (op.num_ops == 4 + && (op.ops[reduc_index] + == op.ops[internal_fn_else_index ((internal_fn) code)])); } bool masked_loop_p = LOOP_VINFO_FULLY_MASKED_P (loop_vinfo); @@ -8498,12 +8500,15 @@ vect_transform_reduction (loop_vec_info loop_vinfo, { /* For a conditional operation pass the truth type as mask vectype. */ - gcc_assert (single_defuse_cycle && reduc_index == 1); + gcc_assert (single_defuse_cycle + && (reduc_index == 1 || reduc_index == 2)); vect_get_vec_defs (loop_vinfo, stmt_info, slp_node, ncopies, op.ops[0], &vec_oprnds0, truth_type_for (vectype_in), - NULL_TREE, &vec_oprnds1, NULL_TREE, - op.ops[2], &vec_oprnds2, NULL_TREE); + reduc_index == 1 ? NULL_TREE : op.ops[1], + &vec_oprnds1, NULL_TREE, + reduc_index == 2 ? NULL_TREE : op.ops[2], + &vec_oprnds2, NULL_TREE); } /* For single def-use cycles get one copy of the vectorized reduction