[gcc(refs/vendors/riscv/heads/gcc-15-with-riscv-opts)] forwprop: Check type conversion in pack/unpack [PR123117].
Jeff Law
law@gcc.gnu.org
Sat Jan 17 07:31:00 GMT 2026
https://gcc.gnu.org/g:a3da3e3c3607a2a484e73c147bafdc7c99886279
commit a3da3e3c3607a2a484e73c147bafdc7c99886279
Author: Robin Dapp <rdapp@qti.qualcomm.com>
Date: Mon Dec 15 13:01:40 2025 +0100
forwprop: Check type conversion in pack/unpack [PR123117].
When using pack or unpack in the simplification of a vector constructor
we must make sure that the original BIT_FIELD_REF was no sign-changing
nop conversion. If it was we cannot safely pack/unpack as that would
skip sign or zero extensions. This patch adds useless_type_conversion_p
to both paths.
PR tree-optimization/123117
gcc/ChangeLog:
* tree-ssa-forwprop.cc (simplify_vector_constructor):
Check if we had a nop conversion and don't use pack/unpack in
that case.
gcc/testsuite/ChangeLog:
* gcc.target/loongarch/vector/lsx/pr123117.c: New test.
(cherry picked from commit e8fd095091ebfc0c4adc1c7f6607ab30b25b3a05)
Diff:
---
gcc/testsuite/gcc.target/loongarch/vector/lsx/pr123117.c | 16 ++++++++++++++++
gcc/tree-ssa-forwprop.cc | 12 ++++++++++++
2 files changed, 28 insertions(+)
diff --git a/gcc/testsuite/gcc.target/loongarch/vector/lsx/pr123117.c b/gcc/testsuite/gcc.target/loongarch/vector/lsx/pr123117.c
new file mode 100644
index 000000000000..c9683e9629b8
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/vector/lsx/pr123117.c
@@ -0,0 +1,16 @@
+/* { dg-options "-mlsx -O1" } */
+
+#define BS_VEC(type, num) type __attribute__((vector_size(num * sizeof(type))))
+#define T BS_VEC(unsigned, 4)
+
+int main ()
+{
+ BS_VEC(long int, 2) BS_VAR_0[1];
+ BS_VEC(int, 4) tt = (BS_VEC(int, 4)){0x9e47d3d2, 0, 0, 0};
+ asm("":"+f"(tt));
+ BS_VEC(unsigned int, 2) SHUF = __builtin_shufflevector((T)tt, (T)tt, 0, 1);
+ BS_VAR_0[0] = __builtin_convertvector(SHUF, BS_VEC(long int, 2));
+
+ if (BS_VAR_0[0][0] != 0x000000009e47d3d2)
+ __builtin_abort ();
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index 86fd74ef047b..26ad9be04fd3 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -2817,6 +2817,7 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
orig[0] = NULL;
orig[1] = NULL;
+ tree orig_elem_type[2] = {};
conv_code = ERROR_MARK;
bool maybe_ident = true;
bool maybe_blend[2] = { true, true };
@@ -2862,6 +2863,11 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
if (j < 2)
{
orig[j] = ref;
+ /* Track what element type was actually extracted (which may
+ differ in signedness from the vector's element type due to
+ tree_nop_conversion_p). */
+ if (!orig_elem_type[j])
+ orig_elem_type[j] = TREE_TYPE (op1);
if (elem != i || j != 0)
maybe_ident = false;
if (elem != i)
@@ -2949,6 +2955,9 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
if (CONVERT_EXPR_CODE_P (conv_code)
&& (2 * TYPE_PRECISION (TREE_TYPE (TREE_TYPE (orig[0])))
== TYPE_PRECISION (TREE_TYPE (type)))
+ && orig_elem_type[0]
+ && useless_type_conversion_p (orig_elem_type[0],
+ TREE_TYPE (type))
&& mode_for_vector (as_a <scalar_mode>
(TYPE_MODE (TREE_TYPE (TREE_TYPE (orig[0])))),
nelts * 2).exists ()
@@ -2988,6 +2997,9 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
else if (CONVERT_EXPR_CODE_P (conv_code)
&& (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (orig[0])))
== 2 * TYPE_PRECISION (TREE_TYPE (type)))
+ && orig_elem_type[0]
+ && useless_type_conversion_p (orig_elem_type[0],
+ TREE_TYPE (type))
&& mode_for_vector (as_a <scalar_mode>
(TYPE_MODE
(TREE_TYPE (TREE_TYPE (orig[0])))),
More information about the Gcc-cvs
mailing list