https://gcc.gnu.org/g:939dd2324e0f1c7cac49d2635532f08762b67674

commit r16-6742-g939dd2324e0f1c7cac49d2635532f08762b67674
Author: Robin Dapp <[email protected]>
Date:   Mon Jan 12 15:45:46 2026 +0100

    forwprop: Fix type mismatch in vec constructor [PR123525].
    
    This issue got raised after r16-6671 in which I removed checks for
    number-of-element equality.  In the splat case with conversion:
    
      vector(16) int w;
      vector(8) long int v;
      _13 = BIT_FIELD_REF <w_12(D), 32, 160>;
      _2 = (long int) _13;
      _3 = (long int) _13;
      ...
      _9 = (long int) _13;
      _1 = {_2, _3, _4, _5, _6, _7, _8, _9};
    
    right now we do
      _16 = VEC_PERM_EXPR <w_12(D), w_12(D), { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 
5, 5, 5, 5, 5 }>;
      _17 = VIEW_CONVERT_EXPR<vector(8) intD.6>(_16);
    
    where the view convert is actually an optimized
      _17 = BIT_FIELD_REF (_16, 512, 0);
    
    512 is the size of the unconverted source but we should actually use the
    converted source type.  That's what this patch does.
    
            PR tree-optimization/123525
    
    gcc/ChangeLog:
    
            * tree-ssa-forwprop.cc (simplify_vector_constructor): Use
            converted source type for conversion bit field ref.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/vect/pr123525.c: New test.
            * g++.dg/vect/pr123525-2.cc: New test.

Diff:
---
 gcc/testsuite/g++.dg/vect/pr123525-2.cc | 38 +++++++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/vect/pr123525.c    | 14 ++++++++++++
 gcc/tree-ssa-forwprop.cc                |  5 ++++-
 3 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/gcc/testsuite/g++.dg/vect/pr123525-2.cc 
b/gcc/testsuite/g++.dg/vect/pr123525-2.cc
new file mode 100644
index 000000000000..4dbe0f1218d5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/vect/pr123525-2.cc
@@ -0,0 +1,38 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-march=tigerlake -std=c++23" { target { x86_64-*-* 
i?86-*-* } } } */
+/* { dg-additional-options "-std=c++23" } */
+
+short ScAddress_nTabP;
+struct ScAddress {
+  short nCol;
+  short nTab;
+  ScAddress(short nColP) : nCol(nColP), nTab(ScAddress_nTabP) {}
+};
+
+struct ScRange {
+  ScAddress aStart;
+};
+
+struct CellRangeAddress {
+  int StartColumn;
+  int StartRow;
+  int EndColumn;
+  int EndRow;
+};
+
+struct ScCellRangeObj {
+  ScCellRangeObj(int, ScRange &);
+};
+
+CellRangeAddress ScVbaRangeMergeArea_aCellAddress;
+void ScVbaRangeMergeArea() {
+  if (ScVbaRangeMergeArea_aCellAddress.StartColumn == 0 &&
+      ScVbaRangeMergeArea_aCellAddress.EndColumn == 0 &&
+      ScVbaRangeMergeArea_aCellAddress.StartRow == 0 &&
+      ScVbaRangeMergeArea_aCellAddress.EndRow == 0)
+    ;
+  else {
+    ScRange refRange(ScVbaRangeMergeArea_aCellAddress.StartColumn);
+    ScCellRangeObj(0, refRange);
+  }
+}
diff --git a/gcc/testsuite/gcc.dg/vect/pr123525.c 
b/gcc/testsuite/gcc.dg/vect/pr123525.c
new file mode 100644
index 000000000000..e00f465e6d73
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr123525.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-mavx512f" { target { x86_64-*-* i?86-*-* } } } */
+/* { dg-additional-options "-Wno-psabi" } */
+
+typedef __attribute__((__vector_size__(64))) long V;
+typedef __attribute__((__vector_size__(64))) int W;
+
+V v;
+
+V
+foo(W w)
+{
+  return w[5] > v;
+}
diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc
index b70fe8169adc..bdc63a7a71bc 100644
--- a/gcc/tree-ssa-forwprop.cc
+++ b/gcc/tree-ssa-forwprop.cc
@@ -4260,7 +4260,10 @@ simplify_vector_constructor (gimple_stmt_iterator *gsi)
       if (nelts != refnelts)
        res = gimple_build (&stmts, BIT_FIELD_REF,
                            conv_code != ERROR_MARK ? conv_src_type : type,
-                           res, TYPE_SIZE (type), bitsize_zero_node);
+                           res,
+                           TYPE_SIZE (conv_code != ERROR_MARK ? conv_src_type
+                                                              : type),
+                           bitsize_zero_node);
       if (conv_code != ERROR_MARK)
        res = gimple_build (&stmts, conv_code, type, res);
       else if (!useless_type_conversion_p (type, TREE_TYPE (res)))

Reply via email to