--- /dev/null
+/* { dg-do compile } */
+/* { dg-additional-options "-ftree-pre -fcode-hoisting" } */
+
+typedef unsigned char u8;
+extern unsigned long pci_io_base;
+u8 in_8 (const volatile void *);
+int eeh_enabled ();
+void eeh_check_failure ();
+static inline
+u8 eeh_readb(const volatile void *addr)
+{
+ u8 val = in_8(addr);
+ if (((val) == (u8)~0 && eeh_enabled())) eeh_check_failure();
+ return val;
+}
+extern struct ppc_pci_io {
+ void (*outb) (u8 val, unsigned long port);
+}
+ppc_pci_io;
+static inline
+u8 readb (const volatile void * addr)
+{
+ return eeh_readb((addr));
+}
+static inline
+u8 inb (unsigned long port)
+{
+ return readb((volatile void *)pci_io_base + port);
+}
+static inline
+void outb (u8 val, unsigned long port)
+{
+ if (ppc_pci_io.outb != ((void *)0)) ppc_pci_io.outb (val, port);
+};
+void frob_econtrol(unsigned long base_hi, unsigned char m, unsigned char v)
+{
+ unsigned char ectr = 0;
+ if (m != 0xff) ectr = inb((base_hi + 0x2));
+ outb((ectr & ~m) ^ v, (base_hi + 0x2));
+}
return newexpr;
}
-/* Given a value id V, find the actual tree representing the constant
- value if there is one, and return it. Return NULL if we can't find
- a constant. */
-
-static tree
-get_constant_for_value_id (unsigned int v)
-{
- if (value_id_constant_p (v))
- {
- unsigned int i;
- bitmap_iterator bi;
- bitmap exprset = value_expressions[v];
-
- EXECUTE_IF_SET_IN_BITMAP (exprset, 0, i, bi)
- {
- pre_expr expr = expression_for_id (i);
- if (expr->kind == CONSTANT)
- return PRE_EXPR_CONSTANT (expr);
- }
- }
- return NULL;
-}
-
/* Get or allocate a pre_expr for a piece of GIMPLE, and return it.
Currently only supports constants and SSA_NAMES. */
static pre_expr
case NARY:
{
vn_nary_op_t nary = PRE_EXPR_NARY (e);
- switch (TREE_CODE_CLASS (nary->opcode))
- {
- case tcc_binary:
- case tcc_comparison:
- {
- /* We have to go from trees to pre exprs to value ids to
- constants. */
- tree naryop0 = nary->op[0];
- tree naryop1 = nary->op[1];
- tree result;
- if (!is_gimple_min_invariant (naryop0))
- {
- pre_expr rep0 = get_or_alloc_expr_for (naryop0);
- unsigned int vrep0 = get_expr_value_id (rep0);
- tree const0 = get_constant_for_value_id (vrep0);
- if (const0)
- naryop0 = fold_convert (TREE_TYPE (naryop0), const0);
- }
- if (!is_gimple_min_invariant (naryop1))
- {
- pre_expr rep1 = get_or_alloc_expr_for (naryop1);
- unsigned int vrep1 = get_expr_value_id (rep1);
- tree const1 = get_constant_for_value_id (vrep1);
- if (const1)
- naryop1 = fold_convert (TREE_TYPE (naryop1), const1);
- }
- result = fold_binary (nary->opcode, nary->type,
- naryop0, naryop1);
- if (result && is_gimple_min_invariant (result))
- return get_or_alloc_expr_for_constant (result);
- /* We might have simplified the expression to a
- SSA_NAME for example from x_1 * 1. But we cannot
- insert a PHI for x_1 unconditionally as x_1 might
- not be available readily. */
- return e;
- }
- case tcc_reference:
- if (nary->opcode != REALPART_EXPR
- && nary->opcode != IMAGPART_EXPR
- && nary->opcode != VIEW_CONVERT_EXPR)
- return e;
- /* Fallthrough. */
- case tcc_unary:
- {
- /* We have to go from trees to pre exprs to value ids to
- constants. */
- tree naryop0 = nary->op[0];
- tree const0, result;
- if (is_gimple_min_invariant (naryop0))
- const0 = naryop0;
- else
- {
- pre_expr rep0 = get_or_alloc_expr_for (naryop0);
- unsigned int vrep0 = get_expr_value_id (rep0);
- const0 = get_constant_for_value_id (vrep0);
- }
- result = NULL;
- if (const0)
- {
- tree type1 = TREE_TYPE (nary->op[0]);
- const0 = fold_convert (type1, const0);
- result = fold_unary (nary->opcode, nary->type, const0);
- }
- if (result && is_gimple_min_invariant (result))
- return get_or_alloc_expr_for_constant (result);
- return e;
- }
- default:
- return e;
- }
+ tree res = vn_nary_simplify (nary);
+ if (!res)
+ return e;
+ if (is_gimple_min_invariant (res))
+ return get_or_alloc_expr_for_constant (res);
+ /* We might have simplified the expression to a
+ SSA_NAME for example from x_1 * 1. But we cannot
+ insert a PHI for x_1 unconditionally as x_1 might
+ not be available readily. */
+ return e;
}
case REFERENCE:
{
gimple_seq stmts = NULL;
tree res = create_expression_by_pieces (block, expr, &stmts,
get_expr_type (expr));
- if (gsi_end_p (last) || is_ctrl_stmt (gsi_stmt (last)))
- gsi_insert_seq_before (&last, stmts, GSI_SAME_STMT);
+
+ /* Do not return true if expression creation ultimately
+ did not insert any statements. */
+ if (gimple_seq_empty_p (stmts))
+ res = NULL_TREE;
else
- gsi_insert_seq_after (&last, stmts, GSI_NEW_STMT);
+ {
+ if (gsi_end_p (last) || is_ctrl_stmt (gsi_stmt (last)))
+ gsi_insert_seq_before (&last, stmts, GSI_SAME_STMT);
+ else
+ gsi_insert_seq_after (&last, stmts, GSI_NEW_STMT);
+ }
/* Make sure to not return true if expression creation ultimately
failed but also make sure to insert any stmts produced as they
}
/* Return a value-number for RCODE OPS... either by looking up an existing
- value-number for the simplified result or by inserting the operation. */
+ value-number for the simplified result or by inserting the operation if
+ INSERT is true. */
static tree
-vn_nary_build_or_lookup (code_helper rcode, tree type, tree *ops)
+vn_nary_build_or_lookup_1 (code_helper rcode, tree type, tree *ops,
+ bool insert)
{
tree result = NULL_TREE;
/* We will be creating a value number for
else
{
tree val = vn_lookup_simplify_result (rcode, type, ops);
- if (!val)
+ if (!val && insert)
{
gimple_seq stmts = NULL;
result = maybe_push_res_to_seq (rcode, type, ops, &stmts);
return result;
}
+/* Return a value-number for RCODE OPS... either by looking up an existing
+ value-number for the simplified result or by inserting the operation. */
+
+static tree
+vn_nary_build_or_lookup (code_helper rcode, tree type, tree *ops)
+{
+ return vn_nary_build_or_lookup_1 (rcode, type, ops, true);
+}
+
+/* Try to simplify the expression RCODE OPS... of type TYPE and return
+ its value if present. */
+
+tree
+vn_nary_simplify (vn_nary_op_t nary)
+{
+ if (nary->length > 3)
+ return NULL_TREE;
+ tree ops[3];
+ memcpy (ops, nary->op, sizeof (tree) * nary->length);
+ return vn_nary_build_or_lookup_1 (nary->opcode, nary->type, ops, false);
+}
+
+
/* Callback for walk_non_aliased_vuses. Tries to perform a lookup
from the statement defining VUSE and if not successful tries to
translate *REFP and VR_ through an aggregate copy at the definition