This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/34043] Missed optimization causing extra loads and stores when using x86_64 builtin function together with aggregate types.
- From: "rguenth at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 3 Jan 2008 17:29:45 -0000
- Subject: [Bug tree-optimization/34043] Missed optimization causing extra loads and stores when using x86_64 builtin function together with aggregate types.
- References: <bug-34043-14442@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #9 from rguenth at gcc dot gnu dot org 2008-01-03 17:29 -------
Confirmed. While I have a patch to make VN handle the case of type-punning
constants, making it to generate VIEW_CONVERT_EXPRs instead runs into the
principle barrier that FRE does not do insertion.
The patch looks like
Index: tree-ssa-sccvn.c
===================================================================
*** tree-ssa-sccvn.c (revision 131302)
--- tree-ssa-sccvn.c (working copy)
*************** visit_reference_op_store (tree lhs, tree
*** 1231,1236 ****
--- 1247,1292 ----
}
vn_reference_insert (lhs, op, vdefs);
+
+ /* For unions and constant stores we can register stores to
+ the other union members as well, allowing propagation.
+ Do this for two-element unions only, as they are likely
+ used for type-punning which we want to optimize. */
+ if (TREE_CODE (lhs) == COMPONENT_REF
+ && TREE_CODE (TREE_TYPE (TREE_OPERAND (lhs, 0))) == UNION_TYPE
+ /* We may be able to handle non-constant type-punnings as well. */
+ && (TREE_CODE (op) == INTEGER_CST
+ || TREE_CODE (op) == REAL_CST
+ || TREE_CODE (op) == VECTOR_CST
+ || TREE_CODE (op) == COMPLEX_CST)
+ && fields_length (TREE_TYPE (TREE_OPERAND (lhs, 0))) == 2)
+ {
+ tree field = TYPE_FIELDS (TREE_TYPE (TREE_OPERAND (lhs, 0)));
+ tree val;
+
+ if (field == TREE_OPERAND (lhs, 1))
+ field = TREE_CHAIN (field);
+
+ /* Do not generate VIEW_CONVERT_EXPRs, but only handle the
+ cases we can fold it away. */
+ val = fold_unary (VIEW_CONVERT_EXPR, TREE_TYPE (field), op);
+ if (val)
+ {
+ if (dump_file)
+ {
+ fprintf (dump_file, "Value numbering store to alternate "
+ "union field ");
+ print_generic_expr (dump_file, field, 0);
+ fprintf (dump_file, " with type-punned value ");
+ print_generic_expr (dump_file, val, 0);
+ fprintf (dump_file, "\n");
+ }
+ vn_reference_insert (build3 (COMPONENT_REF, TREE_TYPE (field),
+ TREE_OPERAND (lhs, 0), field,
+ NULL_TREE),
+ val, vdefs);
+ }
+ }
}
else
{
and it handles the testcase in comment #6 correctly.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu dot
| |org
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2008-01-03 17:29:45
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34043