<div dir="ltr">Thank You</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 28, 2017 at 5:20 PM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"><div><div class="h5">
<p><br>
</p>
<div class="m_-1894187437857369949moz-cite-prefix">On 06/27/2017 11:36 PM, Serge Preis
wrote:<br>
</div>
<blockquote type="cite">
<div> </div>
<div>Hello,</div>
<div> </div>
<div>The message basically means that llvm failed to recognize
C[i][j] as valid reduction. In order to make C[i][j] valid
reduction is to be privatized into some scalar value for the
innermost loop. In you case aliasing analysis fails to prove
that C[i][j] never aliases with A and B and this seems correct.
So you need something like this to make loop vectorizable:</div>
<div> </div>
<div>be explicit:</div>
<div> </div>
<div>
<div>
<div>#include <stdio.h></div>
<div>#define N 1000</div>
<div> </div>
<div>// This function multiplies A[][] and B[][], and stores</div>
<div>// the result in C[][]</div>
<div>void multiply(int A[][N], int B[][N], int C[][N])</div>
<div>{</div>
<div> int i, j, k;</div>
<div> for (i = 0; i < N; i++)</div>
<div> {</div>
<div> for (j = 0; j < N; j++)</div>
<div> {</div>
<div>int res = 0;</div>
<div> for (k = 0; k < N; k++)</div>
<div> res += A[i][k]*B[k][j];</div>
<div>
<div>C[i][j] = res;</div>
</div>
<div> }</div>
<div> }</div>
<div>}</div>
</div>
</div>
<div> </div>
<div>or just add restrict to arguments:</div>
<div> </div>
<div>
<div>
<div>
<div>// This function multiplies A[][] and B[][], and stores</div>
<div>// the result in C[][]</div>
<div>void multiply(int A[restrict][N], int B[restrict][N],
int C[restrict][N])</div>
<div>{</div>
<div> int i, j, k;</div>
<div> for (i = 0; i < N; i++)</div>
<div> {</div>
<div> for (j = 0; j < N; j++)</div>
<div> {</div>
<div> for (k = 0; k < N; k++)</div>
<div> C[i][j] += A[i][k]*B[k][j];</div>
<div>
<div> }</div>
</div>
<div> }</div>
<div>}</div>
</div>
</div>
</div>
</blockquote>
<br></div></div>
I'd advised Hameeza to file a bug report for this. We should be able
to vectorize this without the restrict by emitting runtime checks.<br>
<br>
-Hal<div><div class="h5"><br>
<br>
<blockquote type="cite">
<div>
<div> </div>
</div>
<div> </div>
<div>On the practical side of things though the following loops
reordering should provide much better performance when
vectorizsed because in your case you have gather operation
(strided load) from B + costly reduce operation in j-loop.</div>
<div> </div>
<div>
<div>
<div>
<div>#include <stdio.h></div>
<div>#define N 1000</div>
<div> </div>
<div>// This function multiplies A[][] and B[][], and stores</div>
<div>// the result in C[][]</div>
<div>void multiply(int A[][N], int B[][N], int C[][N])</div>
<div>{</div>
<div> int i, j, k;</div>
<div> for (i = 0; i < N; i++)</div>
<div> {</div>
<div>
<div> for (j = 0; j < N; j++)</div>
C[i][j] = 0;</div>
<div>
<div> for (k = 0; k < N; k++) {</div>
for (j = 0; j < N; j++)</div>
<div> {</div>
<div> C[i][j] += A[i][k]*B[k][j];</div>
<div>
<div> }</div>
<div>}</div>
</div>
<div> }</div>
<div>}</div>
</div>
</div>
</div>
<div> </div>
<div> </div>
<div> </div>
<div>28.06.2017, 02:54, "hameeza ahmed via llvm-dev"
<a class="m_-1894187437857369949moz-txt-link-rfc2396E" href="mailto:llvm-dev@lists.llvm.org" target="_blank"><llvm-dev@lists.llvm.org></a>:</div>
<blockquote type="cite">
<div>Hello,
<div>i am trying to vectorize a simple matrix multiplication
in llvm;</div>
<div>here is my code;</div>
<div> </div>
<div>
<div>#include <stdio.h></div>
<div>#define N 1000</div>
<div> </div>
<div>// This function multiplies A[][] and B[][], and stores</div>
<div>// the result in C[][]</div>
<div>void multiply(int A[][N], int B[][N], int C[][N])</div>
<div>{</div>
<div> int i, j, k;</div>
<div> for (i = 0; i < N; i++)</div>
<div> {</div>
<div> for (j = 0; j < N; j++)</div>
<div> {</div>
<div> C[i][j] = 0;</div>
<div> for (k = 0; k < N; k++)</div>
<div> C[i][j] += A[i][k]*B[k][j];</div>
<div> }</div>
<div> }</div>
<div>}</div>
</div>
<div> </div>
<div>here are the commands;</div>
<div> </div>
<div> </div>
<div> </div>
<div>
<div>clang -S -emit-llvm mat.c -march=knl -O3 -mllvm
-disable-llvm-optzns -o mat.ll</div>
</div>
<div> </div>
<div>
<div>opt -S -O3 mat.ll -o mat_o3.ll</div>
</div>
<div> </div>
<div>
<div>llc -x86-asm-syntax=intel mat_o3.ll -o mat_intel.s</div>
</div>
<div> </div>
<div> </div>
<div>with this command i got the below error</div>
<div>
<div>opt -S -O3 -force-vector-width=16 mat.ll -o mat_o3.ll</div>
<div> </div>
<div> </div>
<div>remark: <unknown>:0:0: loop not vectorized: value
that could not be identified as reduction is used outside
the loop</div>
</div>
<div> </div>
<div> </div>
<div>it is unable to vectorize the matrix multiplication and
in .ll and .s files i see the scalar instructions.</div>
<div> </div>
<div>Why is that so? What is my mistake?? Kindly correct me.</div>
<div> </div>
<div>Looking forward to your reply</div>
<div> </div>
<div>Thank You</div>
<div> </div>
</div>
,
<p>______________________________<wbr>_________________<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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a></p>
</blockquote>
</blockquote>
<br>
</div></div><span class="HOEnZb"><font color="#888888"><pre class="m_-1894187437857369949moz-signature" cols="72">--
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
</font></span></div>
</blockquote></div><br></div>