<div dir="ltr"><div>Hi Jin,</div><div><br></div>I agree, this looks wrong. The bitcasts are fallout from r226781 - and we should be able to look through them if the size is the same.<div>Can you please file a PR?</div><div><br></div><div>Thanks,</div><div> Michael </div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 17, 2016 at 10:39 AM, Lin, Jin via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="m_-8854093685572264031m_-3024713954707881879WordSection1">
<p class="MsoNormal">Hi ,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">The following loop fails to be vectorized since the load c[i] is casted as i64 and the store c[i] is double. The loop access analysis gives up since they are in different types.
<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Since these two memory operations are in the same size, I believe the loop access analysis should return forward dependence and thus the loop can be vectorized.
<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Any comments?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Jin<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">#define N 1000<u></u><u></u></p>
<p class="MsoNormal">double a[N], b[N],c[N];<u></u><u></u></p>
<p class="MsoNormal">void foo() {<u></u><u></u></p>
<p class="MsoNormal">for (int i=0;i<N;i++) {<u></u><u></u></p>
<p class="MsoNormal">b[i] =c[i];<u></u><u></u></p>
<p class="MsoNormal">c[i]=0.0;<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">for.body: <wbr> ; preds = %for.body, %entry<u></u><u></u></p>
<p class="MsoNormal"> %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]<u></u><u></u></p>
<p class="MsoNormal"> %arrayidx = getelementptr inbounds [1000 x double], [1000 x double]* @c, i64 0, i64 %indvars.iv<u></u><u></u></p>
<p class="MsoNormal"> %0 = bitcast double* %arrayidx to i64*<u></u><u></u></p>
<p class="MsoNormal"><span style="color:#0070c0"> %1 = load i64, i64* %0, align 8, !tbaa !1<u></u><u></u></span></p>
<p class="MsoNormal"> %arrayidx2 = getelementptr inbounds [1000 x double], [1000 x double]* @b, i64 0, i64 %indvars.iv<u></u><u></u></p>
<p class="MsoNormal"> %2 = bitcast double* %arrayidx2 to i64*<u></u><u></u></p>
<p class="MsoNormal"> store i64 %1, i64* %2, align 8, !tbaa !1<u></u><u></u></p>
<p class="MsoNormal"><span style="color:#c00000"> store double 0.000000e+00, double* %arrayidx, align 8, !tbaa !1<u></u><u></u></span></p>
<p class="MsoNormal"> %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1<u></u><u></u></p>
<p class="MsoNormal"> %exitcond = icmp eq i64 %indvars.iv.next, 1000<u></u><u></u></p>
<p class="MsoNormal"> br i1 %exitcond, label %for.cond.cleanup, label %for.body<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">LAA: Found a loop in foo: loop.17<u></u><u></u></p>
<p class="MsoNormal">LAA: Processing memory accesses...<u></u><u></u></p>
<p class="MsoNormal"> AST: Alias Set Tracker: 2 alias sets for 3 pointer values.<u></u><u></u></p>
<p class="MsoNormal"> AliasSet[0x9508b80, 1] must alias, No access Pointers: (<4 x i64>* %1, 18446744073709551615)<u></u><u></u></p>
<p class="MsoNormal"> AliasSet[0x95f8a70, 2] must alias, No access Pointers: (<4 x double>* %2, 18446744073709551615), (<4 x i64>* %0, 18446744073709551615)<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">LAA: Accesses(3):<u></u><u></u></p>
<p class="MsoNormal"> %1 = bitcast double* %arrayIdx11 to <4 x i64>* (write)<u></u><u></u></p>
<p class="MsoNormal"> %2 = bitcast double* %arrayIdx to <4 x double>* (write)<u></u><u></u></p>
<p class="MsoNormal"> %0 = bitcast double* %arrayIdx to <4 x i64>* (read-only)<u></u><u></u></p>
<p class="MsoNormal">Underlying objects for pointer %1 = bitcast double* %arrayIdx11 to <4 x i64>*<u></u><u></u></p>
<p class="MsoNormal"> @b = common local_unnamed_addr global [1000 x double] zeroinitializer, align 16<u></u><u></u></p>
<p class="MsoNormal">Underlying objects for pointer %2 = bitcast double* %arrayIdx to <4 x double>*<u></u><u></u></p>
<p class="MsoNormal"> @c = common local_unnamed_addr global [1000 x double] zeroinitializer, align 16<u></u><u></u></p>
<p class="MsoNormal">Underlying objects for pointer %0 = bitcast double* %arrayIdx to <4 x i64>*<u></u><u></u></p>
<p class="MsoNormal"> @c = common local_unnamed_addr global [1000 x double] zeroinitializer, align 16<u></u><u></u></p>
<p class="MsoNormal">LAA: Found a runtime check ptr: %1 = bitcast double* %arrayIdx11 to <4 x i64>*<u></u><u></u></p>
<p class="MsoNormal">LAA: Found a runtime check ptr: %2 = bitcast double* %arrayIdx to <4 x double>*<u></u><u></u></p>
<p class="MsoNormal">LAA: Found a runtime check ptr: %0 = bitcast double* %arrayIdx to <4 x i64>*<u></u><u></u></p>
<p class="MsoNormal">LAA: We need to do 0 pointer comparisons.<u></u><u></u></p>
<p class="MsoNormal">LAA: We can perform a memory runtime check if needed.<u></u><u></u></p>
<p class="MsoNormal">LAA: Checking memory dependencies<u></u><u></u></p>
<p class="MsoNormal">LAA: Src Scev: {@c,+,32}<nsw><%loop.17>Sink Scev: {@c,+,32}<nsw><%loop.17>(Induc<wbr>tion step: 1)<u></u><u></u></p>
<p class="MsoNormal">LAA: Distance for %gepload = load <4 x i64>, <4 x i64>* %0, align 16, !tbaa !1 to store <4 x double> zeroinitializer, <4 x double>* %2, align 16, !tbaa !1: 0<u></u><u></u></p>
<p class="MsoNormal">LAA: Zero dependence difference but different types<u></u><u></u></p>
<p class="MsoNormal">Total Dependences: 1<u></u><u></u></p>
<p class="MsoNormal">LAA: unsafe dependent memory operations in loop<u></u><u></u></p>
</div>
</div>
<br>______________________________<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" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div>