<div dir="ltr">So it looks like AA is being too conservative in aliasSameBasePointerGEPs. <div><br></div><div>For example:</div><div>#define N 10<br>struct foo {<br> float a[N];//[N];<br> float b[N];<br>};<br><br>void compute(struct foo *p )<br>{<br> for (int i = 0; i < N; i++) {<br> p->a[i] += 0.1f * p->b[i];<br> }<br>} <br></div><div><br></div><div>vectorizes. </div><div><br></div><div>There is this code:</div><div><br></div><div>if (GEP1->getNumIndices() != GEP2->getNumIndices() ||<br> GEP1->getNumIndices() < 2)<br> {<br> errs()<<"1\n";<br> return MayAlias;<br> }<br></div><div><br></div><div>which appears to return MayAlias anytime the numder of indices don't equal each other, why? This doesn't seem right.</div><div><br></div><div>Seems like this is being overly conservative. Anytime any GEPs have the same base pointer with different indices this is going to return MayAlias.</div><div><br></div><div>Thanks,</div><div><br></div><div>Ryan</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 15, 2021 at 9:19 AM Ryan Taylor <<a href="mailto:ryta1203@gmail.com" target="_blank">ryta1203@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I see Roman has commented on the ticket. The issue is alias analysis it looks like, we have a partial fix in place in BasicAliasAnalysis.cpp:<div><br></div><div> unsigned MinNumIndex = std::min(GEP1->getNumIndices(), <br> GEP2->getNumIndices());<br> if (MinNumIndex < 2)<br> return MayAlias;<br> SmallVector<Value *, 8> IntermediateIndices;<br> IntermediateIndices.push_back(GEP1->getOperand(1));<br> // Note, <br> // 1. The index to struct field can only be literal constant.<br> // 2. So far all the struct field indexes are the same respectively.<br> // 3. The array indexes could be different, but they don't matter here.<br> // 4. The types should be the same, say, different array indexes don't<br> // matter, and the struct indexes be the same respectively.<br> // If current type is StructType, and the pair of corresponding indexes<br> // are not equal, NoAlias<br> for (unsigned i = 1; i != MinNumIndex - 1; ++i) {<br> if (isa<StructType>(GetElementPtrInst::getIndexedType(<br> GEP1->getSourceElementType(), IntermediateIndices))) {<br> ConstantInt *C1 = dyn_cast<ConstantInt>(GEP1->getOperand(i + 1));<br> ConstantInt *C2 = dyn_cast<ConstantInt>(GEP2->getOperand(i + 1));<br> if (C1 && C2 && C1->getSExtValue() != C2->getSExtValue())<br> return NoAlias;<br> }<br> IntermediateIndices.push_back(GEP1->getOperand(i + 1));<br> }<br> }<br> // Note that we fall back the original logic here, there are still some thing<br> // not covered like p->a[2].x v.s. p->a[1].x.b[2]<br></div><div><br></div><div>but this seems to break some cases and isn't generalized.</div><div><br></div><div>-Ryan</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 15, 2021 at 5:05 AM Simon Pilgrim via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<p>I've reported this here:
<a href="https://bugs.llvm.org/show_bug.cgi?id=51103" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=51103</a></p>
<div>On 15/07/2021 04:04, Ryan Taylor via
llvm-dev wrote:<br>
</div>
<blockquote type="cite">
<div dir="ltr">Given a test case:
<div><br>
</div>
<div>#define N 10<br>
struct foo {<br>
float a[N][N];<br>
float b[N];<br>
};<br>
<br>
void compute(struct foo *p)<br>
{<br>
for (int i = 0; i < N; i++) {<br>
for (int j = 0; j < N; j++) {<br>
p->a[i][j] += 0.1f * p->b[i];<br>
}<br>
}<br>
}<br>
</div>
<div><br>
</div>
<div>LLVM isn't able to vectorize this code. I'm not sure what
the issue is here as it seems to vectorize this code:</div>
<div><br>
</div>
<div>#define N 10<br>
struct foo {<br>
float a[N];<br>
float b[N];<br>
};<br>
<br>
void compute(struct foo *p)<br>
{<br>
for (int i = 0; i < N; i++) {<br>
p->a[i] += 0.1f * p->b[i];<br>
}<br>
}<br>
</div>
<div><br>
</div>
<div>Is this a known issue?</div>
<div><br>
</div>
<div>-Ryan</div>
</div>
<br>
<fieldset></fieldset>
<pre>_______________________________________________
LLVM Developers mailing list
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
</div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
</blockquote></div>