missing load simplification
commit5636cd5cbf816f30ee57d580ec4debd8e0bd7581
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>
Wed, 4 Jan 2017 03:03:21 +0000 (4 04:03 +0100)
committerChristopher Li <sparse@chrisli.org>
Mon, 13 Feb 2017 01:34:45 +0000 (13 09:34 +0800)
tree1a600d68617996638e90486e72808412a64dc0ef
parentc8757aa484fbc45a33baa0b87fdb248f5f14d01d
missing load simplification

In memops:find_dominating_parents(), the 'load-load optimization'
(see commit cf07903a "Don't bother finding dominating loads if ...")
cause some loads simplification to be missed.
For example, with the following code:
int foo(int *i, int *j)
{
*i = 6;
*j = 1;

do {
if (*i != 6)
(*i)++;
(*i)++;
} while (*i != *j);

return *j;
}

test-linearize returns something like:
foo:
.L0:
<entry-point>
store.32    $6 -> 0[%arg1]
store.32    $1 -> 0[%arg2]
br          .L1

.L1:
load.32     %r4 <- 0[%arg1]
setne.32    %r5 <- %r4, $6
br          %r5, .L4, .L5

.L4:
add.32      %r8 <- %r4, $1
store.32    %r8 -> 0[%arg1]
br          .L5

.L5:
load.32     %r10 <- 0[%arg1]
add.32      %r11 <- %r10, $1
store.32    %r11 -> 0[%arg1]
load.32     %r15 <- 0[%arg2]
setne.32    %r16 <- %r11, %r15
br          %r16, .L1, .L6

.L6:
ret.32      %r15

where we can notice that the first load in .L5 is not needed,
the value could be retrieved from %r4 and %r8, like:
@@ -8,15 +8,17 @@
 .L1:
  load.32     %r4 <- 0[%arg1]
  setne.32    %r5 <- %r4, $6
+ phisrc.32   %phi4 <- %r4
  br          %r5, .L4, .L5

 .L4:
  add.32      %r8 <- %r4, $1
  store.32    %r8 -> 0[%arg1]
+ phisrc.32   %phi5 <- %r8
  br          .L5

 .L5:
- load.32     %r10 <- 0[%arg1]
+ phi.32      %r10 <- %phi4, %phi5
  add.32      %r11 <- %r10, $1
  store.32    %r11 -> 0[%arg1]
  load.32     %r15 <- 0[%arg2]

The fix essentially consists in reverting commit cf07903a but on
memops.c's version of find_dominating_parents().

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Signed-off-by: Christopher Li <sparse@chrisli.org>
memops.c