<div dir="ltr"><div>Hello Michael, A very good Morning to you.<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Nov 20, 2019 at 10:58 PM Michael Kruse <<a href="mailto:llvm@meinersbur.de">llvm@meinersbur.de</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">Am Mi., 20. Nov. 2019 um 10:21 Uhr schrieb HAPPY Mahto<br>
<<a href="mailto:cs17btech11018@iith.ac.in" target="_blank">cs17btech11018@iith.ac.in</a>>:<br>
>> #pragma clang loop vectorize_assume_alignment(32)<br>
>> for(int i = 0;i < n; i++){<br>
>> a[i] = b[i] + i*i;<br>
>> }<br>
><br>
>  for this all-access inside the loop will be aligned to 32bit,<br>
> ex  IR<br>
>><br>
>> for.cond:                                         ; preds = %for.inc, %entry<br>
>>   %5 = load i32, i32* %i, align 32, !llvm.access.group !2<br>
>>   %6 = load i32, i32* %n, align 32, !llvm.access.group !2<br>
>>   %cmp = icmp slt i32 %5, %6<br>
>>   br i1 %cmp, label %for.body, label %for.end<br>
>><br>
>> for.body:                                         ; preds = %for.cond<br>
>>   %7 = load i32, i32* %i, align 32, !llvm.access.group !2<br>
>>   %8 = load i32, i32* %i, align 32, !llvm.access.group !2<br>
>>   %idxprom = sext i32 %8 to i64<br>
>>   %arrayidx = getelementptr inbounds i32, i32* %vla1, i64 %idxprom<br>
>>   store i32 %7, i32* %arrayidx, align 32, !llvm.access.group !2<br>
>>   br label %for.inc<br>
>><br>
>> for.inc:                                          ; preds = %for.body<br>
>>   %9 = load i32, i32* %i, align 32, !llvm.access.group !2<br>
>>   %inc = add nsw i32 %9, 1<br>
>>   store i32 %inc, i32* %i, align 32, !llvm.access.group !2<br>
>>   br label %for.cond, !llvm.loop !3<br>
><br>
> You will not need to create pointers for every array(or operand you want to perform the operation on).<br>
<br>
IMHO it is better if the programmer has to. It is not always obvious<br>
which arrays are used in the loop. Also, the information can be used<br>
by other optimzations that the vectorizer.<br>
<br></blockquote><div> We wrote this pragma in by keeping in mind that arrays inside the important loops are used for vectorization and it'll be good for them to be in aligned manner.</div><div>for( int i = 0; i < n; i++){</div><div>  a[i] = b[i] + c[i];</div><div>  d[i] = e[i] + i*i;</div><div>}<br></div><div>If there are more than 4-5 arrays inside loop being used then it'll be extra effort to define all of them as _builtin_assume_aligned, we're thinking of letting that thing handled by pragma itself. It'll be very helpful for us if other people from community can give their views on this.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
>><br>
>> void mult(float* x, int size, float factor){<br>
>>   float* ax = (float*)__builtin_assume_aligned(x, 64);<br>
>>   for (int i = 0; i < size; ++i)<br>
>>      ax[i] *= factor;<br>
>> }<br>
<br>
<a href="https://godbolt.org/z/Fd6HMe" rel="noreferrer" target="_blank">https://godbolt.org/z/Fd6HMe</a><br>
<br>
> the alignment is assumed whereas in #pragma it is set to the number specified.<br>
<br>
Semantically, it is the same.<br>
<br>
I wonder how you expect the assembly output to change? The<br>
__builtin_assume_aligned, will be picked up by the backend and result<br>
in movaps to be used instead of movups.<br>  
<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> it'll be easier, and having a pragma for doing this will help as it's provided in OMP and intel compilers.<br>
<br>
This is a compiler-specific extension. It does not have an influence<br>
on what other compilers do. Even with clang, if you try to do<br>
<br>
#pragma clang loop vectorize_assume_alignment(32)<br>
#pragma omp simd<br>
for (int i = 0; i < size; ++i)<br>
<br>
clang will silently swallow the vectorize_assume_alignment.<br>
<br>
<br>
Michael<br>
</blockquote></div></div>