Pushed to r16-3209.
在 2025/8/14 下午3:56, Lulu Cheng 写道:
PR target/121542
gcc/ChangeLog:
* config/loongarch/loongarch.cc
(loongarch_vector_costs::add_stmt_cost): When using vectype,
first determine whether it is NULL.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/pr121542.c: New test.
---
gcc/config/loongarch/loongarch.cc | 1 +
gcc/testsuite/gcc.target/loongarch/pr121542.c | 54 +++++++++++++++++++
2 files changed, 55 insertions(+)
create mode 100644 gcc/testsuite/gcc.target/loongarch/pr121542.c
diff --git a/gcc/config/loongarch/loongarch.cc
b/gcc/config/loongarch/loongarch.cc
index 3b62ed9cfb9..e2f8e06c1b7 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -4388,6 +4388,7 @@ loongarch_vector_costs::add_stmt_cost (int count,
vect_cost_for_stmt kind,
break;
}
else if (TARGET_RECIP_VEC_DIV
+ && vectype
&& gimple_code (stmt_info->stmt) == GIMPLE_ASSIGN)
{
machine_mode mode = TYPE_MODE (vectype);
diff --git a/gcc/testsuite/gcc.target/loongarch/pr121542.c
b/gcc/testsuite/gcc.target/loongarch/pr121542.c
new file mode 100644
index 00000000000..51a5e3c4480
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/pr121542.c
@@ -0,0 +1,54 @@
+/* { dg-do compile } */
+/* { dg-options "-mrecip=all -mfrecipe -mabi=lp64d -march=loongarch64 -mfpu=64
-msimd=lasx -Ofast" } */
+
+typedef long unsigned int STRLEN;
+typedef struct sv SV;
+struct sv
+{
+ void *sv_any;
+ unsigned int sv_refcnt;
+ unsigned int sv_flags;
+};
+typedef struct xpv XPV;
+struct xpv
+{
+ char *xpv_pv;
+ STRLEN xpv_cur;
+ STRLEN xpv_len;
+};
+typedef unsigned long UV;
+extern char *PL_bufend;
+extern char *d;
+SV *Perl_newSV (STRLEN len);
+
+char *
+S_scan_const (char *start)
+{
+ register char *send = PL_bufend;
+ SV *sv = Perl_newSV (send - start);
+ register char *s = start;
+ UV uv;
+
+ while (s < send)
+ {
+ if (!(((UV)(uv)) < 0x80))
+ {
+ int hicount = 0;
+ unsigned char *c;
+ for (c = (unsigned char *)((XPV *)(sv)->sv_any)->xpv_pv;
+ c < (unsigned char *)d; c++)
+ {
+ if (!(((UV)(*c)) < 0x80))
+ {
+ hicount++;
+ }
+ }
+ d += hicount;
+ *d++ = (char)uv;
+ }
+
+ s++;
+ }
+
+ return s;
+}