public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/111725] New: Missed one vsetvl
@ 2023-10-08  8:06 lehua.ding at rivai dot ai
  2023-10-20  3:57 ` [Bug target/111725] Missed one vsetivli insn cvs-commit at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: lehua.ding at rivai dot ai @ 2023-10-08  8:06 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111725

            Bug ID: 111725
           Summary: Missed one vsetvl
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lehua.ding at rivai dot ai
  Target Milestone: ---

online: https://godbolt.org/z/br456cPs8
C Code (compiler option: -march=rv32gcv -mabi=ilp32d -S -fno-schedule-insns
-fno-schedule-insns2  -fno-tree-vectorize -frename-registers -O2):

#include "riscv_vector.h"

float f (int8_t * restrict in, int8_t * restrict out, int n, int m, unsigned
cond, size_t vl, float scalar)
{
  vbool64_t mask = *(vbool64_t*) (in + 1000000);

  for (size_t i = 0; i < n; i++)
    {
      vfloat32mf2_t v = __riscv_vle32_v_f32mf2 ((float *)(in + i + 200),
__riscv_vsetvlmax_e32mf2 ());
      __riscv_vse32_v_f32mf2 ((float *)(out + i + 200), v,
__riscv_vsetvlmax_e32mf2 ());

      vfloat32mf2_t v2 = __riscv_vle32_v_f32mf2_tumu (mask, v, (float *)(in + i
+ 300), __riscv_vsetvlmax_e32mf2 ());
      __riscv_vse32_v_f32mf2_m (mask, (float *)(out + i + 300), v2,
__riscv_vsetvlmax_e32mf2 ());
    }

  vfloat32m1_t v = *(vfloat32m1_t*)(in + 300000);
  for (size_t i = 0; i < n; i++)
    {
      v = __riscv_vfmv_s_f_f32m1_tu (v, (scalar + i), 3);
    }
  v = __riscv_vfadd_vv_f32m1 (v,v, 3);
  return __riscv_vfmv_f_s_f32m1_f32 (v);
}

Assembly Code:

f:
        li      a5,999424
        addi    t0,a5,576
        add     t1,a0,t0
        vsetvli a4,zero,e32,mf2,tu,mu
        vlm.v   v0,0(t1)
        beq     a2,zero,.L2
        addi    t5,a0,200
        addi    t6,a1,300
        addi    a6,a2,200
        add     t3,a0,a6
.L3:
        vle32.v v1,0(t5)
        addi    a3,t6,-100
        vse32.v v1,0(a3)
        addi    t4,t5,100
        vle32.v v1,0(t4),v0.t
        vse32.v v1,0(t6),v0.t
        addi    t5,t5,1
        addi    t6,t6,1
        bne     t5,t3,.L3
        li      a5,299008
        addi    t0,a5,992
        add     t1,a0,t0
        vl1re32.v       v2,0(t1)
        li      a4,0
.L6:
        fcvt.s.wu       fa5,a4
        fadd.s  ft0,fa5,fa0
        vfmv.s.f        v2,ft0
        addi    a4,a4,1
        bne     a4,a2,.L6
        vfadd.vv        v3,v2,v2 # Miss vsetivli zero,3,e32,m1,ta,ma
        vfmv.f.s        fa0,v3
        ret
.L2:
        li      t2,299008
        addi    a1,t2,992
        add     a0,a0,a1
        vl1re32.v       v2,0(a0)
        vsetivli        zero,3,e32,m1,ta,ma
        vfadd.vv        v3,v2,v2
        vfmv.f.s        fa0,v3
        ret

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/111725] Missed one vsetivli insn
  2023-10-08  8:06 [Bug target/111725] New: Missed one vsetvl lehua.ding at rivai dot ai
@ 2023-10-20  3:57 ` cvs-commit at gcc dot gnu.org
  2023-10-24  3:01 ` lehua.ding at rivai dot ai
  2023-10-25  6:20 ` lehua.ding at rivai dot ai
  2 siblings, 0 replies; 4+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-10-20  3:57 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111725

