From patchwork Sun Jun 25 13:13:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1799532 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org 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=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=HUTjFaCj; dkim-atps=neutral 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Qprz46jxvz20bC for ; Sun, 25 Jun 2023 23:14:08 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 305243858D35 for ; Sun, 25 Jun 2023 13:14:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 305243858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687698846; bh=DIQJWn90Y+eTfy9rOYMdAF8EEZAJrqCC6MaVQ2fq+jQ=; h=Date:Subject:References:To:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=HUTjFaCjaxmyA8Eg8WxGKa3liTPe1RvXf2+EX9aIya5yjU3CvvtcaeCXB4ZiR3je0 eTj4dCWsT2bLpcP/3z9fA/zFxvClT2zbVJhShqiyrsgU18XwS/LvqPIVMsZtWoIW+s s/zD+14CZf1iQm/PtIN9Eny+PCnkFWABQrJ+RbUA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id 664F03858D35 for ; Sun, 25 Jun 2023 13:13:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 664F03858D35 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-668709767b1so1231705b3a.2 for ; Sun, 25 Jun 2023 06:13:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687698821; x=1690290821; h=in-reply-to:from:to:references:content-language:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=DIQJWn90Y+eTfy9rOYMdAF8EEZAJrqCC6MaVQ2fq+jQ=; b=jo4DuJo+mKPGXluUWOatB7VVSRuA11L7CNfyj7h0+PTEpSYruz+EIHXW0ZJ5ga7JDY B/TDywFzuR0/IjG9B0MFJK3z5cPCGG+sTtH+HedUzcg5a1pwyhr1NidWy91Xa1Bo39XM KpaYd91KaQ02/iccmXhdStYmpUSALRoCSPXLlTNFOggPQaejcujX/fAMo5Nl2qwZMNkU MVmteQOvSK7aaTYRKi8vx2VJD6a6NS3v5hJQF3cDb4zmbkD0/o1ILsmQorQNVzkYxmB0 xOzQndHGUgbZ8Z5/43epV7gUAY/hP2S+Mc+M5H0Np1ehSXwTjEHve7FMhFOj6pnxjF++ gI2w== X-Gm-Message-State: AC+VfDxmZGuXq3Y43SSodtb+Q7SU64mChjPFqRT2i7/CdhqDQeU5fmTs oleX4f2cX0qrGvytZcggOHCGcrC5M0k= X-Google-Smtp-Source: ACHHUZ75wB3paEzgr5ICpCxtZGg9fNCdA5mcQ1L1LscgaJEOTUm6enPctBOX5uvbVvPEKMtUVCQF0g== X-Received: by 2002:a05:6a20:7f82:b0:11a:efaa:eb43 with SMTP id d2-20020a056a207f8200b0011aefaaeb43mr26739587pzj.3.1687698821262; Sun, 25 Jun 2023 06:13:41 -0700 (PDT) Received: from [172.31.0.109] ([136.36.130.248]) by smtp.gmail.com with ESMTPSA id v26-20020aa7809a000000b0062cf75a9e6bsm2255340pff.131.2023.06.25.06.13.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 25 Jun 2023 06:13:39 -0700 (PDT) Message-ID: <4524bcd7-53ec-b4b7-59ae-19728281d5bc@gmail.com> Date: Sun, 25 Jun 2023 07:13:37 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: [PING][RISCV] [PR target/110201] Fix operand types for various scalar crypto insns Content-Language: en-US References: To: "gcc-patches@gcc.gnu.org" In-Reply-To: X-Forwarded-Message-Id: X-Spam-Status: No, score=-8.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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jeff Law via Gcc-patches From: Jeff Law Reply-To: Jeff Law Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Ping. With RISCV tag this time. -------- Forwarded Message -------- Subject: [PR target/110201] Fix operand types for various scalar crypto insns Date: Mon, 19 Jun 2023 16:34:28 -0600 From: Jeff Law To: gcc-patches@gcc.gnu.org A handful of the scalar crypto instructions are supposed to take a constant integer argument 0..3 inclusive. A suitable constraint was created and used for this purpose (D03), but the operand's predicate is "register_operand". That's just wrong. This patch adds a new predicate "const_0_3_operand" and fixes the relevant insns to use it. One could argue the constraint is redundant now (and you'd be correct). I wouldn't lose sleep if someone wanted that removed, in which case I'll spin up a V2. The testsuite was broken in a way that made it consistent with the compiler, so the tests passed, when they really should have been issuing errors all along. This patch adjusts the existing tests so that they all expect a diagnostic on the invalid operand usage (including out of range constants). It adds new tests with proper constants, testing the extremes of valid values. OK for the trunk, or should we remove the D03 constraint? Jeff PR target/110201 gcc/ * config/riscv/predicates.md (const_0_3_operand): New predicate. * config/riscv/crypto.md (riscv_aes32dsi): Use new predicate. (riscv_aes32dsmi, riscv_aes32esi, riscvaes32esmi): Likewise. (riscv_sm4ed_, riscv_sm4ks_" [(set (match_operand:X 0 "register_operand" "=r") (unspec:X [(match_operand:X 1 "register_operand" "r") (match_operand:X 2 "register_operand" "r") - (match_operand:SI 3 "register_operand" "D03")] + (match_operand:SI 3 "const_0_3_operand" "D03")] UNSPEC_SM4_ED))] "TARGET_ZKSED" "sm4ed\t%0,%1,%2,%3" @@ -404,7 +404,7 @@ (define_insn "riscv_sm4ks_" [(set (match_operand:X 0 "register_operand" "=r") (unspec:X [(match_operand:X 1 "register_operand" "r") (match_operand:X 2 "register_operand" "r") - (match_operand:SI 3 "register_operand" "D03")] + (match_operand:SI 3 "const_0_3_operand" "D03")] UNSPEC_SM4_KS))] "TARGET_ZKSED" "sm4ks\t%0,%1,%2,%3" diff --git a/gcc/config/riscv/predicates.md b/gcc/config/riscv/predicates.md index 04ca6ceabc7..7aed71b5123 100644 --- a/gcc/config/riscv/predicates.md +++ b/gcc/config/riscv/predicates.md @@ -45,6 +45,10 @@ (define_predicate "const_csr_operand" (and (match_code "const_int") (match_test "IN_RANGE (INTVAL (op), 0, 31)"))) +(define_predicate "const_0_3_operand" + (and (match_code "const_int") + (match_test "IN_RANGE (INTVAL (op), 0, 3)"))) + (define_predicate "csr_operand" (ior (match_operand 0 "const_csr_operand") (match_operand 0 "register_operand"))) diff --git a/gcc/testsuite/gcc.target/riscv/zknd32-2.c b/gcc/testsuite/gcc.target/riscv/zknd32-2.c new file mode 100644 index 00000000000..f8e68c6e56b --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zknd32-2.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv32gc_zknd -mabi=ilp32d" } */ +/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */ + +#include + +int32_t foo1(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32dsi(rs1,rs2,0); +} + +int32_t foo2(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32dsmi(rs1,rs2,0); +} + +int32_t foo3(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32dsi(rs1,rs2,3); +} + +int32_t foo4(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32dsmi(rs1,rs2,3); +} + +/* { dg-final { scan-assembler-times "aes32dsi" 2 } } */ +/* { dg-final { scan-assembler-times "aes32dsmi" 2 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/zknd32.c b/gcc/testsuite/gcc.target/riscv/zknd32.c index 5fcc66da901..7370a2c1812 100644 --- a/gcc/testsuite/gcc.target/riscv/zknd32.c +++ b/gcc/testsuite/gcc.target/riscv/zknd32.c @@ -6,13 +6,30 @@ int32_t foo1(int32_t rs1, int32_t rs2, int bs) { - return __builtin_riscv_aes32dsi(rs1,rs2,bs); + return __builtin_riscv_aes32dsi(rs1,rs2,bs); /* { dg-error "invalid argument to built-in function" } */ } int32_t foo2(int32_t rs1, int32_t rs2, int bs) { - return __builtin_riscv_aes32dsmi(rs1,rs2,bs); + return __builtin_riscv_aes32dsmi(rs1,rs2,bs); /* { dg-error "invalid argument to built-in function" } */ } -/* { dg-final { scan-assembler-times "aes32dsi" 1 } } */ -/* { dg-final { scan-assembler-times "aes32dsmi" 1 } } */ +int32_t foo3(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32dsi(rs1,rs2,-1); /* { dg-error "invalid argument to built-in function" } */ +} + +int32_t foo4(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32dsmi(rs1,rs2,-1); /* { dg-error "invalid argument to built-in function" } */ +} + +int32_t foo5(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32dsi(rs1,rs2,4); /* { dg-error "invalid argument to built-in function" } */ +} + +int32_t foo6(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32dsmi(rs1,rs2,4); /* { dg-error "invalid argument to built-in function" } */ +} diff --git a/gcc/testsuite/gcc.target/riscv/zkne32-2.c b/gcc/testsuite/gcc.target/riscv/zkne32-2.c new file mode 100644 index 00000000000..57a9b3f7d2e --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zkne32-2.c @@ -0,0 +1,28 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv32gc_zkne -mabi=ilp32d" } */ +/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */ + +#include + +int32_t foo1(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32esi(rs1, rs2, 0); +} + +int32_t foo2(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32esmi(rs1, rs2, 0); +} + +int32_t foo3(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32esi(rs1, rs2, 3); +} + +int32_t foo4(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32esmi(rs1, rs2, 3); +} + +/* { dg-final { scan-assembler-times "aes32esi" 2 } } */ +/* { dg-final { scan-assembler-times "aes32esmi" 2 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/zkne32.c b/gcc/testsuite/gcc.target/riscv/zkne32.c index c131c9a6bbb..c7a0d0d02b8 100644 --- a/gcc/testsuite/gcc.target/riscv/zkne32.c +++ b/gcc/testsuite/gcc.target/riscv/zkne32.c @@ -6,13 +6,31 @@ int32_t foo1(int32_t rs1, int32_t rs2, int bs) { - return __builtin_riscv_aes32esi(rs1, rs2, bs); + return __builtin_riscv_aes32esi(rs1, rs2, bs); /* { dg-error "invalid argument to built-in function" } */ } int32_t foo2(int32_t rs1, int32_t rs2, int bs) { - return __builtin_riscv_aes32esmi(rs1, rs2, bs); + return __builtin_riscv_aes32esmi(rs1, rs2, bs); /* { dg-error "invalid argument to built-in function" } */ +} + +int32_t foo3(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32esi(rs1, rs2, -1); /* { dg-error "invalid argument to built-in function" } */ +} + +int32_t foo4(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32esmi(rs1, rs2, -1); /* { dg-error "invalid argument to built-in function" } */ +} + +int32_t foo5(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32esi(rs1, rs2, 4); /* { dg-error "invalid argument to built-in function" } */ +} + +int32_t foo6(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_aes32esmi(rs1, rs2, 4); /* { dg-error "invalid argument to built-in function" } */ } -/* { dg-final { scan-assembler-times "aes32esi" 1 } } */ -/* { dg-final { scan-assembler-times "aes32esmi" 1 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/zksed32-2.c b/gcc/testsuite/gcc.target/riscv/zksed32-2.c new file mode 100644 index 00000000000..6cb5ac35d75 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zksed32-2.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv32gc_zksed -mabi=ilp32" } */ +/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */ + +#include + +int32_t foo1(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_sm4ks(rs1,rs2,0); +} + +int32_t foo2(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_sm4ed(rs1,rs2,0); +} + +int32_t foo3(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_sm4ks(rs1,rs2,3); +} + +int32_t foo4(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_sm4ed(rs1,rs2,3); +} + + +/* { dg-final { scan-assembler-times "sm4ks" 2 } } */ +/* { dg-final { scan-assembler-times "sm4ed" 2 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/zksed32.c b/gcc/testsuite/gcc.target/riscv/zksed32.c index 9548d007cb2..ee296dc7d8f 100644 --- a/gcc/testsuite/gcc.target/riscv/zksed32.c +++ b/gcc/testsuite/gcc.target/riscv/zksed32.c @@ -6,14 +6,31 @@ int32_t foo1(int32_t rs1, int32_t rs2, int bs) { - return __builtin_riscv_sm4ks(rs1,rs2,bs); + return __builtin_riscv_sm4ks(rs1,rs2,bs); /* { dg-error "invalid argument to built-in function" } */ } int32_t foo2(int32_t rs1, int32_t rs2, int bs) { - return __builtin_riscv_sm4ed(rs1,rs2,bs); + return __builtin_riscv_sm4ed(rs1,rs2,bs);/* { dg-error "invalid argument to built-in function" } */ +} + +int32_t foo3(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_sm4ks(rs1,rs2,-1); /* { dg-error "invalid argument to built-in function" } */ +} + +int32_t foo4(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_sm4ed(rs1,rs2,-1);/* { dg-error "invalid argument to built-in function" } */ } -/* { dg-final { scan-assembler-times "sm4ks" 1 } } */ -/* { dg-final { scan-assembler-times "sm4ed" 1 } } */ +int32_t foo5(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_sm4ks(rs1,rs2,4); /* { dg-error "invalid argument to built-in function" } */ +} + +int32_t foo6(int32_t rs1, int32_t rs2) +{ + return __builtin_riscv_sm4ed(rs1,rs2,4);/* { dg-error "invalid argument to built-in function" } */ +} diff --git a/gcc/testsuite/gcc.target/riscv/zksed64-2.c b/gcc/testsuite/gcc.target/riscv/zksed64-2.c new file mode 100644 index 00000000000..5fb0bfd69f8 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/zksed64-2.c @@ -0,0 +1,29 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=rv64gc_zksed -mabi=lp64" } */ +/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */ + +#include + +int64_t foo1(int64_t rs1, int64_t rs2) +{ + return __builtin_riscv_sm4ks(rs1,rs2,0); +} + +int64_t foo2(int64_t rs1, int64_t rs2) +{ + return __builtin_riscv_sm4ed(rs1,rs2,0); +} + +int64_t foo3(int64_t rs1, int64_t rs2) +{ + return __builtin_riscv_sm4ks(rs1,rs2,3); +} + +int64_t foo4(int64_t rs1, int64_t rs2) +{ + return __builtin_riscv_sm4ed(rs1,rs2,3); +} + + +/* { dg-final { scan-assembler-times "sm4ks" 2 } } */ +/* { dg-final { scan-assembler-times "sm4ed" 2 } } */ diff --git a/gcc/testsuite/gcc.target/riscv/zksed64.c b/gcc/testsuite/gcc.target/riscv/zksed64.c index 190a654151d..f7bf9f0c79a 100644 --- a/gcc/testsuite/gcc.target/riscv/zksed64.c +++ b/gcc/testsuite/gcc.target/riscv/zksed64.c @@ -6,14 +6,30 @@ int64_t foo1(int64_t rs1, int64_t rs2, int bs) { - return __builtin_riscv_sm4ks(rs1,rs2,bs); + return __builtin_riscv_sm4ks(rs1,rs2,bs); /* { dg-error "invalid argument to built-in function" } */ } int64_t foo2(int64_t rs1, int64_t rs2, int bs) { - return __builtin_riscv_sm4ed(rs1,rs2,bs); + return __builtin_riscv_sm4ed(rs1,rs2,bs); /* { dg-error "invalid argument to built-in function" } */ } +int64_t foo3(int64_t rs1, int64_t rs2) +{ + return __builtin_riscv_sm4ks(rs1,rs2,-1); /* { dg-error "invalid argument to built-in function" } */ +} + +int64_t foo4(int64_t rs1, int64_t rs2) +{ + return __builtin_riscv_sm4ed(rs1,rs2,-1); /* { dg-error "invalid argument to built-in function" } */ +} -/* { dg-final { scan-assembler-times "sm4ks" 1 } } */ -/* { dg-final { scan-assembler-times "sm4ed" 1 } } */ +int64_t foo5(int64_t rs1, int64_t rs2) +{ + return __builtin_riscv_sm4ks(rs1,rs2,4); /* { dg-error "invalid argument to built-in function" } */ +} + +int64_t foo6(int64_t rs1, int64_t rs2) +{ + return __builtin_riscv_sm4ed(rs1,rs2,4); /* { dg-error "invalid argument to built-in function" } */ +}