From patchwork Thu Dec 14 08:18:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 178561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8392261dys; Thu, 14 Dec 2023 00:19:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUaIuqWQbeKg+WWxZLTq5jHYr6w+b94iKTjvkW2I8GJOwGYealtL2IF2zlKQQwab8Rmp0g X-Received: by 2002:a05:6214:19cf:b0:67f:b61:2799 with SMTP id j15-20020a05621419cf00b0067f0b612799mr629319qvc.8.1702541965970; Thu, 14 Dec 2023 00:19:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702541965; cv=pass; d=google.com; s=arc-20160816; b=d/59nb4OiXcu6Zalw6NQi+LhHbjQM8t/lPoauAEVigNZ6p60hGJXrenVx4QSx/zapI JeE1wft4eBbUrWRrk9CfADngsdOMInPtd/028FL3Mhat1YMHBWYL1ZJVYwbk9H6ETnGp vbdgXgYoxRvz7MMujnGxNGV/+2R05f64dpm71kSQ0C+dZ1h7JZlQQ/c9SNuxPlhGboEy B4dPYfqZH0U5oFl4g9av1zxpHX1J4AfFLXest4ZbJGn4Go2LjlB/BsMZzOrnHbRuH38C t9u6vHqC7d8ljHhV88I9wFaweue9u1UJTI3Q3Ee9xRdalT24uo92THweOjuiogj+bLgy 9N+A== 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 :subject:from:to:content-language:cc:user-agent:mime-version:date :message-id:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=2ynTHj9dsSOX9H0DnGmymTwCOUPZUdrvRgusLqZzy3k=; fh=hBE0u2KEJ4vtNXg4OhERnjVmFasPljG7bDmkDf4H5II=; b=C9RT5xgFEvsQaV3kaFp9SPkxF7EgXU3e85QNyLR2WH41qnAnY2CeTjCRN0QJLPtQRR lmEOOvRWW9G1WUL8RyXw6RT6tp25ZzXT0F5fHV/886Qoa8qK2+HFihm9beMQTZ7Q/5jI L01XUQO/VUe5HeDw+IYNBl6hdwt32TTLiUfkH4DbaYo7aswUqp0NUa53NZqF1iC9+wUk jUyj3J4Lo2KLlBp753MwmDDnbGPU/ve+195reMAsq+goXgR3ADZmznXv7QitdQgcxYJD CFFJ/cAE87ybkJ5FyY8Pd4ovLNDzmb5jlBYGWDqF/F/hhZ4le4jrHWPdwNZIv7Z8TXgC WnxQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MxFd+jB+; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id c1-20020a37e101000000b00774165a6970si13789844qkm.488.2023.12.14.00.19.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Dec 2023 00:19:25 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=MxFd+jB+; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 AB4153861826 for ; Thu, 14 Dec 2023 08:19:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id E3A3E3858C2C for ; Thu, 14 Dec 2023 08:18:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E3A3E3858C2C 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 E3A3E3858C2C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::62a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702541941; cv=none; b=roU/a01PqWUxDYEtXDdpTIZQ6erd/A9G6U5PBAtonQZfRtfXE1JnUz9qT8ckGx5CZwAn8SDMquE0iys7SOk9td2rMPpCw+gZgGOa/kz98lYVDLcISYJ7RZzctm/Oz6Y07a43Gy6CzT34UmjPKhjcOfn0iZ4y1C7R0eXgVTZfO3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702541941; c=relaxed/simple; bh=JM/EEKPGkk1SSR/6CLVgJR6E6YOq1ThON5H4+sqoZTs=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=OcJk73aZBbGRYvGxZTly+qRL0hRl3WS3R0HHjEKurWZw88Bh8I6I0N6u/ILC+Mhlsa1NpSl4jiib+ZUuOYD25flF/WI0lKMusys4vZpx8ePtgh8ge5NtW6FZW1R9qlPoEg0KX7hg9i2ToYoyNO85L7yWgVu3up/kMt4tuA8Sdqo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a1d2f89ddabso939144366b.1 for ; Thu, 14 Dec 2023 00:18:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702541929; x=1703146729; 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=2ynTHj9dsSOX9H0DnGmymTwCOUPZUdrvRgusLqZzy3k=; b=MxFd+jB+JeIjLZtILSX4vItlQHyftlDDsVDkGmTIwtF9RSL/d0jzAB0TFqcffNCJ4/ 8FyxMQMOiJRZIoPJh9vjhGeKYJD5i4n/k+ykrvu12+MME7RdCfnS5wRjEa8z/w8xSD+W d3Rd+1Tl42IdZmxV1lD0BSbtMKKhcQHKltEDvXs6V9REVj4YRu2BWjR63WmS6+kC0176 UcCk5H+Hdoqus79ToyjOY47L89gNVxSzL/8+BRscv/+1WSf/wxlGJcbkcfdRjmTNAUkn L9qCb7dKV6GeapLz2jmipP9kMj1GF2/Kot45OqqJd4LVQ+OW638U/pkztgzwA2wJZSRq /iDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702541929; x=1703146729; 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=2ynTHj9dsSOX9H0DnGmymTwCOUPZUdrvRgusLqZzy3k=; b=XBG8L3lEnC3TRlYXwttpiyZXMQDcebKF23XKyel/Kk10kBGhitLI21f745Rl7mc/CU jyNbI2/zI8Qz8gf6bOmaHjJ7jbdB6He/dOcS2ZiDGBwDLoqlmLVHPEcf+uD3L/R3disN 5t3GSHsg+RCS/w8GYQVP4zGfDsuIAZ0dcx3vCmmB3CIt62lGQ/jIzy7jwpgEh0n7GkKw oljoHJUnwuaSpq9TiM6Rmcv+yJ7xDEDGjy2Z956rusre1KGeX7NqaWKvMaIw4q3EZLyS QP/ft0UCQ5kGKAmy0EUgMru9I01CseK+rAevHBjygvD474xd9X/zMpbl+VxUaUGdDmcq 439Q== X-Gm-Message-State: AOJu0YyqhhCHYbQa2I1o/iAEbNiBmA3eaz1RuQPDQrfD0VdKeVs9WsYm OKmOwbRxkQQU86ncXED+8ED3fdnIgms= X-Received: by 2002:a17:907:7d8c:b0:9b2:cf77:a105 with SMTP id oz12-20020a1709077d8c00b009b2cf77a105mr6635410ejc.15.1702541928474; Thu, 14 Dec 2023 00:18:48 -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 o20-20020a17090611d400b00a0d02cfa48bsm8967774eja.213.2023.12.14.00.18.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Dec 2023 00:18:48 -0800 (PST) Message-ID: <67552cb3-e08e-4003-a45d-9ed64bd7da43@gmail.com> Date: Thu, 14 Dec 2023 09:18:47 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: rdapp.gcc@gmail.com Content-Language: en-US To: gcc-patches , "richard.sandiford" , Richard Biener From: Robin Dapp Subject: [PATCH] expmed: Get vec_extract element mode from insn_data, [PR112999] X-Spam-Status: No, score=-9.1 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: 1785244644557653385 X-GMAIL-MSGID: 1785244644557653385 Hi, this is a bit of a follow up of the latest expmed change. In extract_bit_field_1 we try to get a better vector mode before extracting from it. Better refers to the case when the requested target mode does not equal the inner mode of the vector to extract from and we have an equivalent tieable vector mode with a fitting inner mode. On riscv this triggered an ICE (PR112999) because we would take the detour of extracting from a mask-mode vector via a vector integer mode. One element of that mode could be subreg-punned with TImode which, in turn, would need to be operated on in DImode chunks. As the backend might return the extracted value in a different mode than the inner mode of the input vector, we might already have a mode equivalent to the target mode. Therefore, this patch first obtains the mode the backend uses for the particular vec_extract and then compares it against the target mode. Only if those disagree we try to find a better mode. Otherwise we continue with the initial one. Bootstrapped and regtested on x86, aarch64 and power10. Regtested on riscv. Regards Robin gcc/ChangeLog: PR target/112999 * expmed.cc (extract_bit_field_1): Get vec_extract's result element mode from insn_data and compare it to the target mode. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/pr112999.c: New test. --- gcc/expmed.cc | 17 +++++++++++++++-- .../gcc.target/riscv/rvv/autovec/pr112999.c | 17 +++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112999.c diff --git a/gcc/expmed.cc b/gcc/expmed.cc index ed17850ff74..6fbe4d9cfaf 100644 --- a/gcc/expmed.cc +++ b/gcc/expmed.cc @@ -1722,10 +1722,23 @@ extract_bit_field_1 (rtx str_rtx, poly_uint64 bitsize, poly_uint64 bitnum, } } + /* The target may prefer to return the extracted value in a different mode + than INNERMODE. */ + machine_mode outermode = GET_MODE (op0); + machine_mode element_mode = GET_MODE_INNER (outermode); + if (VECTOR_MODE_P (outermode) && !MEM_P (op0)) + { + enum insn_code icode + = convert_optab_handler (vec_extract_optab, outermode, element_mode); + + if (icode != CODE_FOR_nothing) + element_mode = insn_data[icode].operand[0].mode; + } + /* See if we can get a better vector mode before extracting. */ if (VECTOR_MODE_P (GET_MODE (op0)) && !MEM_P (op0) - && GET_MODE_INNER (GET_MODE (op0)) != tmode) + && element_mode != tmode) { machine_mode new_mode; @@ -1755,7 +1768,7 @@ extract_bit_field_1 (rtx str_rtx, poly_uint64 bitsize, poly_uint64 bitnum, /* Use vec_extract patterns for extracting parts of vectors whenever available. If that fails, see whether the current modes and bitregion give a natural subreg. */ - machine_mode outermode = GET_MODE (op0); + outermode = GET_MODE (op0); if (VECTOR_MODE_P (outermode) && !MEM_P (op0)) { scalar_mode innermode = GET_MODE_INNER (outermode); diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112999.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112999.c new file mode 100644 index 00000000000..c049c5a0386 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr112999.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv64gcv_zvl512b -mabi=lp64d --param=riscv-autovec-lmul=m8 --param=riscv-autovec-preference=fixed-vlmax -O3 -fno-vect-cost-model -fno-tree-loop-distribute-patterns" } */ + +int a[1024]; +int b[1024]; + +_Bool +fn1 () +{ + _Bool tem; + for (int i = 0; i < 1024; ++i) + { + tem = !a[i]; + b[i] = tem; + } + return tem; +}