--- Comment #1 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The trunk branch has been updated by Lehua Ding <lhtin@gcc.gnu.org>:

https://gcc.gnu.org/g:29331e72d0ce9fe8aabdeb8c320b99943b9e067a

commit r14-4773-g29331e72d0ce9fe8aabdeb8c320b99943b9e067a
Author: Lehua Ding <lehua.ding@rivai.ai>
Date:   Fri Oct 20 10:22:43 2023 +0800

    RISC-V: Refactor and cleanup vsetvl pass

    This patch refactors and cleanups the vsetvl pass in order to make the code
    easier to modify and understand. This patch does several things:

    1. Introducing a virtual CFG for vsetvl infos and Phase 1, 2 and 3 only
maintain
       and modify this virtual CFG. Phase 4 performs insertion, modification
and
       deletion of vsetvl insns based on the virtual CFG. The basic block in
the
       virtual CFG is called vsetvl_block_info and the vsetvl information
inside
       is called vsetvl_info.
    2. Combine Phase 1 and 2 into a single Phase 1 and unified the demand
system,
       this phase only fuse local vsetvl info in forward direction.
    3. Refactor Phase 3, change the logic for determining whether to uplift
vsetvl
       info to a pred basic block to a more unified method that there is a
vsetvl
       info in the vsetvl defintion reaching in compatible with it.
    4. Place all modification operations to the RTL in Phase 4 and Phase 5.
       Phase 4 is responsible for inserting, modifying and deleting vsetvl
       instructions based on fully optimized vsetvl infos. Phase 5 removes the
avl
       operand from the RVV instruction and removes the unused dest operand
       register from the vsetvl insns.

    These modifications resulted in some testcases needing to be updated. The
reasons
    for updating are summarized below:

    1. more optimized
       vlmax_back_prop-{25,26}.c
       vlmax_conflict-{3,12}.c/vsetvl-{13,23}.c/vsetvl-23.c/
       avl_single-{23,84,95}.c/pr109773-1.c
    2. less unnecessary fusion
       avl_single-46.c/imm_bb_prop-1.c/pr109743-2.c/vsetvl-18.c
    3. local fuse direction (backward -> forward)
       scalar_move-1.c
    4. add some bugfix testcases.
       pr111037-{3,4}.c/pr111037-4.c
       avl_single-{89,104,105,106,107,108,109}.c

            PR target/111037
            PR target/111234
            PR target/111725

    gcc/ChangeLog:

            * config/riscv/riscv-vsetvl.cc (bitmap_union_of_preds_with_entry):
