How to check that two ssa registers have the same symbolic value

Jeffrey Law law@redhat.com
Tue May 29 16:24:00 GMT 2007


On Tue, 2007-05-29 at 18:25 +0300, Victor Kaplansky wrote:
> Hello,
> 
> I'm working on a pass performing store-sinking
> as in following example:
> 
> if (c)
>   p[i] = x;
> else
>   p[i] = y;
> 
> The idea is to perform store sinking:
> 
> if (c)
>   tmp = x;
> else
>   tmp = y;
> 
> a[i] = tmp;
> 
> The objective is to help if-convert pass to get rid of conditional
> branches, which can be very expansive on some architectures.
> 
> I have a difficulty to recognize the same store location in both
> clauses of if. Sometimes it is not enough to use operand_equal_p().
> For above example, the tree-ssa looks like:
> 
> <bb 0>:
>   if (c_1 != 0) goto <L0>; else goto <L1>;
> 
> <L0>:;
>   i.0_9 = (unsigned int) i_2;
>   D.1284_10 = i.0_9 * 4;
>   D.1285_11 = (int *) D.1284_10;
>   D.1286_12 = p_6 + D.1285_11;
>   *D.1286_12 = x_13;
>   goto <bb 3> (<L2>);
> 
> <L1>:;
>   i.0_3 = (unsigned int) i_2;
>   D.1284_4 = i.0_3 * 4;
>   D.1285_5 = (int *) D.1284_4;
>   D.1286_7 = p_6 + D.1285_5;
>   *D.1286_7 = y_8;
> 
> <L2>:;
> 
> What is the easy/right way to check that D.1286_12 and D.1286_7
> point to the same location (have same symbolic value).
In this specific case, you could hoist all the address computation
into the start of bb0 since they are anticipatable at the start
of bb0.  That would effectively give you something like this:

<bb 0>:
  i.0_3 = (unsigned int i_2);
  D.1284_4 = i.0_3 * 4;
  D.1285_5 = (int *) D. 1284_4;
  D.1286_7 = p_6 + D.1285_5
  if (c_1 != 0) goto <L0>; else goto <L1>;

  <L0>:;
    *D.1286_7 = x_13
    goto <bb3> (<L2>);

  <L1>:;
    *D.1286_7 = y_8

  <L2>:;

At which point you've got a fighting chance to sink the store.

Note that this form of  code hoisting is generally a win from a
codesize standpoint.  We have an RTL implementation, but not a
tree-ssa implementation IIRC.

JEff




More information about the Gcc-patches mailing list