https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112999
Bug ID: 112999 Summary: riscv: Infinite loop with mask extraction Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: rdapp at gcc dot gnu.org CC: juzhe.zhong at rivai dot ai, pan2.li at intel dot com Target Milestone: --- Target: riscv Pan Li found the following problematic case in his "full-coverage" testing and I'm just documenting it here for reference. /* { dg-do compile } */ /* { dg-options "-march=rv64gcv_zvl512b -mabi=lp64d --param=riscv-autovec-lmul=m8 --param=riscv-autovec-preference=fixed-vlmax -O3 -fno-vect-cost-model -fno-tree-loop-distribute-patterns" } */ int a[1024]; int b[1024]; _Bool fn1 () { _Bool tem; for (int i = 0; i < 1024; ++i) { tem = !a[i]; b[i] = tem; } return tem; } We try to extract the last bit from a 128-bit value of a mask vector. In order to do so we first subreg by a tieable vector mode (here RVVMF4QI) then, because we do not have a RVVMF4QI -> BI vector extraction, try type punning with a TImode subreg. As we do not natively support TImode, the result needs to be subreg'd again to DImode. In the course of doing so we get lost in subreg moves and hit an infinite loop. I have not tracked down the real root cause but the problem is fixed by providing a movti pattern and special casing subreg:TI extraction from vectors (just like we do in legitimize_move for other scalar subregs of vectors - and wich I don't particularly like either :) ).