RISC-V: Postpone full available optimization [VSETVL PASS]

Fix VSETVL BUG that AVL is polluted

.L15:
        li      a3,9
        lui     a4,%hi(s)
        sw      a3,%lo(j)(t2)
        sh      a5,%lo(s)(a4) <--a4 is hold the address of s
        beq     t0,zero,.L42
        sw      t5,8(t4)
        vsetvli zero,a4,e8,m8,ta,ma  <<--- a4 as avl

Actually, this vsetvl is redundant.
The root cause we include full available optimization in LCM local data computation.

full available optimization should be after LCM computation.

	PR target/112929
	PR target/112988

gcc/ChangeLog:

	* config/riscv/riscv-vsetvl.cc
	(pre_vsetvl::compute_lcm_local_properties): Remove full available.
	(pre_vsetvl::pre_global_vsetvl_info): Add full available optimization.

gcc/testsuite/ChangeLog:

	* gcc.target/riscv/rvv/vsetvl/pr112929.c: New test.
	* gcc.target/riscv/rvv/vsetvl/pr112988.c: New test.
This commit is contained in:
Juzhe-Zhong 2023-12-13 13:48:11 +08:00 committed by Pan Li
parent 90be333ad5
commit ef21ae5c45
3 changed files with 139 additions and 2 deletions

View file

@ -2723,8 +2723,7 @@ pre_vsetvl::compute_lcm_local_properties ()
vsetvl_info &header_info = block_info.get_entry_info ();
vsetvl_info &footer_info = block_info.get_exit_info ();
if (header_info.valid_p ()
&& (anticipated_exp_p (header_info) || block_info.full_available))
if (header_info.valid_p () && anticipated_exp_p (header_info))
bitmap_set_bit (m_antloc[bb_index],
get_expr_index (m_exprs, header_info));
@ -3224,6 +3223,17 @@ pre_vsetvl::pre_global_vsetvl_info ()
info.set_delete ();
}
/* Remove vsetvl infos if all precessors are available to the block. */
for (const bb_info *bb : crtl->ssa->bbs ())
{
vsetvl_block_info &block_info = get_block_info (bb);
if (block_info.empty_p () || !block_info.full_available)
continue;
vsetvl_info &info = block_info.get_entry_info ();
info.set_delete ();
}
for (const bb_info *bb : crtl->ssa->bbs ())
{
vsetvl_block_info &block_info = get_block_info (bb);

View file

@ -0,0 +1,58 @@
/* { dg-do compile } */
/* { dg-options "-march=rv64gcv -mabi=lp64d -O3" } */
int printf(char *, ...);
int a, l, i, p, q, t, n, o;
int *volatile c;
static int j;
static struct pack_1_struct d;
long e;
char m = 5;
short s;
#pragma pack(1)
struct pack_1_struct {
long c;
int d;
int e;
int f;
int g;
int h;
int i;
} h, r = {1}, *f = &h, *volatile g;
void add_em_up(int count, ...) {
__builtin_va_list ap;
__builtin_va_start(ap, count);
__builtin_va_end(ap);
}
int main() {
int u;
j = 0;
for (; j < 9; ++j) {
u = ++t ? a : 0;
if (u) {
int *v = &d.d;
*v = g || e;
*c = 0;
*f = h;
}
s = l && c;
o = i;
d.f || (p = 0);
q |= n;
}
r = *f;
add_em_up(1, 1);
printf("%d\n", m);
}
/* { dg-final { scan-assembler-times {vsetvli} 2 { target { no-opts "-O0" no-opts "-Os" no-opts "-Oz" no-opts "-funroll-loops" no-opts "-g" } } } } */
/* { dg-final { scan-assembler-not {vsetivli} } } */
/* { dg-final { scan-assembler-times {vsetvli\tzero,\s*[a-x0-9]+,\s*e8,\s*m8,\s*t[au],\s*m[au]} 2 { target { no-opts "-O0" no-opts "-Os" no-opts "-Oz" no-opts "-funroll-loops" no-opts "-g" } } } } */
/* { dg-final { scan-assembler-times {li\t[a-x0-9]+,\s*32} 2 { target { no-opts "-O0" no-opts "-Os" no-opts "-Oz" no-opts "-funroll-loops" no-opts "-g" } } } } */

View file

@ -0,0 +1,69 @@
/* { dg-do compile } */
/* { dg-options "-march=rv64gcv -mabi=lp64d -O3" } */
int a = 0;
int p, q, r, x = 230;
short d;
int e[256];
static struct f w;
int *c = &r;
short y(short z) {
return z * d;
}
#pragma pack(1)
struct f {
int g;
short h;
int j;
char k;
char l;
long m;
long n;
int o;
} s = {1}, v, t, *u = &v, *b = &s;
void add_em_up(int count, ...) {
__builtin_va_list ap;
__builtin_va_start(ap, count);
__builtin_va_end(ap);
}
int main() {
int i = 0;
for (; i < 256; i++)
e[i] = i;
p = 0;
for (; p <= 0; p++) {
*c = 4;
*u = t;
x |= y(6 >= q);
}
*b = w;
add_em_up(1, 1);
if (a != 0)
return 1;
if (q != 0)
return 2;
if (p != 1)
return 3;
if (r != 4)
return 4;
if (x != 0xE6)
return 5;
if (d != 0)
return 6;
return 0;
}
/* { dg-final { scan-assembler-times {vsetvli} 1 } } */
/* { dg-final { scan-assembler-times {vsetivli} 1 } } */
/* { dg-final { scan-assembler-times {vsetivli\tzero,\s*4,\s*e32,\s*m1,\s*t[au],\s*m[au]} 1 } } */
/* { dg-final { scan-assembler-times {vsetvli\tzero,\s*[a-x0-9]+,\s*e8,\s*m8,\s*t[au],\s*m[au]} 1 } } */
/* { dg-final { scan-assembler-times {li\t[a-x0-9]+,\s*32} 1 } } */