Antideps analysis fails if an array is written in different branches
The antideps analysis fails with an error "Can't form anti-dependencies when there are two independent writes depending on a single collection value." on programs where the same array is written from different branches.
For example the Juno program
fn foo<n : usize>(inout a : i32[n]) {
for i = 0 to n {
if i % 2 == 0 {
a[i] *= 2;
} else {
a[i] += 2;
}
}
}
or the equivalentish Hercules program
fn foo<1>(x : array(i32, #0)) -> array(i32, #0)
zero = constant(u64, 0)
two = constant(u64, 2)
i_ctrl = fork(start, #0)
i_idx = thread_id(i_ctrl, 0)
if = if(i_ctrl, idx_even)
if_false = projection(if, 0)
if_true = projection(if, 1)
if_join = region(if_true, if_false)
i_join_ctrl = join(if_join)
r = return(i_join_ctrl, update_a)
idx_rem2 = rem(i_idx, two)
idx_even = eq(idx_rem2, zero)
read = read(update_a, position(i_idx))
read_mul2 = mul(read, two)
read_add2 = add(read, two)
arr_true = write(update_a, read_mul2, position(i_idx))
arr_false = write(update_a, read_add2, position(i_idx))
arr = phi(if_join, arr_true, arr_false)
update_a = reduce(i_join_ctrl, x, arr)
Ran into this because there is code like this in Cava.