[Bug tree-optimization/19791] New: [tcb] A constant not fully propagated

kazu@cs.umass.edu gcc-bugzilla@gcc.gnu.org
Sun Feb 6 13:21:00 GMT 2005


Consider:

extern void abort (void) __attribute__ ((__noreturn__));

extern int bar (int, int);

int
foo (int mode, int size, unsigned int align)
{
  int align0;
  int iftmp1;

  if (mode == 0)
    {
      if (align != 128)
	abort ();
    }

  align0 = (int) align;
  if (mode == 0)
    {
      int D1131 = align0 / 8;
      int D1132 = D1131 + size;
      int D1133 = D1132 - 1;
      int D1134 = D1131 - 1;
      int D1135 = ~D1134;

      iftmp1 = D1133 & D1135;
    }
  else
    {
      iftmp1 = size;
    }

  return bar (iftmp1, align0);
}

Note that if we get to the basic block that starts with "int D1131",
we know that align0 == 128, which can be propagated.

The last tree SSA dump looks like so:

foo (mode, size, align)
{
  int prephitmp.1;
  int pretmp.0;
  int D1135;
  int D1134;
  int D1133;
  int D1132;
  int D1131;
  int iftmp1;
  int align0;
  int D.1134;
  int D.1133;

<bb 0>:
  if (mode_4 == 0) goto <L0>; else goto <L10>;

<L0>:;
  if (align_6 != 128) goto <L1>; else goto <L13>;

<L1>:;
  abort ();

<L10>:;
  align0_5 = (int) align_6;

Invalid sum of outgoing probabilities 0.0%
Invalid sum of incoming frequencies 5000, should be 0
  # align0_2 = PHI <align0_5(3)>;
<L2>:;

Invalid sum of incoming frequencies 0, should be 9950
  # align0_7 = PHI <align0_9(6), align0_2(4)>;
  # iftmp1_3 = PHI <iftmp1_18(6), size_11(4)>;
<L6>:;
  D.1133_8 = bar (iftmp1_3, align0_7) [tail call];
  return D.1133_8;

Invalid sum of incoming frequencies 4950, should be 0
  # align0_9 = PHI <128(1)>;
<L13>:;
  D1131_13 = align0_9 / 8;
  D1132_14 = size_11 + D1131_13;
  D1133_15 = D1132_14 - 1;
  D1134_16 = D1131_13 - 1;
  D1135_17 = ~D1134_16;
  iftmp1_18 = D1133_15 & D1135_17;
  goto <bb 5> (<L6>);

}

Notice

  # align0_9 = PHI <128(1)>;

which means we are missing the obvious constant propagation opportunity.

This opportunity is picked up at the RTL level.

On mainline, the opportunity is not as obvious, but the RTL optimizers do
take care of this.

-- 
           Summary: [tcb] A constant not fully propagated
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization, TREE
          Severity: enhancement
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19791



More information about the Gcc-bugs mailing list