forked from ruyisdk/riscv-gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RISC-V: Add conditional sqrt autovec pattern
This patch adds a combined pattern for combining vfsqrt.v and vcond_mask. gcc/ChangeLog: * config/riscv/autovec-opt.md (*cond_<optab><mode>): Add sqrt + vcond_mask combine pattern. * config/riscv/autovec.md (<optab><mode>2): Change define_expand to define_insn_and_split. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/cond/cond_sqrt-1.c: New test. * gcc.target/riscv/rvv/autovec/cond/cond_sqrt-2.c: New test. * gcc.target/riscv/rvv/autovec/cond/cond_sqrt_run-1.c: New test. * gcc.target/riscv/rvv/autovec/cond/cond_sqrt_run-2.c: New test.
- Loading branch information
1 parent
845dbaa
commit d4554ae
Showing
6 changed files
with
131 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
gcc/testsuite/gcc.target/riscv/rvv/autovec/cond/cond_sqrt-1.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* { dg-do compile } */ | ||
/* { dg-additional-options "-march=rv64gcv_zvfh -mabi=lp64d --param riscv-autovec-preference=scalable -fno-vect-cost-model -ffast-math" } */ | ||
|
||
#include <stdint.h> | ||
|
||
#define DEF_LOOP(TYPE, OP) \ | ||
void __attribute__ ((noipa)) \ | ||
test_##TYPE##_##OP (TYPE *__restrict r, TYPE *__restrict a, \ | ||
TYPE *__restrict pred, int n) \ | ||
{ \ | ||
for (int i = 0; i < n; ++i) \ | ||
r[i] = pred[i] ? OP (a[i]) : a[i]; \ | ||
} | ||
|
||
#define TEST_ALL(T) \ | ||
T (_Float16, __builtin_sqrtf16) \ | ||
T (float, __builtin_sqrtf) \ | ||
T (double, __builtin_sqrt) | ||
|
||
TEST_ALL (DEF_LOOP) | ||
|
||
/* { dg-final { scan-assembler-times {\tvfsqrt\.v\tv[0-9]+,v[0-9]+,v0\.t} 3 } } */ | ||
|
||
/* { dg-final { scan-assembler {\tvsetvli\t[a-z0-9]+,[a-z0-9]+,e[0-9]+,m[f0-9]+,t[au],mu} } } */ |
24 changes: 24 additions & 0 deletions
24
gcc/testsuite/gcc.target/riscv/rvv/autovec/cond/cond_sqrt-2.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* { dg-do compile } */ | ||
/* { dg-additional-options "-march=rv64gcv_zvfh -mabi=lp64d --param riscv-autovec-preference=scalable -fno-vect-cost-model -ffast-math" } */ | ||
|
||
#include <stdint.h> | ||
|
||
#define DEF_LOOP(TYPE, OP) \ | ||
void __attribute__ ((noipa)) \ | ||
test_##TYPE##_##OP (TYPE *__restrict r, TYPE *__restrict a, \ | ||
TYPE *__restrict b, TYPE *__restrict pred, int n) \ | ||
{ \ | ||
for (int i = 0; i < n; ++i) \ | ||
r[i] = pred[i] ? OP (a[i]) : b[i]; \ | ||
} | ||
|
||
#define TEST_ALL(T) \ | ||
T (_Float16, __builtin_sqrtf16) \ | ||
T (float, __builtin_sqrtf) \ | ||
T (double, __builtin_sqrt) | ||
|
||
TEST_ALL (DEF_LOOP) | ||
|
||
/* { dg-final { scan-assembler-times {\tvfsqrt\.v\tv[0-9]+,v[0-9]+,v0\.t} 3 } } */ | ||
|
||
/* { dg-final { scan-assembler {\tvsetvli\t[a-z0-9]+,[a-z0-9]+,e[0-9]+,m[f0-9]+,t[au],mu} } } */ |
29 changes: 29 additions & 0 deletions
29
gcc/testsuite/gcc.target/riscv/rvv/autovec/cond/cond_sqrt_run-1.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* { dg-do run { target { riscv_vector } } } */ | ||
/* { dg-additional-options "--param riscv-autovec-preference=scalable -fno-vect-cost-model -ffast-math " } */ | ||
|
||
#include "cond_sqrt-1.c" | ||
#include <stdio.h> | ||
|
||
#define N 99 | ||
|
||
#define TEST_LOOP(TYPE, OP) \ | ||
{ \ | ||
TYPE r[N], a[N], pred[N]; \ | ||
for (int i = 0; i < N; ++i) \ | ||
{ \ | ||
a[i] = (i & 1 ? i : 3 * i) * (i % 3 == 0 ? 1 : 2); \ | ||
pred[i] = (i % 7 < 4); \ | ||
asm volatile("" ::: "memory"); \ | ||
} \ | ||
test_##TYPE##_##OP (r, a, pred, N); \ | ||
for (int i = 0; i < N; ++i) \ | ||
if (r[i] != (pred[i] ? OP (a[i]) : a[i])) \ | ||
__builtin_abort (); \ | ||
} | ||
|
||
int | ||
main () | ||
{ | ||
TEST_ALL (TEST_LOOP) | ||
return 0; | ||
} |
29 changes: 29 additions & 0 deletions
29
gcc/testsuite/gcc.target/riscv/rvv/autovec/cond/cond_sqrt_run-2.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* { dg-do run { target { riscv_vector } } } */ | ||
/* { dg-additional-options "--param riscv-autovec-preference=scalable -fno-vect-cost-model -ffast-math" } */ | ||
|
||
#include "cond_sqrt-2.c" | ||
|
||
#define N 99 | ||
|
||
#define TEST_LOOP(TYPE, OP) \ | ||
{ \ | ||
TYPE r[N], a[N], b[N], pred[N]; \ | ||
for (int i = 0; i < N; ++i) \ | ||
{ \ | ||
a[i] = (i & 1 ? i : 3 * i) * (i % 3 == 0 ? 1 : 2); \ | ||
b[i] = (i % 9) * (i % 7 + 1); \ | ||
pred[i] = (i % 7 < 4); \ | ||
asm volatile("" ::: "memory"); \ | ||
} \ | ||
test_##TYPE##_##OP (r, a, b, pred, N); \ | ||
for (int i = 0; i < N; ++i) \ | ||
if (r[i] != (pred[i] ? OP (a[i]) : b[i])) \ | ||
__builtin_abort (); \ | ||
} | ||
|
||
int | ||
main () | ||
{ | ||
TEST_ALL (TEST_LOOP) | ||
return 0; | ||
} |