@@ -148,7 +148,7 @@ (define_insn "riscv_aes32dsi"
[(set (match_operand:SI 0 "register_operand" "=r")
(unspec:SI [(match_operand:SI 1 "register_operand" "r")
(match_operand:SI 2 "register_operand" "r")
- (match_operand:SI 3 "register_operand" "D03")]
+ (match_operand:SI 3 "const_0_3_operand" "D03")]
UNSPEC_AES_DSI))]
"TARGET_ZKND && !TARGET_64BIT"
"aes32dsi\t%0,%1,%2,%3"
@@ -158,7 +158,7 @@ (define_insn "riscv_aes32dsmi"
[(set (match_operand:SI 0 "register_operand" "=r")
(unspec:SI [(match_operand:SI 1 "register_operand" "r")
(match_operand:SI 2 "register_operand" "r")
- (match_operand:SI 3 "register_operand" "D03")]
+ (match_operand:SI 3 "const_0_3_operand" "D03")]
UNSPEC_AES_DSMI))]
"TARGET_ZKND && !TARGET_64BIT"
"aes32dsmi\t%0,%1,%2,%3"
@@ -214,7 +214,7 @@ (define_insn "riscv_aes32esi"
[(set (match_operand:SI 0 "register_operand" "=r")
(unspec:SI [(match_operand:SI 1 "register_operand" "r")
(match_operand:SI 2 "register_operand" "r")
- (match_operand:SI 3 "register_operand" "D03")]
+ (match_operand:SI 3 "const_0_3_operand" "D03")]
UNSPEC_AES_ESI))]
"TARGET_ZKNE && !TARGET_64BIT"
"aes32esi\t%0,%1,%2,%3"
@@ -224,7 +224,7 @@ (define_insn "riscv_aes32esmi"
[(set (match_operand:SI 0 "register_operand" "=r")
(unspec:SI [(match_operand:SI 1 "register_operand" "r")
(match_operand:SI 2 "register_operand" "r")
- (match_operand:SI 3 "register_operand" "D03")]
+ (match_operand:SI 3 "const_0_3_operand" "D03")]
UNSPEC_AES_ESMI))]
"TARGET_ZKNE && !TARGET_64BIT"
"aes32esmi\t%0,%1,%2,%3"
@@ -394,7 +394,7 @@ (define_insn "riscv_sm4ed_<mode>"
[(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_<mode>"
[(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"
@@ -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")))
new file mode 100644
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv32gc_zknd -mabi=ilp32d" } */
+/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
+
+#include <stdint-gcc.h>
+
+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 } } */
@@ -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" } */
+}
new file mode 100644
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv32gc_zkne -mabi=ilp32d" } */
+/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
+
+#include <stdint-gcc.h>
+
+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 } } */
@@ -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 } } */
new file mode 100644
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv32gc_zksed -mabi=ilp32" } */
+/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
+
+#include <stdint-gcc.h>
+
+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 } } */
@@ -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" } */
+}
new file mode 100644
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=rv64gc_zksed -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-g" "-flto"} } */
+
+#include <stdint-gcc.h>
+
+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 } } */
@@ -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" } */
+}
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 <jeffreyalaw@gmail.com> To: gcc-patches@gcc.gnu.org <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_<mode>, riscv_sm4ks_<mode): Likewise. gcc/testsuite * testsuite/gcc.target/riscv/zknd32.c: Verify diagnostics are issued for invalid builtin arguments. * testsuite/gcc.target/riscv/zkne32.c: Likewise. * testsuite/gcc.target/riscv/zksed32.c: Likewise. * testsuite/gcc.target/riscv/zksed64.c: Likewise. * testsuite/gcc.target/riscv/zknd32-2.c: New test. * testsuite/gcc.target/riscv/zkne32-2.c: Likewise. * testsuite/gcc.target/riscv/zksed32-2.c: Likewise. * testsuite/gcc.target/riscv/zksed64-2.c: Likewise.