]> gcc.gnu.org Git - gcc.git/commitdiff
RISC-V: Fix bugs of handling scalar of SEW64 vx instruction in RV32
authorJuzhe-Zhong <juzhe.zhong@rivai.ai>
Sat, 28 Oct 2023 02:05:07 +0000 (10:05 +0800)
committerJeff Law <jlaw@ventanamicro.com>
Mon, 30 Oct 2023 18:07:12 +0000 (12:07 -0600)
sew64_scalar_helper is handling SEW64 vx instruction pattern on RV32 system.
According to RVV ISA, we can directly use vx instruction of SEW64 on RV32 system
since RV32 GR reg is 32bit.

Consider this following case:

vsetvl e64m1
vadd.vx v,v,x

will be transform by sew64_scalar_helper:

vsetvl e64m1
sw
sw
vlse v
vadd.vv

This bug is reported by Robin.
(insn 143 179 230 9 (set (reg:SI 15 a5 [234])
        (unspec:SI [
                (const_int 64 [0x40])
            ] UNSPEC_VLMAX)) 751 {vlmax_avlsi}
     (expr_list:REG_EQUIV (unspec:SI [
                (const_int 64 [0x40])
            ] UNSPEC_VLMAX)
        (nil)))
(insn 230 143 78 9 (parallel [
            (set (reg:SI 66 vl)
                (unspec:SI [
                        (reg:SI 15 a5 [234])
                        (const_int 64 [0x40])
                        (const_int 0 [0])
                    ] UNSPEC_VSETVL))
            (set (reg:SI 67 vtype)
                (unspec:SI [
                        (const_int 64 [0x40])
                        (const_int 0 [0])
                        (const_int 1 [0x1]) repeated x2
                    ] UNSPEC_VSETVL))
        ]) "bug.c":14:14 discrim 1 1469 {vsetvl_discard_resultsi}
     (nil))
(insn 78 230 84 9 (set (reg:RVVM1DI 102 v6 [203])
        (if_then_else:RVVM1DI (unspec:RVVMF64BI [
                    (const_vector:RVVMF64BI repeat [
                            (const_int 1 [0x1])
                        ])
                    (const_int 0 [0])
                    (const_int 2 [0x2]) repeated x2
                    (const_int 0 [0])
                    (reg:SI 66 vl)
                    (reg:SI 67 vtype)
                ] UNSPEC_VPREDICATE)
            (vec_duplicate:RVVM1DI (mem/u/c:DI (reg/f:SI 29 t4 [230]) [0  S8 A64]))
            (unspec:RVVM1DI [
                    (reg:SI 0 zero)
                ] UNSPEC_VUNDEF))) "bug.c":14:14 discrim 1 1872 {*pred_broadcastrvvm1di}
     (expr_list:REG_DEAD (reg/f:SI 29 t4 [230])
        (nil)))

The root cause of this is because we missed VLMAX handling since the codes was invented
long time ago (Callers always intrinsics codes, no VLMAX situation).

Now, all following bugs are fixed after this patch:

FAIL: gcc.target/riscv/rvv/autovec/unop/popcount-run-1.c execution test
FAIL: gcc.target/riscv/rvv/autovec/unop/popcount-run-1.c execution test
FAIL: gcc.target/riscv/rvv/autovec/unop/popcount-run-1.c execution test
FAIL: gcc.target/riscv/rvv/autovec/unop/popcount-run-1.c execution test
FAIL: gcc.target/riscv/rvv/autovec/unop/popcount-run-1.c execution test
FAIL: gcc.target/riscv/rvv/autovec/unop/popcount-run-1.c execution test
FAIL: gcc.target/riscv/rvv/autovec/unop/popcount-run-1.c execution test
FAIL: gcc.target/riscv/rvv/autovec/unop/popcount-run-1.c execution test

gcc/ChangeLog:

* config/riscv/riscv-protos.h (sew64_scalar_helper): Fix bug.
* config/riscv/riscv-v.cc (sew64_scalar_helper): Ditto.
* config/riscv/vector.md: Ditto.

(cherry picked from commit eb1cdb3e43f43a7311c324e0acf85ceaf79314e5)

gcc/config/riscv/riscv-protos.h
gcc/config/riscv/riscv-v.cc
gcc/config/riscv/vector.md

index 2926d5d50d5a72b5063a5a6a382db8d1a52bd8e6..150b61bb5b593cde6f8101a13f32933ecdb3a882 100644 (file)
@@ -490,7 +490,7 @@ void expand_vec_lceil (rtx, rtx, machine_mode, machine_mode);
 void expand_vec_lfloor (rtx, rtx, machine_mode, machine_mode);
 #endif
 bool sew64_scalar_helper (rtx *, rtx *, rtx, machine_mode,
-                         bool, void (*)(rtx *, rtx));
+                         bool, void (*)(rtx *, rtx), enum avl_type);
 rtx gen_scalar_move_mask (machine_mode);
 rtx gen_no_side_effects_vsetvl_rtx (machine_mode, rtx, rtx);
 
