<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body dir="auto">
According to the OpenMP standard, The simd construct can be applied to a loop to indicate that the loop can be transformed into a SIMD loop (that is, multiple iterations of the loop can be executed concurrently using SIMD instructions). It means that the vectorization
 can be performed unconditionally because the user is sure that it is safe to vectorize the loop.<br>
<br>
<div id="AppleMailSignature" dir="ltr">Best regards,
<div>Alexey Bataev</div>
</div>
<div dir="ltr"><br>
26 июня 2019 г., в 5:54, Raja Sekhar Bhetala via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> написал(а):<br>
<br>
</div>
<blockquote type="cite">
<div dir="ltr">
<div dir="ltr"><br clear="all">
<div>Hi All, </div>
<div>   I have a doubt regarding the behavior of LoopAccessAnalysis on incorrect  #pragma omp simd with -fopenmp-simd flag.  </div>
<div>How should the compiler behave if the #pragma omp simd on a loop is incorrect and can be proved by Loop Access Analysis. </div>
<div><br>
</div>
<div>Here is the sample code. </div>
<div>
<p style="margin:7.5pt 0in 0.0001pt;line-height:15pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:10.5pt;font-family:Arial,sans-serif">  #pragma omp simd</span></p>
<p style="margin:7.5pt 0in 0.0001pt;line-height:15pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-family:Arial,sans-serif;font-size:10.5pt">for (dim_t p = 0; p < m; ++p)</span></p>
<p style="margin:7.5pt 0in 0.0001pt;line-height:15pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:10.5pt;font-family:Arial,sans-serif">#pragma unroll </span></p>
<p style="margin:7.5pt 0in 0.0001pt;line-height:15pt;font-size:11pt;font-family:Calibri,sans-serif">
<span style="font-size:10.5pt;font-family:Arial,sans-serif">       for (dim_t i = 0; i < 6; ++i) {<br>
          {<br>
            (((r[i]).real)) += (((a[p + i * lda]).real)) * (((x[p]).real)) +<br>
                               (((a[p + i * lda]).imag)) * (((x[p]).imag));<br>
            (((r[i]).imag)) += (((a[p + i * lda]).imag)) * (((x[p]).real)) -<br>
                               (((a[p + i * lda]).real)) * (((x[p]).imag));<br>
          };<br>
        }</span></p>
</div>
<div>
<div><span style="font-family:Calibri,sans-serif;font-size:11pt">The specification on this loop is incorrect as the parallel_accesses metadata indicate that there is no loop carried memory dependence, which is not true in this case.  </span></div>
<br class="gmail-Apple-interchange-newline">
</div>
<div>In the default flow, LICM hoists and sinks the loads and stores of r[i]  and the loop vectorizer vectorizes this loop based on <span style="font-family:Calibri,sans-serif;font-size:11pt">“llvm.loop.parallel_accesses” metadata. </span></div>
<div><span style="font-family:Calibri,sans-serif;font-size:11pt"><br>
</span></div>
<div><span style="font-family:Calibri,sans-serif;font-size:11pt">If the hoist and sink transformation is prevented for some accesses for some reason in LICM, Loop vectorizer currently generates incorrect vector code without any warning.  Although a check is
 being done in LoopAccessAnalysis.cpp to detect such cases (</span>HasDependenceInvolvingLoopInvariantAddress<span style="font-family:Calibri,sans-serif;font-size:11pt">),  LAA does not warn if the </span><span style="font-family:Calibri,sans-serif;font-size:11pt">“llvm.loop.parallel_accesses”
 metadata is present. <br>
</span></div>
<div><span style="font-family:Calibri,sans-serif;font-size:11pt"><br>
</span></div>
<div><span style="font-size:14.6667px;font-family:Calibri,sans-serif">Is this expected ? </span><br>
</div>
<div><font face="Calibri, sans-serif"><span style="font-size:14.6667px">Shouldn't the compiler not Vectorize if it can prove that there is a loop carried dependence and the Vectorizer will generate an incorrect code ? </span></font></div>
<div><font face="Calibri, sans-serif"><span style="font-size:14.6667px">Or Should it blindly follow the user directive (without a warning) ? </span></font></div>
<div><font face="Calibri, sans-serif"><span style="font-size:14.6667px"><br>
</span></font></div>
<div><span style="font-family:Calibri,sans-serif;font-size:11pt">It is very difficult for the user to identify the real source of the problem if the compiler vectorizes the loop silently. I agree its hard to detect incorrect specifications. But for cases, where
 it is easy to detect we should atleast dump a warning. </span></div>
<div><span style="font-family:Calibri,sans-serif;font-size:11pt"><br>
</span></div>
<div><span style="font-family:Calibri,sans-serif;font-size:11pt">I am attaching a sample input file on which loop vectorizer generates incorrect code. </span></div>
<div><span style="font-family:Calibri,sans-serif;font-size:11pt">run with : opt -loop-vectorize </span><br>
</div>
<div><span style="font-family:Calibri,sans-serif;font-size:11pt"><br>
</span></div>
<div><span style="font-family:Calibri,sans-serif;font-size:11pt">Thanks,</span></div>
<div><span style="font-family:Calibri,sans-serif;font-size:11pt">Rajasekhar</span></div>
<div><br>
</div>
</div>
</div>
</blockquote>
<blockquote type="cite">
<div dir="ltr"><r0.ll></div>
</blockquote>
</body>
</html>