From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 770B43858D32; Tue, 3 Jan 2023 01:51:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 770B43858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672710708; bh=c3qnDOlU0KwWs03s+uue35+meVe8L1ILW5U2rv7MsvE=; h=From:To:Subject:Date:From; b=krl3Av+KtsBD9YCZOillGhPgbRzK6MGGB8bAUzjnM+ZjBzCz5feZnSwrHarbOoRdp 9w7PRoOlQmN+8oIYw/KaalaVv7U2KcAiLREPIerZ6tFKFfzqMiodH7gF1jTzJge8IM XrIIS5nDbajaXnYUalTOyM1VgYbFkiKq3knB90vw= From: "juzhe.zhong at rivai dot ai" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108270] New: un-optimal vsetvl for multi-loop if avl is 0 ~ 31 immediate Date: Tue, 03 Jan 2023 01:51:48 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: juzhe.zhong at rivai dot ai X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108270 Bug ID: 108270 Summary: un-optimal vsetvl for multi-loop if avl is 0 ~ 31 immediate Product: gcc Version: 13.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: --- Consider this following case: #include "riscv_vector.h" void f1 (void * restrict in, void * restrict out, int l, int n, int m) { for (int i =3D 0; i < l; i++){ for (int j =3D 0; j < m; j++){ for (int k =3D 0; k < n; k++) { vint8mf8_t v =3D __riscv_vle8_v_i8mf8 (in + i + j, 17); __riscv_vse8_v_i8mf8 (out + i + j, v, 17); } } } } GCC ASM: f1: 0: mv a7,a2 1: mv a6,a0 2: mv t1,a1 3: mv a2,a3 4: vsetivli zero,17,e8,mf8,ta,ma 5: ble a7,zero,.L1 6: ble a4,zero,.L1 7: ble a3,zero,.L1 8: add a1,a0,a4 9: li a0,0 10:.L4: 11: add a3,a6,a0 12: add a4,t1,a0 13:.L7: 14: li a5,0 15:.L5: 16: vle8.v v24,0(a3) 17: addiw a5,a5,1 18: vse8.v v24,0(a4) 19: bne a2,a5,.L5 20: addi a3,a3,1 21: addi a4,a4,1 22: bne a3,a1,.L7 23: addi a0,a0,1 24: addi a1,a1,1 25: bne a0,a7,.L4 26:.L1: 27: ret The vsetivli instruction is hoisted too early. The best location of vsetivli should be any point from 8 to 9.=