https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113474
Bug ID: 113474
Summary: RISC-V: Fail to use vmerge.vim for constant vector
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: juzhe.zhong at rivai dot ai
Target Milestone: ---
void
foo (int n, int **__restrict a)
{
int b;
int c;
int d;
for (b = 0; b < n; b++)
for (long e = 8; e > 0; e--)
a[b][e] = a[b][e] == 15;
}
ASM:
foo:
ble a0,zero,.L5
slli a3,a0,3
add a3,a1,a3
vsetivli zero,4,e32,m1,ta,ma
vmv.v.i v3,1 -> redundant
vmv.v.i v2,0
.L3:
ld a5,0(a1)
addi a4,a5,4
addi a5,a5,20
vle32.v v1,0(a5)
vle32.v v0,0(a4)
vmseq.vi v0,v0,15
vmerge.vvm v4,v2,v3,v0 ----> It should be vmerge.vim
vse32.v v4,0(a4)
vmseq.vi v0,v1,15
addi a1,a1,8
vmerge.vvm v1,v2,v3,v0 ----> It should be vmerge.vim
vse32.v v1,0(a5)
bne a1,a3,.L3
.L5:
ret
It's odd we can generate vmseq.vi but fail to generate vmerge.vim.
Look into patterns of vcond_mask:
(define_insn_and_split "vcond_mask_<mode><vm>"
[(set (match_operand:V_VLS 0 "register_operand")
(if_then_else:V_VLS
(match_operand:<VM> 3 "register_operand")
(match_operand:V_VLS 1 "nonmemory_operand") -> relax the predicate
(match_operand:V_VLS 2 "register_operand")))]
Why GCC doesn't fold const_vector into operand 1 ?