<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/149991>149991</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DA] Assume coefficient of subscript is non-zero
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:analysis
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
kasuga-fj
</td>
</tr>
</table>
<pre>
Input:
```llvm
define void @f(ptr %a, i64 %k) {
entry:
br label %loop
loop:
%i = phi i64 [ 0, %entry ], [ %i.next, %loop ]
%subscript = mul i64 %i, %k
%idx = getelementptr i8, ptr %a, i64 %subscript
store i8 42, ptr %idx
%i.next = add i64 %i, 1
%cond.exit = icmp eq i64 %i.next, 100
br i1 %cond.exit, label %exit, label %loop
exit:
ret void
}
```
Result:
```
$ opt -passes='print<da>' -disable-output test.ll
Printing analysis 'Dependence Analysis' for function 'f':
Src: store i8 42, ptr %idx, align 1 --> Dst: store i8 42, ptr %idx, align 1
da analyze - none!
```
godbolt: https://godbolt.org/z/6eq4W84q5
This is incorrect when `%k` is zero, where the store accesses the same memory location in all iterations. At first glance, it seems that some routines in DA assume that the coefficient of the subscript is non-zero, which is not always the case.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVF9vq7gT_TTOy4gIxhCSBx5ouZF-bz_trrTPjhmCb41NbdM2_fQrG5reP9VqJUtxZo7PHB8PI7xXV0PUsOqBVd1OLGG0rnkSfrmKbPi-u9j-1vzPzEtgvGV5Wod8XVq_TCxvexqUIXixqgdW5gPD4xwcMKwEw0dQhzLunxiegNUPLG_JBHdb6QAuDrS4kI4Ybe281ki7DcGwUsB4B_OoVrbqAfJIzbBKXMCqLv2vHhJ6b-gtbIDIlPIblV8uXjo1h0Q5LfpDoNoOPN2L9m8Jc6VAmiYyIV5LHSPuiwveidN5H6wjUEco8Qe86t_u7ElkKiD6_icRxQdGWtPv6U2tMCWnGej5Dr3fssjzDytV8dO5mL27-1vg0-6U2ux2FNJbxkzd_fjeK_YP8ov-ohviHkuwc4BsFt6TZ7xjWM9OmcD4Yy8Y_8awhqxXXlw0ZXYJ8xIgkA97rVne_j9ClbmCMELfvPLAsO5oJtOTkQTtFo4sg3UwLEYGZU2EDQzrVdSfTjL-r0-AjyC0uhooIMsY_wadD__5SDKpF6vGd4IMjDXEsPjdqqvtLzZ5BWMIs4_68MzwvCX21l0Znt8Zng_0XP59LJ-r9eRfo_IQl5HWOZIBXkcyEJljhx7ymHwnZ6Ow15EcQRhp0y-kpOj_GhITwUSTdTfQVorklzIgtAYVyKWA30MbYFDOB7hqYSSlxg7giabIIwJ4OxE4uwRlKAqDrgXh_TLRmo_FpKVhUFKRCWCHtf79e1M-OpV9qlZyXIMBhH4Vt1WwFJ72u77h_YmfxI6aoq54UZ_qut6NjTwiP9aiHg415qI8cjxWhwrlcDxUnPd8pxrMscprxCJHrOp9xXmOgrg4FWV1KC-szGkSSu_j-IovsFPeL9QU5el0Knbp6_BpHiKmCcdbce87jEPSNTGeXZarZ2WulQ_-kyyooNM47VpWddCuDv1izJem7Banm1_6RIVxueylnRiek5j1J5ud_U4yMDwn8Z7hedP_0uA_AQAA__9UvsR9">