This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [tree-ssa] More jump threading improvements


Jeff, 
I think that I have discovered a bug in the transformations performed
by the "dom" pass.  Here is a short analysis.  

Basically I was dealing with the regressions introduced by the recent
tree-ssa to lno merge, when I was quite surprised by the conclusions
of my analyzer for the following testcase:

int main(void)
{
  int a;
  int b;

  for (a = 22; a < 50; a+=1)
    {
       for (b = 23; b < 50; b+=5)
	{
	  ++a;
	}
    }
}

The analyzer was expected to answer the following:
a  ->  {{22, +, 7}_1, +, 1}_2

but after the merge, the analyzer answers:
a  ->  {{22, +, 8}_1, +, 1}_2

that means that the variable A has a step 8 in the loop 1 instead of a
step 7.  After having investigated a little, on another example that
showed the same bogus behaviour,

int main(void)
{
  int a = 0;
  int b;
  while (a < 50)
    {
      for (b = 0; b < 10; b++)
        {
	  a++;
        }
      a++;
    }
}

I discovered that the dom-pass transforms the statement of the outer loop 

  a_6 = a_1 + 1; 
into 
  a_15 = a_1 + 2; 

see the representation before and after the dom pass below.  An
interesting thing is that when the inner loop contains a statement
with a different step: say "a += 3", the result after the dom pass is
"a_15 = a_1 + 4".

I don't know enough about the dom pass in order to completely diagnose
this case, but it seems related to the recent changes to this pass.
If you want I can track this behavior down to the patch that introduced it.

Sebastian


The representation before the "dom" pass:

main ()
{
  int b;
  int a;

  # BLOCK 0
  # PRED: ENTRY (fallthru)
  a_4 = 0;
  goto <bb 5> (<L4>);
  # SUCC: 5 (fallthru)

  # BLOCK 1
  # PRED: 5 (true)
<L0>:;
  b_5 = 0;
  goto <bb 3> (<L2>);
  # SUCC: 3 (fallthru)

  # BLOCK 2
  # PRED: 3 (true)
<L1>:;
  a_7 = a_1 + 1;
  b_8 = b_3 + 1;
  # SUCC: 3 (fallthru)

  # BLOCK 3
  # PRED: 2 (fallthru) 1 (fallthru)
  # b_3 = PHI <b_5(1), b_8(2)>;
  # a_1 = PHI <a_2(1), a_7(2)>;
<L2>:;
  if (b_3 <= 9) goto <L1>; else goto <L3>;
  # SUCC: 4 (false) 2 (true)

  # BLOCK 4
  # PRED: 3 (false)
<L3>:;
  a_6 = a_1 + 1;
  # SUCC: 5 (fallthru)

  # BLOCK 5
  # PRED: 4 (fallthru) 0 (fallthru)
  # a_2 = PHI <a_4(0), a_6(4)>;
<L4>:;
  if (a_2 <= 49) goto <L0>; else goto <L5>;
  # SUCC: 6 (false) 1 (true)

  # BLOCK 6
  # PRED: 5 (false)
<L5>:;
  return;
  # SUCC: EXIT

}

and the representation after the "dom" pass:

main ()
{
  int b;
  int a;

  # BLOCK 0
  # PRED: ENTRY (fallthru)
  a_9 = 0;
  a_10 = 0;
  # SUCC: 1 (fallthru)

  # BLOCK 1
  # PRED: 0 (fallthru) 3 (true)
  # a_2 = PHI <0(0), a_15(3)>;
<L0>:;
  b_11 = 0;
  b_12 = 0;
  # SUCC: 2 (fallthru)

  # BLOCK 2
  # PRED: 1 (fallthru) 2 (true)
  # b_3 = PHI <0(1), b_14(2)>;
  # a_1 = PHI <a_2(1), a_13(2)>;
<L1>:;
  a_13 = a_1 + 1;
  b_14 = b_3 + 1;
  if (b_14 <= 9) goto <L1>; else goto <L3>;
  # SUCC: 3 (false) 2 (true)

  # BLOCK 3
  # PRED: 2 (false)
<L3>:;
  a_15 = a_1 + 2;
  if (a_15 <= 49) goto <L0>; else goto <L5>;
  # SUCC: 4 (false) 1 (true)

  # BLOCK 4
  # PRED: 3 (false)
<L5>:;
  return;
  # SUCC: EXIT

}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]