[v2] RISC-V: Fix vsetvl compatibility predicate [PR118154].
Checks
| Context |
Check |
Description |
| rivoscibot/toolchain-ci-rivos-lint |
success
|
Lint passed
|
| rivoscibot/toolchain-ci-rivos-apply-patch |
success
|
Patch applied
|
| rivoscibot/toolchain-ci-rivos-build--newlib-rv64gcv-lp64d-multilib |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gcc_build--master-arm |
success
|
Build passed
|
| rivoscibot/toolchain-ci-rivos-build--linux-rv64gc_zba_zbb_zbc_zbs-lp64d-multilib |
success
|
Build passed
|
| rivoscibot/toolchain-ci-rivos-build--linux-rv64gcv-lp64d-multilib |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_gcc_check--master-arm |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 |
success
|
Build passed
|
| rivoscibot/toolchain-ci-rivos-test |
success
|
Testing passed
|
| linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 |
fail
|
Patch failed to apply
|
Commit Message
Hi,
in PR118154 we emit strided stores but the first of those does not
always have the proper VTYPE. That's because we erroneously delete
a necessary vsetvl.
In order to determine whether to elide
(1)
Expr[7]: VALID (insn 116, bb 17)
Demand fields: demand_ratio_and_ge_sew demand_avl
SEW=8, VLMUL=mf2, RATIO=16, MAX_SEW=64
TAIL_POLICY=agnostic, MASK_POLICY=agnostic
AVL=(reg:DI 0 zero)
when e.g.
(2)
Expr[3]: VALID (insn 360, bb 15)
Demand fields: demand_sew_lmul demand_avl
SEW=64, VLMUL=m1, RATIO=64, MAX_SEW=64
TAIL_POLICY=agnostic, MASK_POLICY=agnostic
AVL=(reg:DI 0 zero)
VL=(reg:DI 13 a3 [345])
is already available, we use
sew_ge_and_prev_sew_le_next_max_sew_and_next_ratio_valid_for_prev_sew_p.
(1) requires RATIO = SEW/LMUL = 16 and an SEW >= 8. (2) has ratio = 64,
though, so we cannot directly elide (1).
This patch uses ratio_eq_p instead of next_ratio_valid_for_prev_sew_p.
Regtested on rv64gcv_zvl512b.
Regards
Robin
PR target/118154
gcc/ChangeLog:
* config/riscv/riscv-vsetvl.cc (MAX_LMUL): New define.
(pre_vsetvl::earliest_fuse_vsetvl_info): Use.
(pre_vsetvl::pre_global_vsetvl_info): New predicate with equal
ratio.
* config/riscv/riscv-vsetvl.def: Use.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/pr118154-1.c: New test.
* gcc.target/riscv/rvv/autovec/pr118154-2.c: New test.
---
gcc/config/riscv/riscv-vsetvl.cc | 14 +++++++--
gcc/config/riscv/riscv-vsetvl.def | 4 +--
.../gcc.target/riscv/rvv/autovec/pr118154-1.c | 23 ++++++++++++++
.../gcc.target/riscv/rvv/autovec/pr118154-2.c | 31 +++++++++++++++++++
4 files changed, 67 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118154-1.c
create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118154-2.c
Comments
LGTM
juzhe.zhong@rivai.ai
From: Robin Dapp
Date: 2025-01-14 16:19
To: gcc-patches
CC: palmer@dabbelt.com; kito.cheng@gmail.com; juzhe.zhong@rivai.ai; jeffreyalaw@gmail.com; pan2.li@intel.com; rdapp.gcc@gmail.com
Subject: [PATCH v2] RISC-V: Fix vsetvl compatibility predicate [PR118154].
Hi,
in PR118154 we emit strided stores but the first of those does not
always have the proper VTYPE. That's because we erroneously delete
a necessary vsetvl.
In order to determine whether to elide
(1)
Expr[7]: VALID (insn 116, bb 17)
Demand fields: demand_ratio_and_ge_sew demand_avl
SEW=8, VLMUL=mf2, RATIO=16, MAX_SEW=64
TAIL_POLICY=agnostic, MASK_POLICY=agnostic
AVL=(reg:DI 0 zero)
when e.g.
(2)
Expr[3]: VALID (insn 360, bb 15)
Demand fields: demand_sew_lmul demand_avl
SEW=64, VLMUL=m1, RATIO=64, MAX_SEW=64
TAIL_POLICY=agnostic, MASK_POLICY=agnostic
AVL=(reg:DI 0 zero)
VL=(reg:DI 13 a3 [345])
is already available, we use
sew_ge_and_prev_sew_le_next_max_sew_and_next_ratio_valid_for_prev_sew_p.
(1) requires RATIO = SEW/LMUL = 16 and an SEW >= 8. (2) has ratio = 64,
though, so we cannot directly elide (1).
This patch uses ratio_eq_p instead of next_ratio_valid_for_prev_sew_p.
Regtested on rv64gcv_zvl512b.
Regards
Robin
PR target/118154
gcc/ChangeLog:
* config/riscv/riscv-vsetvl.cc (MAX_LMUL): New define.
(pre_vsetvl::earliest_fuse_vsetvl_info): Use.
(pre_vsetvl::pre_global_vsetvl_info): New predicate with equal
ratio.
* config/riscv/riscv-vsetvl.def: Use.
gcc/testsuite/ChangeLog:
* gcc.target/riscv/rvv/autovec/pr118154-1.c: New test.
* gcc.target/riscv/rvv/autovec/pr118154-2.c: New test.
---
gcc/config/riscv/riscv-vsetvl.cc | 14 +++++++--
gcc/config/riscv/riscv-vsetvl.def | 4 +--
.../gcc.target/riscv/rvv/autovec/pr118154-1.c | 23 ++++++++++++++
.../gcc.target/riscv/rvv/autovec/pr118154-2.c | 31 +++++++++++++++++++
4 files changed, 67 insertions(+), 5 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118154-1.c
create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118154-2.c
diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc
index e9de21787dd..a4016beebc0 100644
--- a/gcc/config/riscv/riscv-vsetvl.cc
+++ b/gcc/config/riscv/riscv-vsetvl.cc
@@ -223,6 +223,8 @@ enum emit_type
EMIT_AFTER,
};
+static const int MAX_LMUL = 8;
+
/* dump helper functions */
static const char *
vlmul_to_str (vlmul_type vlmul)
@@ -1445,14 +1447,13 @@ private:
inline bool prev_ratio_valid_for_next_sew_p (const vsetvl_info &prev,
const vsetvl_info &next)
{
- return prev.get_ratio () >= (next.get_sew () / 8);
+ return prev.get_ratio () >= (next.get_sew () / MAX_LMUL);
}
inline bool next_ratio_valid_for_prev_sew_p (const vsetvl_info &prev,
const vsetvl_info &next)
{
- return next.get_ratio () >= (prev.get_sew () / 8);
+ return next.get_ratio () >= (prev.get_sew () / MAX_LMUL);
}
-
inline bool sew_ge_and_ratio_eq_p (const vsetvl_info &prev,
const vsetvl_info &next)
{
@@ -1470,6 +1471,13 @@ private:
return sew_ge_p (prev, next) && prev_sew_le_next_max_sew_p (prev, next)
&& next_ratio_valid_for_prev_sew_p (prev, next);
}
+ inline bool
+ sew_ge_and_prev_sew_le_next_max_sew_and_ratio_eq_p (
+ const vsetvl_info &prev, const vsetvl_info &next)
+ {
+ return sew_ge_p (prev, next) && prev_sew_le_next_max_sew_p (prev, next)
+ && ratio_eq_p (prev, next);
+ }
inline bool sew_le_and_next_sew_le_prev_max_sew_p (const vsetvl_info &prev,
const vsetvl_info &next)
{
diff --git a/gcc/config/riscv/riscv-vsetvl.def b/gcc/config/riscv/riscv-vsetvl.def
index 2dfff71d987..d7a5ada772d 100644
--- a/gcc/config/riscv/riscv-vsetvl.def
+++ b/gcc/config/riscv/riscv-vsetvl.def
@@ -53,8 +53,8 @@ DEF_SEW_LMUL_RULE (sew_lmul, ge_sew, sew_lmul,
sew_ge_and_prev_sew_le_next_max_sew_p, nop)
DEF_SEW_LMUL_RULE (
sew_lmul, ratio_and_ge_sew, sew_lmul,
- sew_ge_and_prev_sew_le_next_max_sew_and_next_ratio_valid_for_prev_sew_p,
- sew_ge_and_prev_sew_le_next_max_sew_and_next_ratio_valid_for_prev_sew_p, nop)
+ sew_ge_and_prev_sew_le_next_max_sew_and_ratio_eq_p,
+ sew_ge_and_prev_sew_le_next_max_sew_and_ratio_eq_p, nop)
DEF_SEW_LMUL_RULE (ratio_only, sew_lmul, sew_lmul, ratio_eq_p, always_false,
use_next_sew_lmul)
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118154-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118154-1.c
new file mode 100644
index 00000000000..55386568a5f
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118154-1.c
@@ -0,0 +1,23 @@
+/* { dg-do run } */
+/* { dg-require-effective-target riscv_v_ok } */
+/* { dg-add-options riscv_v } */
+/* { dg-additional-options "-std=gnu99 -Wno-pedantic" } */
+
+long a;
+char b;
+char c[22][484];
+int main() {
+ for (int e = 4; e < 33; e++) {
+ for (int f = 0; f < 3; f++)
+ for (int g = 0; g < 18; g++) {
+ c[f][g * 22] = 1;
+ a = ({ a > 1 ? a : 1; });
+ }
+ for (int i = 0; i < 33; i++)
+ for (int h = 0; h < 6; h++)
+ for (int j = 0; j < 17; j++)
+ b = ({ b > 17 ? b : 17; });
+ }
+ if (c[1][44] != 1)
+ __builtin_abort ();
+}
diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118154-2.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118154-2.c
new file mode 100644
index 00000000000..4172f292994
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/pr118154-2.c
@@ -0,0 +1,31 @@
+/* { dg-do run } */
+/* { dg-require-effective-target riscv_v_ok } */
+/* { dg-add-options riscv_v } */
+/* { dg-additional-options "-std=gnu99 -Wno-pedantic" } */
+
+long a;
+signed char b;
+long long d;
+signed char c[22][22][484];
+void m(long long *l, int n) { *l ^= n + (*l >> 2); }
+int main() {
+ signed char l = 35;
+ for (signed char f = 4; f; f++) {
+ for (signed g = 0; g < 022; g += 4)
+ for (signed char h = 0; h < 022; h++) {
+ c[9][g][h * 22 + h] = l;
+ a = ({ a > 4095 ? a : 4095; });
+ }
+ for (int i = 0; i < 22; i += 3)
+ for (signed char j = 1; j; j++)
+ for (signed char k = 0; k < 022; k++)
+ b = ({ b > 19 ? b : 19; });
+ }
+ for (long f = 0; f < 22; ++f)
+ for (long g = 0; g < 22; ++g)
+ for (long h = 0; h < 22; ++h)
+ for (long i = 0; i < 22; ++i)
+ m(&d, c[f][g][h * 2 + i]);
+ if (d != 38)
+ __builtin_abort ();
+}
--
2.47.1
@@ -223,6 +223,8 @@ enum emit_type
EMIT_AFTER,
};
+static const int MAX_LMUL = 8;
+
/* dump helper functions */
static const char *
vlmul_to_str (vlmul_type vlmul)
@@ -1445,14 +1447,13 @@ private:
inline bool prev_ratio_valid_for_next_sew_p (const vsetvl_info &prev,
const vsetvl_info &next)
{
- return prev.get_ratio () >= (next.get_sew () / 8);
+ return prev.get_ratio () >= (next.get_sew () / MAX_LMUL);
}
inline bool next_ratio_valid_for_prev_sew_p (const vsetvl_info &prev,
const vsetvl_info &next)
{
- return next.get_ratio () >= (prev.get_sew () / 8);
+ return next.get_ratio () >= (prev.get_sew () / MAX_LMUL);
}
-
inline bool sew_ge_and_ratio_eq_p (const vsetvl_info &prev,
const vsetvl_info &next)
{
@@ -1470,6 +1471,13 @@ private:
return sew_ge_p (prev, next) && prev_sew_le_next_max_sew_p (prev, next)
&& next_ratio_valid_for_prev_sew_p (prev, next);
}
+ inline bool
+ sew_ge_and_prev_sew_le_next_max_sew_and_ratio_eq_p (
+ const vsetvl_info &prev, const vsetvl_info &next)
+ {
+ return sew_ge_p (prev, next) && prev_sew_le_next_max_sew_p (prev, next)
+ && ratio_eq_p (prev, next);
+ }
inline bool sew_le_and_next_sew_le_prev_max_sew_p (const vsetvl_info &prev,
const vsetvl_info &next)
{
@@ -53,8 +53,8 @@ DEF_SEW_LMUL_RULE (sew_lmul, ge_sew, sew_lmul,
sew_ge_and_prev_sew_le_next_max_sew_p, nop)
DEF_SEW_LMUL_RULE (
sew_lmul, ratio_and_ge_sew, sew_lmul,
- sew_ge_and_prev_sew_le_next_max_sew_and_next_ratio_valid_for_prev_sew_p,
- sew_ge_and_prev_sew_le_next_max_sew_and_next_ratio_valid_for_prev_sew_p, nop)
+ sew_ge_and_prev_sew_le_next_max_sew_and_ratio_eq_p,
+ sew_ge_and_prev_sew_le_next_max_sew_and_ratio_eq_p, nop)
DEF_SEW_LMUL_RULE (ratio_only, sew_lmul, sew_lmul, ratio_eq_p, always_false,
use_next_sew_lmul)
new file mode 100644
@@ -0,0 +1,23 @@
+/* { dg-do run } */
+/* { dg-require-effective-target riscv_v_ok } */
+/* { dg-add-options riscv_v } */
+/* { dg-additional-options "-std=gnu99 -Wno-pedantic" } */
+
+long a;
+char b;
+char c[22][484];
+int main() {
+ for (int e = 4; e < 33; e++) {
+ for (int f = 0; f < 3; f++)
+ for (int g = 0; g < 18; g++) {
+ c[f][g * 22] = 1;
+ a = ({ a > 1 ? a : 1; });
+ }
+ for (int i = 0; i < 33; i++)
+ for (int h = 0; h < 6; h++)
+ for (int j = 0; j < 17; j++)
+ b = ({ b > 17 ? b : 17; });
+ }
+ if (c[1][44] != 1)
+ __builtin_abort ();
+}
new file mode 100644
@@ -0,0 +1,31 @@
+/* { dg-do run } */
+/* { dg-require-effective-target riscv_v_ok } */
+/* { dg-add-options riscv_v } */
+/* { dg-additional-options "-std=gnu99 -Wno-pedantic" } */
+
+long a;
+signed char b;
+long long d;
+signed char c[22][22][484];
+void m(long long *l, int n) { *l ^= n + (*l >> 2); }
+int main() {
+ signed char l = 35;
+ for (signed char f = 4; f; f++) {
+ for (signed g = 0; g < 022; g += 4)
+ for (signed char h = 0; h < 022; h++) {
+ c[9][g][h * 22 + h] = l;
+ a = ({ a > 4095 ? a : 4095; });
+ }
+ for (int i = 0; i < 22; i += 3)
+ for (signed char j = 1; j; j++)
+ for (signed char k = 0; k < 022; k++)
+ b = ({ b > 19 ? b : 19; });
+ }
+ for (long f = 0; f < 22; ++f)
+ for (long g = 0; g < 22; ++g)
+ for (long h = 0; h < 22; ++h)
+ for (long i = 0; i < 22; ++i)
+ m(&d, c[f][g][h * 2 + i]);
+ if (d != 38)
+ __builtin_abort ();
+}