aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Biener <rguenther@suse.de>2025-08-11 09:42:09 +0200
committerRichard Biener <rguenth@gcc.gnu.org>2025-08-11 15:44:23 +0200
commitf2a85db9eee7d761692ca8f69ea1a20d32715bad (patch)
treef9db300814540a21a61c23cb940aa7047e3ea61e /gcc
parent45a56f42b4909e2ae0d1ad35dab05c5c092a14bc (diff)
downloadgcc-f2a85db9eee7d761692ca8f69ea1a20d32715bad.zip
gcc-f2a85db9eee7d761692ca8f69ea1a20d32715bad.tar.gz
gcc-f2a85db9eee7d761692ca8f69ea1a20d32715bad.tar.bz2
tree-optimization/121488 - improve BIT_FIELD_REF lookup in VN
When a BIT_FIELD_REF lookup combined with a defining load RHS results in a wrongly typed result, try looking up or inserting a VIEW_CONVERT_EXPR to the desired type. PR tree-optimization/121488 * tree-ssa-sccvn.cc (visit_nary_op): If the BIT_FIELD_REF result is of wrong type, try a VIEW_CONVERT_EXPR around it. * gcc.dg/tree-ssa/ssa-fre-108.c: New testcase.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-108.c30
-rw-r--r--gcc/tree-ssa-sccvn.cc17
2 files changed, 47 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-108.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-108.c
new file mode 100644
index 0000000..a13e972
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-108.c
@@ -0,0 +1,30 @@
+/* { dg-do compile } */
+/* { dg-options "-O -Wno-psabi -fdump-tree-fre1" } */
+
+#define vector16 __attribute__((vector_size(16)))
+#define vector32 __attribute__((vector_size(32)))
+
+union u1
+{
+ struct s1
+ {
+ vector16 int hi;
+ vector16 int low;
+ }hilow;
+ vector32 int v;
+};
+
+vector16 float f(vector16 int a, vector16 int b)
+{
+ union u1 c;
+ c.hilow.hi = a;
+ c.hilow.low = b;
+ vector32 int d0 = c.v;
+ vector32 float d = (vector32 float)d0;
+ vector16 float e = __builtin_shufflevector (d, d, 0, 1, 2, 3);
+ vector16 float f = __builtin_shufflevector (d, d, 4, 5, 6, 7);
+ return e/f;
+}
+
+/* { dg-final { scan-tree-dump-times "_\[0-9\]\+ = VIEW_CONVERT_EXPR" 2 "fre1" } } */
+/* { dg-final { scan-tree-dump-not "BIT_FIELD_REF" "fre1" } } */
diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 866d49c..61d794d 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -5660,6 +5660,23 @@ visit_nary_op (tree lhs, gassign *stmt)
if (result
&& useless_type_conversion_p (type, TREE_TYPE (result)))
return set_ssa_val_to (lhs, result);
+ else if (result
+ && TYPE_SIZE (type)
+ && TYPE_SIZE (TREE_TYPE (result))
+ && operand_equal_p (TYPE_SIZE (type),
+ TYPE_SIZE (TREE_TYPE (result))))
+ {
+ gimple_match_op match_op (gimple_match_cond::UNCOND,
+ VIEW_CONVERT_EXPR,
+ type, result);
+ result = vn_nary_build_or_lookup (&match_op);
+ if (result)
+ {
+ bool changed = set_ssa_val_to (lhs, result);
+ vn_nary_op_insert_stmt (stmt, result);
+ return changed;
+ }
+ }
}
}
}