From patchwork Thu Jan 6 16:42:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1576185 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=jb/dnEcC; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JVBwc2cVHz9sSs for ; Fri, 7 Jan 2022 03:42:38 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 41FFB3857C48 for ; Thu, 6 Jan 2022 16:42:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 5F0CA3858408 for ; Thu, 6 Jan 2022 16:42:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5F0CA3858408 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=RLJUVM6PgKj/BqqgaOgaPQK6SYNh28aNPBYivhP/mbQ=; b=jb/dnEcCQiWRABRBG7bkoi4ymN DhntMZTkui3UBmUtaKbIiZLy32OYLdH59K/zGjnTeC+gX5EFEgLq0zJGQzcN+WeHaGUpLZ9QXGnYs k8frSugx4fD0KEMCPvVG8xPG4dRBAq0S6YHFkaCMATPT5+LbT4tcU3iVREdsaHKgcAjeMQBDAKpbz zAudxJAmycjoTapmaKJCel6Ac3SMErurTNHxR2J8KMUGdMNlLr6m+r2klBFZW/So53kqy2lmVUt64 CKkKSOlSx189khy+9ExW9m8QWiPdKTKnasGb3VnjtxhBtG/7XNmlhNk+YVhb51KA3t3+8kLmyIgEB OQhT+Npg==; Received: from [185.62.158.67] (port=53582 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1n5Vq8-0005bI-La; Thu, 06 Jan 2022 11:42:12 -0500 From: "Roger Sayle" To: "'GCC Patches'" Subject: [PATCH] nvptx: Add support for PTX's cnot instruction. Date: Thu, 6 Jan 2022 16:42:11 -0000 Message-ID: <000a01d8031c$5adc1510$10943f30$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdgDG/LMC1lUrU6TQC2EFVBh6+YxtA== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 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 Sender: "Gcc-patches" Happy New Year for 2022. This is a simple patch, now that the nvptx backend has transitioned to STORE_FLAG_VALUE=1, that adds support for NVidia's cnot instruction, that implements C/C++ style logical negation. Previously, the simple function: int foo(int x) { return !x; } on nvptx-none with -O2 would generate: mov.u32 %r24, %ar0; setp.eq.u32 %r28, %r24, 0; selp.u32 %value, 1, 0, %r28; with this patch, GCC now generates: mov.u32 %r24, %ar0; cnot.b32 %value, %r24; This patch has been tested on nvptx-none hosted on x86_64-pc-linux-gnu (including newlib) with a make and make -k check with no new failures. Ok for mainline? 2022-01-06 Roger Sayle gcc/ChangeLog * config/nvptx/nvptx.md (*cnot2): New define_insn. gcc/testsuite/ChangeLog * gcc.target/nvptx/cnot-1.c: New test case. Thanks in advance, Roger diff --git a/gcc/config/nvptx/nvptx.md b/gcc/config/nvptx/nvptx.md index a4c14a3..ce74672 100644 --- a/gcc/config/nvptx/nvptx.md +++ b/gcc/config/nvptx/nvptx.md @@ -592,6 +592,13 @@ "" "%.\\tnot.b%T0\\t%0, %1;") +(define_insn "*cnot2" + [(set (match_operand:HSDIM 0 "nvptx_register_operand" "=R") + (eq:HSDIM (match_operand:HSDIM 1 "nvptx_register_operand" "R") + (const_int 0)))] + "" + "%.\\tcnot.b%T0\\t%0, %1;") + (define_insn "bitrev2" [(set (match_operand:SDIM 0 "nvptx_register_operand" "=R") (unspec:SDIM [(match_operand:SDIM 1 "nvptx_register_operand" "R")] diff --git a/gcc/testsuite/gcc.target/nvptx/cnot-1.c b/gcc/testsuite/gcc.target/nvptx/cnot-1.c new file mode 100644 index 0000000..d0bdccd --- /dev/null +++ b/gcc/testsuite/gcc.target/nvptx/cnot-1.c @@ -0,0 +1,94 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +int test1(int x) +{ + return !x; +} + +int test2(int x) +{ + return x ? 0 : 1; +} + +int test3(int x) +{ + return (x == 0) ? 1 : 0; +} + +unsigned int test4(unsigned int x) +{ + return !x; +} + +unsigned int test5(unsigned int x) +{ + return x ? 0 : 1; +} + +unsigned int test6(unsigned int x) +{ + return (x == 0) ? 1 : 0; +} + +short test7(short x) +{ + return !x; +} + +short test8(short x) +{ + return x ? 0 : 1; +} + +short test9(short x) +{ + return (x == 0) ? 1 : 0; +} + +unsigned short test10(unsigned short x) +{ + return !x; +} + +unsigned short test11(unsigned short x) +{ + return x ? 0 : 1; +} + +unsigned short test12(unsigned short x) +{ + return (x == 0) ? 1 : 0; +} + +long test13(long x) +{ + return !x; +} + +long test14(long x) +{ + return x ? 0 : 1; +} + +long test15(long x) +{ + return (x == 0) ? 1: 0; +} + +unsigned long test16(unsigned long x) +{ + return !x; +} + +unsigned long test17(unsigned long x) +{ + return x ? 0 : 1; +} + +unsigned long test18(unsigned long x) +{ + return (x == 0) ? 1 : 0; +} + +/* { dg-final { scan-assembler-times "cnot.b" 18 } } */