index 53991cc10906599b1e5adc035c4728dbc35cfa4a..ee631404b44570e939132d71c270d3e6273941ba 100644 (file)
@@ -1641,7 +1641,7 @@ has_vi_variant_p (rtx_code code, rtx x)
 bool
 sew64_scalar_helper (rtx *operands, rtx *scalar_op, rtx vl,
                     machine_mode vector_mode, bool has_vi_variant_p,
-                    void (*emit_vector_func) (rtx *, rtx))
+                    void (*emit_vector_func) (rtx *, rtx), enum avl_type type)
 {
   machine_mode scalar_mode = GET_MODE_INNER (vector_mode);
   if (has_vi_variant_p)
@@ -1671,7 +1671,11 @@ sew64_scalar_helper (rtx *operands, rtx *scalar_op, rtx vl,
 
   rtx tmp = gen_reg_rtx (vector_mode);
   rtx ops[] = {tmp, *scalar_op};
-  emit_nonvlmax_insn (code_for_pred_broadcast (vector_mode), UNARY_OP, ops, vl);
+  if (type == VLMAX)
+    emit_vlmax_insn (code_for_pred_broadcast (vector_mode), UNARY_OP, ops);
+  else
+    emit_nonvlmax_insn (code_for_pred_broadcast (vector_mode), UNARY_OP, ops,
+                       vl);
   emit_vector_func (operands, tmp);
 
   return true;
index cea3dbf37a6e0da78f544b62948873c31984fedc..c4c136cb5d2cc317b832839fb2db025bedea6a24 100644 (file)
          emit_insn (gen_pred_merge<mode> (operands[0], operands[1],
               operands[2], boardcast_scalar, operands[4], operands[5],
               operands[6], operands[7]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[7])))
     DONE;
 })
 
          emit_insn (gen_pred_<optab><mode> (operands[0], operands[1],
               operands[2], operands[3], boardcast_scalar, operands[5],
               operands[6], operands[7], operands[8]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[8])))
     DONE;
 })
 
          emit_insn (gen_pred_<optab><mode> (operands[0], operands[1],
               operands[2], operands[3], boardcast_scalar, operands[5],
               operands[6], operands[7], operands[8]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[8])))
     DONE;
 })
 
          emit_insn (gen_pred_sub<mode> (operands[0], operands[1],
               operands[2], boardcast_scalar, operands[3], operands[5],
               operands[6], operands[7], operands[8]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[8])))
     DONE;
 })
 
          emit_insn (gen_pred_mulh<v_su><mode> (operands[0], operands[1],
               operands[2], operands[3], boardcast_scalar, operands[5],
               operands[6], operands[7], operands[8]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[8])))
     DONE;
 })
 
          emit_insn (gen_pred_adc<mode> (operands[0], operands[1],
               operands[2], boardcast_scalar, operands[4], operands[5],
               operands[6], operands[7]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[7])))
     DONE;
 })
 
          emit_insn (gen_pred_sbc<mode> (operands[0], operands[1],
               operands[2], boardcast_scalar, operands[4], operands[5],
               operands[6], operands[7]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[7])))
     DONE;
 })
 
        [] (rtx *operands, rtx boardcast_scalar) {
          emit_insn (gen_pred_madc<mode> (operands[0], operands[1],
               boardcast_scalar, operands[3], operands[4], operands[5]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[5])))
     DONE;
 })
 
        [] (rtx *operands, rtx boardcast_scalar) {
          emit_insn (gen_pred_msbc<mode> (operands[0], operands[1],
               boardcast_scalar, operands[3], operands[4], operands[5]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[5])))
     DONE;
 })
 
        [] (rtx *operands, rtx boardcast_scalar) {
          emit_insn (gen_pred_madc<mode>_overflow (operands[0], operands[1],
               boardcast_scalar, operands[3], operands[4]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[4])))
     DONE;
 })
 
        [] (rtx *operands, rtx boardcast_scalar) {
          emit_insn (gen_pred_msbc<mode>_overflow (operands[0], operands[1],
               boardcast_scalar, operands[3], operands[4]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[4])))
     DONE;
 })
 
          emit_insn (gen_pred_<optab><mode> (operands[0], operands[1],
               operands[2], operands[3], boardcast_scalar, operands[5],
               operands[6], operands[7], operands[8]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[8])))
     DONE;
 })
 
          emit_insn (gen_pred_<optab><mode> (operands[0], operands[1],
               operands[2], operands[3], boardcast_scalar, operands[5],
               operands[6], operands[7], operands[8]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[8])))
     DONE;
 })
 
          emit_insn (gen_pred_<sat_op><mode> (operands[0], operands[1],
               operands[2], operands[3], boardcast_scalar, operands[5],
               operands[6], operands[7], operands[8], operands[9]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[8])))
     DONE;
 })
 
            emit_insn (gen_pred_cmp<mode> (operands[0], operands[1],
                operands[2], operands[3], operands[4], boardcast_scalar,
                operands[6], operands[7], operands[8]));
-          }))
+          },
+       (riscv_vector::avl_type) INTVAL (operands[8])))
     DONE;
 })
 
          emit_insn (gen_pred_cmp<mode> (operands[0], operands[1],
                operands[2], operands[3], operands[4], boardcast_scalar,
                operands[6], operands[7], operands[8]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[8])))
     DONE;
 })
 
          emit_insn (gen_pred_mul_plus<mode> (operands[0], operands[1],
               boardcast_scalar, operands[3], operands[4], operands[5],
               operands[6], operands[7], operands[8], operands[9]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[9])))
     DONE;
 })
 
          emit_insn (gen_pred_minus_mul<mode> (operands[0], operands[1],
               boardcast_scalar, operands[3], operands[4], operands[5],
               operands[6], operands[7], operands[8], operands[9]));
-        }))
+        },
+       (riscv_vector::avl_type) INTVAL (operands[9])))
     DONE;
 })
 
This page took 0.104154 seconds and 5 git commands to generate.