https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118243

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot 
gnu.org

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
So upon inlining of test.constprop.isra into f1() we have the callees
untransformed body

void test.constprop.isra ()
{
  const complex_t & c;
  const int & x;
  int _1;

  <bb 7> [local count: 1073741824]:

  <bb 2> [local count: 1073741824]:

  <bb 3> [local count: 1073741824]:
  _1 = 123;
  if (_1 < 0)
    goto <bb 4>; [41.00%]
  else
    goto <bb 5>; [59.00%]

  <bb 4> [local count: 440234144]:
  g ("%d\n", _1);
  goto <bb 6>; [100.00%]

  <bb 5> [local count: 633507680]:
  _Z4testRKCiRKi.part.0 (1, 0);

  <bb 6> [local count: 1073741824]:
  return;

which is then turned into

  <bb 4> [local count: 1073741824]:

  <bb 5> [local count: 1073741824]:

  <bb 6> [local count: 1073741824]:
  _9 = 123;
  if (_9 < 0)
    goto <bb 7>; [41.00%]
  else
    goto <bb 8>; [59.00%]

  <bb 7> [local count: 440234144]:
  __builtin_unreachable ();
  goto <bb 9>; [100.00%]

  <bb 8> [local count: 633507680]:
  _Z4testRKCiRKi.part.0.isra (__complex__ (0, 0));

  <bb 9> [local count: 1073741824]:

  <bb 3> [local count: 1073741824]:

we have a

{type = <complex_type 0x7ffff6fc17e0 complex_t>, 
  alias_ptr_type = <reference_type 0x7ffff6fc1930>, unit_offset = 0, 
  base_index = 0, prev_clone_index = 0, op = IPA_PARAM_OP_SPLIT, 
  prev_clone_adjustment = 0, param_prefix_index = 1, reverse = 0, 
  user_flag = 0}

but

      if (repl)
        {
          if (!useless_type_conversion_p(apm->type, repl->typed.type))
            {
              repl = force_value_to_type (apm->type, repl);
              repl = force_gimple_operand_gsi (&gsi, repl,
                                               true, NULL, true,
GSI_SAME_STMT);

makes __complex__ (0, 0) from 1 here.  So the transform stage isn't up
to what the analysis stage seems to handle?

The following fixes this particular type - it's fragile, we don't seem to
have the size of the split part to verify.  Also vectors likely will have
the same issue.  Handling this via type mismatch seems quite fragile.
Maybe vectors are safe as possibly the used BIT_FIELD_REF for element
acccess isn't handled.  Maybe.

diff --git a/gcc/ipa-param-manipulation.cc b/gcc/ipa-param-manipulation.cc
index 9b74fe24cc4..4b594c1c024 100644
--- a/gcc/ipa-param-manipulation.cc
+++ b/gcc/ipa-param-manipulation.cc
@@ -742,7 +742,21 @@ ipa_param_adjustments::modify_call (cgraph_edge *cs,
        {
          if (!useless_type_conversion_p(apm->type, repl->typed.type))
            {
-             repl = force_value_to_type (apm->type, repl);
+             if (TREE_CODE (apm->type) == COMPLEX_TYPE)
+               {
+                 tree zero = build_zero_cst (TREE_TYPE (apm->type));
+                 if (apm->unit_offset == 0)
+                   repl = build_complex (apm->type, repl, zero);
+                 else
+                   {
+                     gcc_assert (compare_tree_int
+                                   (TYPE_SIZE_UNIT (TREE_TYPE (apm->type)),
+                                    apm->unit_offset) == 0);
+                     repl = build_complex (apm->type, zero, repl);
+                   }
+               }
+             else
+               repl = force_value_to_type (apm->type, repl);
              repl = force_gimple_operand_gsi (&gsi, repl,
                                               true, NULL, true,
GSI_SAME_STMT);
            }


I'm testing the above, but ...

Reply via email to