aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2024-07-23 10:50:29 +0200
committerThomas Koenig <tkoenig@gcc.gnu.org>2024-07-28 19:05:47 +0200
commitcaad1323a23c3933a9a29205f3602616cec0e879 (patch)
treefb8632521b9782a0de6309a80f29f1d2acbac8df
parent6d116bc5f958054fca819ab38d40e1abefd74b2d (diff)
downloadgcc-caad1323a23c3933a9a29205f3602616cec0e879.zip
gcc-caad1323a23c3933a9a29205f3602616cec0e879.tar.gz
gcc-caad1323a23c3933a9a29205f3602616cec0e879.tar.bz2
ssa: Fix up maybe_rewrite_mem_ref_base complex type handling [PR116034]
The folding into REALPART_EXPR is correct, used only when the mem_offset is zero, but for IMAGPART_EXPR it didn't check the exact offset value (just that it is not 0). The following patch fixes that by using IMAGPART_EXPR only if the offset is right and using BITFIELD_REF or whatever else otherwise. 2024-07-23 Jakub Jelinek <jakub@redhat.com> Andrew Pinski <quic_apinski@quicinc.com> PR tree-optimization/116034 * tree-ssa.cc (maybe_rewrite_mem_ref_base): Only use IMAGPART_EXPR if MEM_REF offset is equal to element type size. * gcc.dg/pr116034.c: New test.
-rw-r--r--gcc/testsuite/gcc.dg/pr116034.c22
-rw-r--r--gcc/tree-ssa.cc5
2 files changed, 26 insertions, 1 deletions
diff --git a/gcc/testsuite/gcc.dg/pr116034.c b/gcc/testsuite/gcc.dg/pr116034.c
new file mode 100644
index 0000000..9a31de0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr116034.c
@@ -0,0 +1,22 @@
+/* PR tree-optimization/116034 */
+/* { dg-do run } */
+/* { dg-options "-O1 -fno-strict-aliasing" } */
+
+int g;
+
+static inline int
+foo (_Complex unsigned short c)
+{
+ __builtin_memmove (&g, 1 + (char *) &c, 2);
+ return g;
+}
+
+int
+main ()
+{
+ if (__SIZEOF_SHORT__ == 2
+ && __CHAR_BIT__ == 8
+ && (foo (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ ? 0x100 : 1)
+ != (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ ? 1 : 0x100)))
+ __builtin_abort ();
+}
diff --git a/gcc/tree-ssa.cc b/gcc/tree-ssa.cc
index 27ab9cf..f4fa4e9 100644
--- a/gcc/tree-ssa.cc
+++ b/gcc/tree-ssa.cc
@@ -1506,7 +1506,10 @@ maybe_rewrite_mem_ref_base (tree *tp, bitmap suitable_for_renaming)
}
else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
&& useless_type_conversion_p (TREE_TYPE (*tp),
- TREE_TYPE (TREE_TYPE (sym))))
+ TREE_TYPE (TREE_TYPE (sym)))
+ && (integer_zerop (TREE_OPERAND (*tp, 1))
+ || tree_int_cst_equal (TREE_OPERAND (*tp, 1),
+ TYPE_SIZE_UNIT (TREE_TYPE (*tp)))))
{
*tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
? REALPART_EXPR : IMAGPART_EXPR,