New.
            (debug): Removed.
            (compute_reaching_defintion): New.
            (enum vsetvl_type): Moved.
            (vlmax_avl_p): Moved.
            (enum emit_type): Moved.
            (vlmul_to_str): Moved.
            (vlmax_avl_insn_p): Removed.
            (policy_to_str): Moved.
            (loop_basic_block_p): Removed.
            (valid_sew_p): Removed.
            (vsetvl_insn_p): Moved.
            (vsetvl_vtype_change_only_p): Removed.
            (after_or_same_p): Removed.
            (before_p): Removed.
            (anticipatable_occurrence_p): Removed.
            (available_occurrence_p): Removed.
            (insn_should_be_added_p): Removed.
            (get_all_sets): Moved.
            (get_same_bb_set): Moved.
            (gen_vsetvl_pat): Removed.
            (calculate_vlmul): Moved.
            (get_max_int_sew): New.
            (emit_vsetvl_insn): Removed.
            (get_max_float_sew): New.
            (eliminate_insn): Removed.
            (insert_vsetvl): Removed.
            (count_regno_occurrences): Moved.
            (get_vl_vtype_info): Removed.
            (enum def_type): Moved.
            (validate_change_or_fail): Moved.
            (change_insn): Removed.
            (get_all_real_uses): Moved.
            (get_forward_read_vl_insn): Removed.
            (get_backward_fault_first_load_insn): Removed.
            (change_vsetvl_insn): Removed.
            (avl_source_has_vsetvl_p): Removed.
            (source_equal_p): Moved.
            (calculate_sew): Removed.
            (same_equiv_note_p): Moved.
            (get_expr_id): New.
            (incompatible_avl_p): Removed.
            (get_regno): New.
            (different_sew_p): Removed.
            (get_bb_index): New.
            (different_lmul_p): Removed.
            (has_no_uses): Moved.
            (different_ratio_p): Removed.
            (different_tail_policy_p): Removed.
            (different_mask_policy_p): Removed.
            (possible_zero_avl_p): Removed.
            (enum demand_flags): New.
            (second_ratio_invalid_for_first_sew_p): Removed.
            (second_ratio_invalid_for_first_lmul_p): Removed.
            (enum class): New.
            (float_insn_valid_sew_p): Removed.
            (second_sew_less_than_first_sew_p): Removed.
            (first_sew_less_than_second_sew_p): Removed.
            (class vsetvl_info): New.
            (compare_lmul): Removed.
            (second_lmul_less_than_first_lmul_p): Removed.
            (second_ratio_less_than_first_ratio_p): Removed.
            (DEF_INCOMPATIBLE_COND): Removed.
            (greatest_sew): Removed.
            (first_sew): Removed.
            (second_sew): Removed.
            (first_vlmul): Removed.
            (second_vlmul): Removed.
            (first_ratio): Removed.
            (second_ratio): Removed.
            (vlmul_for_first_sew_second_ratio): Removed.
            (vlmul_for_greatest_sew_second_ratio): Removed.
            (ratio_for_second_sew_first_vlmul): Removed.
            (class vsetvl_block_info): New.
            (DEF_SEW_LMUL_FUSE_RULE): New.
            (always_unavailable): Removed.
            (avl_unavailable_p): Removed.
            (class demand_system): New.
            (sew_unavailable_p): Removed.
            (lmul_unavailable_p): Removed.
            (ge_sew_unavailable_p): Removed.
            (ge_sew_lmul_unavailable_p): Removed.
            (ge_sew_ratio_unavailable_p): Removed.
            (DEF_UNAVAILABLE_COND): Removed.
            (same_sew_lmul_demand_p): Removed.
            (propagate_avl_across_demands_p): Removed.
            (reg_available_p): Removed.
            (support_relaxed_compatible_p): Removed.
            (demands_can_be_fused_p): Removed.
            (earliest_pred_can_be_fused_p): Removed.
            (vsetvl_dominated_by_p): Removed.
            (avl_info::avl_info): Removed.
            (avl_info::single_source_equal_p): Removed.
            (avl_info::multiple_source_equal_p): Removed.
            (DEF_SEW_LMUL_RULE): New.
            (avl_info::operator=): Removed.
            (avl_info::operator==): Removed.
            (DEF_POLICY_RULE): New.
            (avl_info::operator!=): Removed.
            (avl_info::has_non_zero_avl): Removed.
            (vl_vtype_info::vl_vtype_info): Removed.
            (vl_vtype_info::operator==): Removed.
            (DEF_AVL_RULE): New.
            (vl_vtype_info::operator!=): Removed.
            (vl_vtype_info::same_avl_p): Removed.
            (vl_vtype_info::same_vtype_p): Removed.
            (vl_vtype_info::same_vlmax_p): Removed.
            (vector_insn_info::operator>=): Removed.
            (vector_insn_info::operator==): Removed.
            (class pre_vsetvl): New.
            (vector_insn_info::parse_insn): Removed.
            (vector_insn_info::compatible_p): Removed.
            (vector_insn_info::skip_avl_compatible_p): Removed.
            (vector_insn_info::compatible_avl_p): Removed.
            (vector_insn_info::compatible_vtype_p): Removed.
            (vector_insn_info::available_p): Removed.
            (vector_insn_info::fuse_avl): Removed.
            (vector_insn_info::fuse_sew_lmul): Removed.
            (vector_insn_info::fuse_tail_policy): Removed.
            (vector_insn_info::fuse_mask_policy): Removed.
            (vector_insn_info::local_merge): Removed.
            (vector_insn_info::global_merge): Removed.
            (vector_insn_info::get_avl_or_vl_reg): Removed.
            (vector_insn_info::update_fault_first_load_avl): Removed.
            (vector_insn_info::dump): Removed.
            (vector_infos_manager::vector_infos_manager): Removed.
            (vector_infos_manager::create_expr): Removed.
            (vector_infos_manager::get_expr_id): Removed.
            (vector_infos_manager::all_same_ratio_p): Removed.
            (vector_infos_manager::all_avail_in_compatible_p): Removed.
            (vector_infos_manager::all_same_avl_p): Removed.
            (vector_infos_manager::expr_set_num): Removed.
            (vector_infos_manager::release): Removed.
            (vector_infos_manager::create_bitmap_vectors): Removed.
            (vector_infos_manager::free_bitmap_vectors): Removed.
            (vector_infos_manager::dump): Removed.
            (class pass_vsetvl): Adjust.
            (pass_vsetvl::get_vector_info): Removed.
            (pass_vsetvl::get_block_info): Removed.
            (pass_vsetvl::update_vector_info): Removed.
            (pass_vsetvl::update_block_info): Removed.
            (pre_vsetvl::compute_avl_def_data): New.
            (pass_vsetvl::simple_vsetvl): Removed.
            (pass_vsetvl::compute_local_backward_infos): Removed.
            (pass_vsetvl::need_vsetvl): Removed.
            (pass_vsetvl::transfer_before): Removed.
            (pass_vsetvl::transfer_after): Removed.
            (pre_vsetvl::compute_vsetvl_def_data): New.
            (pass_vsetvl::emit_local_forward_vsetvls): Removed.
            (pass_vsetvl::prune_expressions): Removed.
            (pass_vsetvl::compute_local_properties): Removed.
            (pre_vsetvl::compute_lcm_local_properties): New.
            (pass_vsetvl::earliest_fusion): Removed.
            (pre_vsetvl::fuse_local_vsetvl_info): New.
            (pass_vsetvl::vsetvl_fusion): Removed.
            (pass_vsetvl::can_refine_vsetvl_p): Removed.
            (pre_vsetvl::earliest_fuse_vsetvl_info): New.
            (pass_vsetvl::refine_vsetvls): Removed.
            (pass_vsetvl::cleanup_vsetvls): Removed.
            (pass_vsetvl::commit_vsetvls): Removed.
            (pass_vsetvl::pre_vsetvl): Removed.
            (pass_vsetvl::get_vsetvl_at_end): Removed.
            (local_avl_compatible_p): Removed.
            (pass_vsetvl::local_eliminate_vsetvl_insn): Removed.
            (pre_vsetvl::pre_global_vsetvl_info): New.
            (get_first_vsetvl_before_rvv_insns): Removed.
            (pass_vsetvl::global_eliminate_vsetvl_insn): Removed.
            (pre_vsetvl::emit_vsetvl): New.
            (pass_vsetvl::ssa_post_optimization): Removed.
            (pre_vsetvl::cleaup): New.
            (pre_vsetvl::remove_avl_operand): New.
            (pass_vsetvl::df_post_optimization): Removed.
            (pre_vsetvl::remove_unused_dest_operand): New.
            (pass_vsetvl::init): Removed.
            (pass_vsetvl::done): Removed.
            (pass_vsetvl::compute_probabilities): Removed.
            (pass_vsetvl::lazy_vsetvl): Adjust.
            (pass_vsetvl::execute): Adjust.
            * config/riscv/riscv-vsetvl.def (DEF_INCOMPATIBLE_COND): Removed.
            (DEF_SEW_LMUL_RULE): New.
            (DEF_SEW_LMUL_FUSE_RULE): Removed.
            (DEF_POLICY_RULE): New.
            (DEF_UNAVAILABLE_COND): Removed
            (DEF_AVL_RULE): New demand type.
            (sew_lmul): New demand type.
            (ratio_only): New demand type.
            (sew_only): New demand type.
            (ge_sew): New demand type.
            (ratio_and_ge_sew): New demand type.
            (tail_mask_policy): New demand type.
            (tail_policy_only): New demand type.
            (mask_policy_only): New demand type.
            (ignore_policy): New demand type.
            (avl): New demand type.
            (non_zero_avl): New demand type.
            (ignore_avl): New demand type.
            * config/riscv/t-riscv: Removed riscv-vsetvl.h
            * config/riscv/riscv-vsetvl.h: Removed.

    gcc/testsuite/ChangeLog:

            * gcc.target/riscv/rvv/base/scalar_move-1.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/avl_single-23.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/avl_single-46.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/avl_single-84.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/avl_single-89.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/avl_single-95.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/imm_bb_prop-1.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/pr109743-2.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/pr109773-1.c: Adjust.
            * gcc.target/riscv/rvv/base/pr111037-1.c: Moved to...
            * gcc.target/riscv/rvv/vsetvl/pr111037-1.c: ...here.
            * gcc.target/riscv/rvv/base/pr111037-2.c: Moved to...
            * gcc.target/riscv/rvv/vsetvl/pr111037-2.c: ...here.
            * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-25.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/vlmax_back_prop-26.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-12.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/vlmax_conflict-3.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/vsetvl-13.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/vsetvl-18.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/vsetvl-23.c: Adjust.
            * gcc.target/riscv/rvv/vsetvl/avl_single-104.c: New test.
            * gcc.target/riscv/rvv/vsetvl/avl_single-105.c: New test.
            * gcc.target/riscv/rvv/vsetvl/avl_single-106.c: New test.
            * gcc.target/riscv/rvv/vsetvl/avl_single-107.c: New test.
            * gcc.target/riscv/rvv/vsetvl/avl_single-108.c: New test.
            * gcc.target/riscv/rvv/vsetvl/avl_single-109.c: New test.
            * gcc.target/riscv/rvv/vsetvl/pr111037-3.c: New test.
            * gcc.target/riscv/rvv/vsetvl/pr111037-4.c: New test.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/111725] Missed one vsetivli insn
  2023-10-08  8:06 [Bug target/111725] New: Missed one vsetvl lehua.ding at rivai dot ai
  2023-10-20  3:57 ` [Bug target/111725] Missed one vsetivli insn cvs-commit at gcc dot gnu.org
@ 2023-10-24  3:01 ` lehua.ding at rivai dot ai
  2023-10-25  6:20 ` lehua.ding at rivai dot ai
  2 siblings, 0 replies; 4+ messages in thread
From: lehua.ding at rivai dot ai @ 2023-10-24  3:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111725

--- Comment #2 from Lehua Ding <lehua.ding at rivai dot ai> ---
Confirmed fix.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug target/111725] Missed one vsetivli insn
  2023-10-08  8:06 [Bug target/111725] New: Missed one vsetvl lehua.ding at rivai dot ai
  2023-10-20  3:57 ` [Bug target/111725] Missed one vsetivli insn cvs-commit at gcc dot gnu.org
  2023-10-24  3:01 ` lehua.ding at rivai dot ai
@ 2023-10-25  6:20 ` lehua.ding at rivai dot ai
  2 siblings, 0 replies; 4+ messages in thread
From: lehua.ding at rivai dot ai @ 2023-10-25  6:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111725

Lehua Ding <lehua.ding at rivai dot ai> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Lehua Ding <lehua.ding at rivai dot ai> ---
Fixed on trunk.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-10-25  6:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-08  8:06 [Bug target/111725] New: Missed one vsetvl lehua.ding at rivai dot ai
2023-10-20  3:57 ` [Bug target/111725] Missed one vsetivli insn cvs-commit at gcc dot gnu.org
2023-10-24  3:01 ` lehua.ding at rivai dot ai
2023-10-25  6:20 ` lehua.ding at rivai dot ai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).