linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* SSSA and some C pointer manipulation.
@ 2017-08-19  2:46 Christopher Li
  2017-08-19  9:46 ` Dibyendu Majumdar
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Christopher Li @ 2017-08-19  2:46 UTC (permalink / raw)
  To: Luc Van Oostenryck; +Cc: Linux-Sparse

Hi Luc,

I have done the first round of reading your 29 patches.
It is actually very nice organized. Thanks for the effort
to make this review so easy to digest.

One thing I notices is that, if the use site is very far
from define, there are a lot of blocks in between. That
will cause a lot of possible phi node to be created.
That plus the ptrmap will have some memory allocation
over head. Might explain the 2% slow down.
Compare to classic way to convert to SSA. The expansive
part is doing the dominator tree. However that is mostly
read, very few write. The SSA is doing a lot of write
(creating phi node just in case it is needed.)

Another thing I just realized is that, this SSSA conversion
only works for *local* variable, not C pointers?
I want to construct some test source to verify.
However it is not even working for the base case:

================test 1.c=========
int a, b, c, d, e;

static void foo(void)
{
if (a)
b = c;
else
b = d;
if (c)
a = b;
if (b)
e = a;
}

for this test, none of the global variable access has
been promote to SSA. In this regard, it is different
in master. The master branch at least try to promote
a, b, c, d, e content pseudot to ssa.

This is from sssa-mini-v1
foo:
.L0:
<entry-point>
load.32     %r1 <- 0[a]
cbr         %r1, .L1, .L2

.L1:
load.32     %r2 <- 0[c]
store.32    %r2 -> 0[b]
br          .L3

.L2:
load.32     %r3 <- 0[d]
store.32    %r3 -> 0[b]
br          .L3

.L3:
load.32     %r4 <- 0[c]
cbr         %r4, .L4, .L5

.L4:
load.32     %r5 <- 0[b]
store.32    %r5 -> 0[a]
br          .L5

.L5:
load.32     %r6 <- 0[b]
cbr         %r6, .L6, .L8

.L6:
load.32     %r7 <- 0[a]
store.32    %r7 -> 0[e]
br          .L8

.L8:
ret

No phi at all.

============== test 2.c ==========
int a, c, d;

static int foo(void)
{
int b, e;
if (a)
b = c;
else
b = d;
if (c)
a = b;
if (b)
e = a;
return e;
}

static int foo_ptr(void)
{
int b, *bp = &b;
int e, *ep = &e;

if (a)
*bp = c;
else
*bp = d;
if (c)
a = *bp;
if (b)
e = a;
return e;
}
==============
There are two functions foo() and foo_ptr(),
The are exactly the same, except foo_ptr() is using
ptr to access the variable. The pointer is not used
for another other purpose.

You can see in the foo base, the variable b
has been promote to SSA. However, in foo_ptr()
the variable b has not been promote to SSA.

I look back the paper, the paper actually did not
discuss pointer at all. However pointer usage is
a big part of C. So in this regard, the previous master
branch actually try to promote the variable used by
pointers, because it first convert the symbol to symbol
address and using load and store to access them.

That I see as another big draw back the paper
haven't cover, (other than goto. ) The pointers.
It can't effectively deal with pointer because it
does not have the CFG yet. In that regard, this
series functionally is less than what is in the previous
master branch does. Given the previous master does
it incorrectly. I think fixing them wouldn't be much
bigger than what is needed for SSSA.

If we want to deal with pointer, I suspect it will need
to do more or less the SSSA paper  trying to avoid.
Do the CFG route and promote memory access to
pseudo. That means we can't remove that code in
patch 29 and also need to make it work as well.

Any idea how to make the above two test case
work?

Chris

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2017-08-23  1:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-19  2:46 SSSA and some C pointer manipulation Christopher Li
2017-08-19  9:46 ` Dibyendu Majumdar
2017-08-19 10:56   ` Christopher Li
2017-08-19 11:57     ` Dibyendu Majumdar
2017-08-19 12:39       ` Christopher Li
2017-08-20  0:08       ` Luc Van Oostenryck
2017-08-20  0:33         ` Dibyendu Majumdar
2017-08-20 14:45           ` Luc Van Oostenryck
2017-08-20 16:18 ` Luc Van Oostenryck
2017-08-21  3:29   ` Christopher Li
2017-08-21  3:41     ` Christopher Li
2017-08-23  1:03 ` Luc Van Oostenryck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).