Skip to content

Commit aaa82d6

Browse files
committed
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 <[email protected]> Andrew Pinski <[email protected]> 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. (cherry picked from commit b9cefd6)
1 parent 1880ff0 commit aaa82d6

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

gcc/testsuite/gcc.dg/pr116034.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* PR tree-optimization/116034 */
2+
/* { dg-do run } */
3+
/* { dg-options "-O1 -fno-strict-aliasing" } */
4+
5+
int g;
6+
7+
static inline int
8+
foo (_Complex unsigned short c)
9+
{
10+
__builtin_memmove (&g, 1 + (char *) &c, 2);
11+
return g;
12+
}
13+
14+
int
15+
main ()
16+
{
17+
if (__SIZEOF_SHORT__ == 2
18+
&& __CHAR_BIT__ == 8
19+
&& (foo (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ ? 0x100 : 1)
20+
!= (__BYTE_ORDER__ != __ORDER_BIG_ENDIAN__ ? 1 : 0x100)))
21+
__builtin_abort ();
22+
}

gcc/tree-ssa.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,10 @@ maybe_rewrite_mem_ref_base (tree *tp, bitmap suitable_for_renaming)
15291529
}
15301530
else if (TREE_CODE (TREE_TYPE (sym)) == COMPLEX_TYPE
15311531
&& useless_type_conversion_p (TREE_TYPE (*tp),
1532-
TREE_TYPE (TREE_TYPE (sym))))
1532+
TREE_TYPE (TREE_TYPE (sym)))
1533+
&& (integer_zerop (TREE_OPERAND (*tp, 1))
1534+
|| tree_int_cst_equal (TREE_OPERAND (*tp, 1),
1535+
TYPE_SIZE_UNIT (TREE_TYPE (*tp)))))
15331536
{
15341537
*tp = build1 (integer_zerop (TREE_OPERAND (*tp, 1))
15351538
? REALPART_EXPR : IMAGPART_EXPR,

0 commit comments

Comments
 (0)