From patchwork Thu Nov 16 22:36:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoni Boucher X-Patchwork-Id: 165953 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp159463vqn; Thu, 16 Nov 2023 14:37:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpJrajtNhI3+rTG2KEv1urnciBbYurLJYKGvaEwqbsromyghOAaotQOmkBGvHB7wy+/0Bs X-Received: by 2002:a05:620a:4888:b0:774:1795:4a89 with SMTP id ea8-20020a05620a488800b0077417954a89mr12178576qkb.71.1700174261182; Thu, 16 Nov 2023 14:37:41 -0800 (PST) ARC-Seal: i=3; a=rsa-sha256; t=1700174261; cv=pass; d=google.com; s=arc-20160816; b=eeCDj52saMqCXd6tfzJqf6tyjF80jGEL/yf2/ArlVJYWcFAF1tzPSdkf0+uD3sRBN1 gd+ANB4RxY9mnJLtqbRWZCatNNhcEVNdA3Pong/zT9rvwF8RpQKxX2KgyRK83JdjCewY 2gim6GFQvnj19OGetneUWm/J8j3dXzxU/alN58T0OwJ1RVHq9u8PaxUBgJkofyvCdT1N IRGtno9SkXHvRYPm85kCIfIK7Ow2e/kHJc1Ym2KjbzmyigPYbPGBvGRtkr5YYTBdx+Wx 2OT9m1hr8wREbZxtnm16HbIBDsszYF6AprbHkUi23lCE9O8XBTFEDu16sVxjEr9XMm9N CmPg== ARC-Message-Signature: i=3; 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:feedback-id:mime-version :user-agent:autocrypt:date:cc:to:from:subject:message-id :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=bsyZv+WPCC8Upp01lLGogjK2eDwUAktYJlABZgHOG8A=; fh=JISpz+bBSU4NvpZkyVsds76plEm8twWz26DY1VOoDBc=; b=YyWFijssgifcExuV5PAN324pwiesp0s81VXj0C1rae+imvoHVT9xaS0dY/lgRq7XmL R1BZ+OpYhBbLOK0/r00K9uL5dzMt0eHdMk6ag2EqrBwkKMRLtLSFiuBFsPKlrEiRE40M StI+RtHM6seyGhvRqIgQP6Pf99rJfkJNuu+aW1JsJlZxA52KiCBN0yhUQF4q4lj/veJk Esbhl0yTWbXhisFxzqe6J1shcboa1rVE5F7KnVqwknk62LsJP4ytEfwQLYduvfik0Y5S Aytmbv3gsVoRq1J2KkWvxGyyS2IfrWseIyNmWhDQL9vm0rVSxzeQxfNT811s2R2x1Tyo M1vA== ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@zoho.com header.s=zm2022 header.b=fbXlFarg; arc=pass (i=2); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=zoho.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r16-20020a05620a299000b0076db59242a1si472284qkp.468.2023.11.16.14.37.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Nov 2023 14:37:41 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@zoho.com header.s=zm2022 header.b=fbXlFarg; arc=pass (i=2); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=zoho.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D7A5A3844741 for ; Thu, 16 Nov 2023 22:37:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from sender4-pp-o91.zoho.com (sender4-pp-o91.zoho.com [136.143.188.91]) by sourceware.org (Postfix) with ESMTPS id C937138618D2; Thu, 16 Nov 2023 22:36:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C937138618D2 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=zoho.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=zoho.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C937138618D2 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=136.143.188.91 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700174218; cv=pass; b=Kbdt3UApHyoKYhBq6FiKnD0udVUGqq2jJebWrLi6imgehaBHE8YP2cbX2udVrOVEtY71yQHRfksQC/d8QQViGi9rljJu+0h+de/0HUAfokf9nx66tMAE56wgUc+Bd5rLXA4Ou//SJkEx5NiV2oJvscbUg2Dn65oZUjDGPfHjZbs= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1700174218; c=relaxed/simple; bh=lVE0ND3c4ZAxHUSYjohDtY3m/EOfcIfqEkh+cKiW1uA=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=tp5r5Sqg0YLrQRbY7L8dAQMAg0AG/clBYChnVw+y1XQFvGqZBJ93lxZx7BKQ1YWKuIw+ZgIbZAmdXLkdRdFS5zJhxzkni9JJsebi6J3wy3LcU6fW1mtC9+csnM0nQt3eFVDs7DaEibum+1cNlzW5K5LN8FPGliFtWRy1tw4wCFI= ARC-Authentication-Results: i=2; server2.sourceware.org ARC-Seal: i=1; a=rsa-sha256; t=1700174199; cv=none; d=zohomail.com; s=zohoarc; b=IUxXRCC7XUROm+NsFQ8n1RTeueaV8oXbP8k+S6z9Rgyuu32uCFLkWbR6nY9bhUPOPDIR7JUEjm0fvbu4fobFnVtEjFYsvfZ/7thtwkIKRerOzSGwLOFTHB91jKk13Kdq9P1vFfY7rlF8C4UlMQeRbl1/5weCyQeP2Q3lBEPuP3s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1700174199; h=Content-Type:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=bsyZv+WPCC8Upp01lLGogjK2eDwUAktYJlABZgHOG8A=; b=PRjY2PoVNkHoL8nkVuJw77PO81HGqrzF3/uyVS/jyHQ6BkSsv40TBiJnw93T9cU2lTZrzUsdgeHD4rtXEMAuvbnai0EACx+n0yl9xlzAEWH+5eNbjABsqsZ0XFv2V71/GOQrjakT8tdRyya47rwt7wVb2tk8/U5FqNn+7rNME14= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=zoho.com; spf=pass smtp.mailfrom=bouanto@zoho.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1700174199; s=zm2022; d=zoho.com; i=bouanto@zoho.com; h=Message-ID:Subject:Subject:From:From:To:To:Cc:Cc:Date:Date:Content-Type:MIME-Version:Feedback-ID:Message-Id:Reply-To; bh=bsyZv+WPCC8Upp01lLGogjK2eDwUAktYJlABZgHOG8A=; b=fbXlFargtZZuXv10d9c6IJrntwkv8Ahy74GOscng6+m3WXfciFuKHWFK8f8+hS6Y KoIP3ugho1WS8eBLSiW1aSkm7RLZAeCk2Ti0rdmYWUTBA+t8s1mR+2kX8vxIZMK26le 1OGiMggLh9Ss9cbOeQznfuQPCDhKW2r683r5m7p4= Received: from [192.168.1.172] (38.87.11.6 [38.87.11.6]) by mx.zohomail.com with SMTPS id 170017419842647.166824498242704; Thu, 16 Nov 2023 14:36:38 -0800 (PST) Message-ID: Subject: [PATCH] libgccjit Fix a RTL bug for libgccjit From: Antoni Boucher To: jit@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: David Malcolm Date: Thu, 16 Nov 2023 17:36:36 -0500 Autocrypt: addr=bouanto@zoho.com; prefer-encrypt=mutual; keydata=mQENBFOSMLQBCADO5aw6Ys8thMQUNzrwAnfJX2wbgWiz0pQ01DjYj22eeIpChkoZn6LWdt4dieq30u2rFi/yQzJ02foHwI2+aL9rU6xz/x4TwqyRJQGMOqklNc3R+pdXmH4WDQkQDWmLxvc07vu+zb8Tx5A6pMDh4J2ncCEhLEUcH39Yq/yg4eBnFwUX6N7kakvHrnScGNqhnSFCacoJeMJUAR+1G7VBSBd++jmnHLnx3mj7QkRZVECJUw2zqiv1yReCC6GU4SvqLjdqm5ZGeoWOqD/NHjBRoEeOVjzp6M/qOjjWRbkJVqmvgfcD8UytSSqqboR35YFT4L+rZt2ri3T12MJb3i5syCAXABEBAAG0IUFudG9uaSBCb3VjaGVyIDxib3VhbnRvQHpvaG8uY29tPokBVgQTAQgAQAIbIwcLCQgHAwIBBhUIAgkKCwQWAgMBAh4BAheAFiEEOELC4Uw1Jeb66YE6RVeGAwR4zcEFAlz4QM4FCRLMEZoACgkQRVeGAwR4zcFBQQf/afttJrA/puADQZhrDfkgr0MFvq6iB+GCy1b8BkXimk1TOXTPt87YLehSeijNu3JkYhl5eRc87BNfU9J87KfI/KIy6hZxqlDXk16FhW9bw/7wYEA0hpb3MUn7xLElXDT0ZHaD+KTe8Oun7qfzgx5RlL6r/WODf3CkSpO085R/rfeBqDEx9mVlhDWgq6Az3CZoD+3CqiCKVqmDuHTWz4kwrd9AM5eVcLvvLKnZIdoIp+G5Ao6BvaGlZyfenN1iOSjLy2NXNt4MnUt0lUYEP5KSIIRhHQ8xkUbj7eWUmaahkxhNb3fH3sAPwGnRZrPpb4rgYzNmSk63wWMh9M2xk+rLb7kBDQRTkjC0AQgAumZzsAV/UFWI+dpzebQfma36kKYZZFuseant5sq/HWP553XQ/U6ttJiKyN5MpCqtxvCAoRplf42YhlHuFqgf73WJxoJ6Y+sdyqoBSwlR+ gzAneAmsa8gmmY0wawH0Z2leazjKuS7mJjVEQZg0ZGsiCVRGeRnDqFGzDEzDc9ngWKSoTq0fKzlGy1X85OrtmUrvEbhSo6HP+FoeunHkIqrxu3w3vDoFEXxVQlKI6V3I4nCz5n6DB8WR3L7nsiiTnOiGirPw1ngvWFLW86kkA4FJpayc8Xl3va3SLY+2y4yuROboX2DVI4AC/Qeug/mDiBicPxkP6YfUartQRMe6obkEQARAQABiQE8BBgBCAAmAhsMFiEEOELC4Uw1Jeb66YE6RVeGAwR4zcEFAlz4QRsFCRLMEecACgkQRVeGAwR4zcE56ggAgTgrJInBKC+7552Dpccuo6Clh3wZfjlNLv9/6r5lKEbaNzaTrfhPiAP4WgnluIUmj8amOFLFJpj+BAVNOXpZ4D2R3o9ch8z7fot+fW4Yw+PKIxH4I2xEys8ndoEB3aiQwHjKcGIhkIU7uyMJFQr2aWjdTY0gmXw0YZueHOSLgo7uX4XKxB8fEO/yto/Tff2YBAAq+AtNwt+Gh5YS9rZw7rwUTWMi84yVOlc+zRE79E9NJkvdTwX7IJYo64VzIRNfgHsn7QNdVzuM1XIFHl+Glk6cIlI8s6BO7nEoCn3hTF104fQTAO3fEs+XXZOKXo2lk8faowEoPq5r58StrV0nyg== User-Agent: Evolution 3.50.1 MIME-Version: 1.0 X-Zoho-Virus-Status: 1 X-Zoho-AV-Stamp: zmail-av-1.1.0/200.101.90 Feedback-ID: rr08011228588d2f9e14bdb64b2e27e52f00008bc1257bff07aa9aa2381f8efec770f3852fc2a9f25463016d45:zu080112264ec969aa51c17fe35e84c7280000c1f024f990da4d6781ca49f72c4633ae5b0ce1faee4c7ee6:rf08011232c4917eb5dfefe972bdc597550000fadd526612b59ad5c1c27d8cc191eae203c09f2d8ad77f05e6d8ec7eed016b2891c16571:ZohoMail X-ZohoMailClient: External X-Spam-Status: No, score=-11.8 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: 1782761926129826560 X-GMAIL-MSGID: 1782761926129826560 Hi. This patch fixes a RTL bug when using some target-specific builtins in libgccjit (bug 112576). The test use a function from an unmerged patch: https://gcc.gnu.org/pipermail/jit/2023q1/001605.html Thanks for the review! From 9236998f5ad3156ebe39e97c03d1a28ce80dd95a Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Thu, 9 Jun 2022 20:57:41 -0400 Subject: [PATCH] libgccjit Fix a RTL bug for libgccjit This fixes a 'unrecognizable insn' error when generating some code using target-specific builtins. gcc/ChangeLog: PR jit/112576 * emit-rtl.cc (init_emit_once): Do not initialize const_int_rtx if already initialized. gcc/testsuite: PR jit/112576 * jit.dg/all-non-failing-tests.h: Mention test-rtl-bug-target-builtins.c. * jit.dg/test-rtl-bug-target-builtins.c: New test. --- gcc/emit-rtl.cc | 9 +- gcc/testsuite/jit.dg/all-non-failing-tests.h | 3 + .../jit.dg/test-rtl-bug-target-builtins.c | 87 +++++++++++++++++++ 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/jit.dg/test-rtl-bug-target-builtins.c diff --git a/gcc/emit-rtl.cc b/gcc/emit-rtl.cc index 84b6833225e..a18ac1de98c 100644 --- a/gcc/emit-rtl.cc +++ b/gcc/emit-rtl.cc @@ -6216,8 +6216,13 @@ init_emit_once (void) /* Don't use gen_rtx_CONST_INT here since gen_rtx_CONST_INT in this case tries to use these variables. */ for (i = - MAX_SAVED_CONST_INT; i <= MAX_SAVED_CONST_INT; i++) - const_int_rtx[i + MAX_SAVED_CONST_INT] = - gen_rtx_raw_CONST_INT (VOIDmode, (HOST_WIDE_INT) i); + { + // Do not initialize twice the constants because there are used elsewhere + // and libgccjit execute this function twice. + if (const_int_rtx[i + MAX_SAVED_CONST_INT] == NULL) + const_int_rtx[i + MAX_SAVED_CONST_INT] + = gen_rtx_raw_CONST_INT (VOIDmode, (HOST_WIDE_INT) i); + } if (STORE_FLAG_VALUE >= - MAX_SAVED_CONST_INT && STORE_FLAG_VALUE <= MAX_SAVED_CONST_INT) diff --git a/gcc/testsuite/jit.dg/all-non-failing-tests.h b/gcc/testsuite/jit.dg/all-non-failing-tests.h index e762563f9bd..3da2e285b80 100644 --- a/gcc/testsuite/jit.dg/all-non-failing-tests.h +++ b/gcc/testsuite/jit.dg/all-non-failing-tests.h @@ -322,6 +322,9 @@ /* test-setting-alignment.c: This can't be in the testcases array as it is target-specific. */ +/* test-rtl-bug-target-builtins.c: This can't be in the testcases array as it + is target-specific. */ + /* test-string-literal.c */ #define create_code create_code_string_literal #define verify_code verify_code_string_literal diff --git a/gcc/testsuite/jit.dg/test-rtl-bug-target-builtins.c b/gcc/testsuite/jit.dg/test-rtl-bug-target-builtins.c new file mode 100644 index 00000000000..d4a686271f9 --- /dev/null +++ b/gcc/testsuite/jit.dg/test-rtl-bug-target-builtins.c @@ -0,0 +1,87 @@ +/* { dg-do compile { target x86_64-*-* } } */ + +#include +#include + +#include "libgccjit.h" + +#define TEST_PROVIDES_MAIN +#include "harness.h" + +void +create_code (gcc_jit_context *ctxt, void *user_data) +{ + gcc_jit_context_add_command_line_option (ctxt, "-mavx512vl"); + gcc_jit_function *builtin = + gcc_jit_context_get_target_builtin_function (ctxt, + "__builtin_ia32_cvtpd2udq128_mask"); + + gcc_jit_type *u8_type = + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_UINT8_T); + gcc_jit_type *double_type = + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE); + gcc_jit_type *v2df = gcc_jit_type_get_vector (double_type, 2); + gcc_jit_type *int_type = + gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); + gcc_jit_type *v4si = gcc_jit_type_get_vector (int_type, 4); + + gcc_jit_function *func = + gcc_jit_context_new_function (ctxt, NULL, + GCC_JIT_FUNCTION_EXPORTED, + v4si, + "epu32", + 0, NULL, + 0); + gcc_jit_block *block = gcc_jit_function_new_block (func, NULL); + gcc_jit_lvalue *var1 = gcc_jit_function_new_local (func, NULL, v2df, "var1"); + gcc_jit_lvalue *var2 = gcc_jit_function_new_local (func, NULL, v4si, "var2"); + gcc_jit_rvalue *args[3] = { + gcc_jit_lvalue_as_rvalue (var1), + gcc_jit_lvalue_as_rvalue (var2), + gcc_jit_context_zero (ctxt, u8_type), + }; + gcc_jit_rvalue *call = gcc_jit_context_new_call (ctxt, NULL, builtin, 3, args); + gcc_jit_block_end_with_return (block, NULL, call); +} + +void +verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) +{ + CHECK_NON_NULL (result); +} + +int +main (int argc, char **argv) +{ + /* This is the same as the main provided by harness.h, but it first create a dummy context and compile + in order to add the target builtins to libgccjit's internal state. */ + gcc_jit_context *ctxt; + ctxt = gcc_jit_context_acquire (); + if (!ctxt) + { + fail ("gcc_jit_context_acquire failed"); + return -1; + } + gcc_jit_result *result; + result = gcc_jit_context_compile (ctxt); + gcc_jit_result_release (result); + gcc_jit_context_release (ctxt); + + int i; + + for (i = 1; i <= 5; i++) + { + snprintf (test, sizeof (test), + "%s iteration %d of %d", + extract_progname (argv[0]), + i, 5); + + //printf ("ITERATION %d\n", i); + test_jit (argv[0], NULL); + //printf ("\n"); + } + + totals (); + + return 0; +} -- 2.42.1