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>