+ if (TREE_CODE (stmt) != GIMPLE_MODIFY_STMT)
+ return SSA_PROP_VARYING;
+
+ lhs = GIMPLE_STMT_OPERAND (stmt, 0);
+ rhs = GIMPLE_STMT_OPERAND (stmt, 1);
+
+ /* These conditions should be satisfied due to the initial filter
+ set up in init_dont_simulate_again. */
+ gcc_assert (TREE_CODE (lhs) == SSA_NAME);
+ gcc_assert (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE);
+
+ *result_p = lhs;
+ ver = SSA_NAME_VERSION (lhs);
+ old_l = VEC_index (complex_lattice_t, complex_lattice_values, ver);
+
+ switch (TREE_CODE (rhs))
+ {
+ case SSA_NAME:
+ case COMPLEX_EXPR:
+ case COMPLEX_CST:
+ new_l = find_lattice_value (rhs);
+ break;
+
+ case PLUS_EXPR:
+ case MINUS_EXPR:
+ op1_l = find_lattice_value (TREE_OPERAND (rhs, 0));
+ op2_l = find_lattice_value (TREE_OPERAND (rhs, 1));
+
+ /* We've set up the lattice values such that IOR neatly
+ models addition. */
+ new_l = op1_l | op2_l;
+ break;
+
+ case MULT_EXPR:
+ case RDIV_EXPR:
+ case TRUNC_DIV_EXPR:
+ case CEIL_DIV_EXPR:
+ case FLOOR_DIV_EXPR:
+ case ROUND_DIV_EXPR:
+ op1_l = find_lattice_value (TREE_OPERAND (rhs, 0));
+ op2_l = find_lattice_value (TREE_OPERAND (rhs, 1));
+
+ /* Obviously, if either varies, so does the result. */
+ if (op1_l == VARYING || op2_l == VARYING)
+ new_l = VARYING;
+ /* Don't prematurely promote variables if we've not yet seen
+ their inputs. */
+ else if (op1_l == UNINITIALIZED)
+ new_l = op2_l;
+ else if (op2_l == UNINITIALIZED)
+ new_l = op1_l;
+ else
+ {
+ /* At this point both numbers have only one component. If the
+ numbers are of opposite kind, the result is imaginary,
+ otherwise the result is real. The add/subtract translates
+ the real/imag from/to 0/1; the ^ performs the comparison. */
+ new_l = ((op1_l - ONLY_REAL) ^ (op2_l - ONLY_REAL)) + ONLY_REAL;
+
+ /* Don't allow the lattice value to flip-flop indefinitely. */
+ new_l |= old_l;
+ }
+ break;
+
+ case NEGATE_EXPR:
+ case CONJ_EXPR:
+ new_l = find_lattice_value (TREE_OPERAND (rhs, 0));
+ break;
+
+ default:
+ new_l = VARYING;
+ break;
+ }
+
+ /* If nothing changed this round, let the propagator know. */
+ if (new_l == old_l)
+ return SSA_PROP_NOT_INTERESTING;
+
+ VEC_replace (complex_lattice_t, complex_lattice_values, ver, new_l);
+ return new_l == VARYING ? SSA_PROP_VARYING : SSA_PROP_INTERESTING;
+}
+
+/* Evaluate a PHI node against the complex lattice defined above. */
+
+static enum ssa_prop_result
+complex_visit_phi (tree phi)
+{
+ complex_lattice_t new_l, old_l;
+ unsigned int ver;
+ tree lhs;
+ int i;
+
+ lhs = PHI_RESULT (phi);
+
+ /* This condition should be satisfied due to the initial filter
+ set up in init_dont_simulate_again. */
+ gcc_assert (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE);
+
+ /* We've set up the lattice values such that IOR neatly models PHI meet. */
+ new_l = UNINITIALIZED;
+ for (i = PHI_NUM_ARGS (phi) - 1; i >= 0; --i)
+ new_l |= find_lattice_value (PHI_ARG_DEF (phi, i));
+
+ ver = SSA_NAME_VERSION (lhs);
+ old_l = VEC_index (complex_lattice_t, complex_lattice_values, ver);
+
+ if (new_l == old_l)
+ return SSA_PROP_NOT_INTERESTING;
+
+ VEC_replace (complex_lattice_t, complex_lattice_values, ver, new_l);
+ return new_l == VARYING ? SSA_PROP_VARYING : SSA_PROP_INTERESTING;
+}
+
+/* Create one backing variable for a complex component of ORIG. */
+
+static tree
+create_one_component_var (tree type, tree orig, const char *prefix,
+ const char *suffix, enum tree_code code)
+{
+ tree r = create_tmp_var (type, prefix);
+ add_referenced_var (r);
+
+ DECL_SOURCE_LOCATION (r) = DECL_SOURCE_LOCATION (orig);
+ DECL_ARTIFICIAL (r) = 1;
+
+ if (DECL_NAME (orig) && !DECL_IGNORED_P (orig))
+ {
+ const char *name = IDENTIFIER_POINTER (DECL_NAME (orig));
+ tree inner_type;
+
+ DECL_NAME (r) = get_identifier (ACONCAT ((name, suffix, NULL)));
+
+ inner_type = TREE_TYPE (TREE_TYPE (orig));
+ SET_DECL_DEBUG_EXPR (r, build1 (code, type, orig));
+ DECL_DEBUG_EXPR_IS_FROM (r) = 1;
+ DECL_IGNORED_P (r) = 0;
+ TREE_NO_WARNING (r) = TREE_NO_WARNING (orig);
+ }
+ else
+ {
+ DECL_IGNORED_P (r) = 1;
+ TREE_NO_WARNING (r) = 1;
+ }
+
+ return r;
+}
+
+/* Retrieve a value for a complex component of VAR. */
+
+static tree
+get_component_var (tree var, bool imag_p)
+{
+ size_t decl_index = DECL_UID (var) * 2 + imag_p;
+ tree ret = cvc_lookup (decl_index);
+
+ if (ret == NULL)
+ {
+ ret = create_one_component_var (TREE_TYPE (TREE_TYPE (var)), var,
+ imag_p ? "CI" : "CR",
+ imag_p ? "$imag" : "$real",
+ imag_p ? IMAGPART_EXPR : REALPART_EXPR);
+ cvc_insert (decl_index, ret);
+ }
+
+ return ret;
+}
+
+/* Retrieve a value for a complex component of SSA_NAME. */
+
+static tree
+get_component_ssa_name (tree ssa_name, bool imag_p)
+{
+ complex_lattice_t lattice = find_lattice_value (ssa_name);
+ size_t ssa_name_index;
+ tree ret;
+
+ if (lattice == (imag_p ? ONLY_REAL : ONLY_IMAG))
+ {
+ tree inner_type = TREE_TYPE (TREE_TYPE (ssa_name));
+ if (SCALAR_FLOAT_TYPE_P (inner_type))
+ return build_real (inner_type, dconst0);
+ else
+ return build_int_cst (inner_type, 0);
+ }
+
+ ssa_name_index = SSA_NAME_VERSION (ssa_name) * 2 + imag_p;
+ ret = VEC_index (tree, complex_ssa_name_components, ssa_name_index);
+ if (ret == NULL)
+ {
+ ret = get_component_var (SSA_NAME_VAR (ssa_name), imag_p);
+ ret = make_ssa_name (ret, NULL);
+
+ /* Copy some properties from the original. In particular, whether it
+ is used in an abnormal phi, and whether it's uninitialized. */
+ SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ret)
+ = SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name);
+ if (TREE_CODE (SSA_NAME_VAR (ssa_name)) == VAR_DECL
+ && IS_EMPTY_STMT (SSA_NAME_DEF_STMT (ssa_name)))
+ {
+ SSA_NAME_DEF_STMT (ret) = SSA_NAME_DEF_STMT (ssa_name);
+ set_default_def (SSA_NAME_VAR (ret), ret);
+ }
+
+ VEC_replace (tree, complex_ssa_name_components, ssa_name_index, ret);
+ }
+
+ return ret;
+}
+
+/* Set a value for a complex component of SSA_NAME, return a STMT_LIST of
+ stuff that needs doing. */
+
+static tree
+set_component_ssa_name (tree ssa_name, bool imag_p, tree value)
+{
+ complex_lattice_t lattice = find_lattice_value (ssa_name);
+ size_t ssa_name_index;
+ tree comp, list, last;
+
+ /* We know the value must be zero, else there's a bug in our lattice
+ analysis. But the value may well be a variable known to contain
+ zero. We should be safe ignoring it. */
+ if (lattice == (imag_p ? ONLY_REAL : ONLY_IMAG))
+ return NULL;
+
+ /* If we've already assigned an SSA_NAME to this component, then this
+ means that our walk of the basic blocks found a use before the set.
+ This is fine. Now we should create an initialization for the value
+ we created earlier. */
+ ssa_name_index = SSA_NAME_VERSION (ssa_name) * 2 + imag_p;
+ comp = VEC_index (tree, complex_ssa_name_components, ssa_name_index);
+ if (comp)
+ ;
+
+ /* If we've nothing assigned, and the value we're given is already stable,
+ then install that as the value for this SSA_NAME. This preemptively
+ copy-propagates the value, which avoids unnecessary memory allocation. */
+ else if (is_gimple_min_invariant (value))
+ {
+ VEC_replace (tree, complex_ssa_name_components, ssa_name_index, value);
+ return NULL;
+ }
+ else if (TREE_CODE (value) == SSA_NAME
+ && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (ssa_name))
+ {
+ /* Replace an anonymous base value with the variable from cvc_lookup.
+ This should result in better debug info. */
+ if (DECL_IGNORED_P (SSA_NAME_VAR (value))
+ && !DECL_IGNORED_P (SSA_NAME_VAR (ssa_name)))
+ {
+ comp = get_component_var (SSA_NAME_VAR (ssa_name), imag_p);
+ replace_ssa_name_symbol (value, comp);
+ }
+
+ VEC_replace (tree, complex_ssa_name_components, ssa_name_index, value);
+ return NULL;
+ }
+
+ /* Finally, we need to stabilize the result by installing the value into
+ a new ssa name. */
+ else
+ comp = get_component_ssa_name (ssa_name, imag_p);
+
+ /* Do all the work to assign VALUE to COMP. */
+ value = force_gimple_operand (value, &list, false, NULL);
+ last = build_gimple_modify_stmt (comp, value);
+ append_to_statement_list (last, &list);
+
+ gcc_assert (SSA_NAME_DEF_STMT (comp) == NULL);
+ SSA_NAME_DEF_STMT (comp) = last;
+
+ return list;
+}