<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><p class="MsoNormal">> Does this kind of IR have “undefined behavior” under LLVM semantics or is it acceptable?<u></u><u></u></p><br class="gmail-Apple-interchange-newline"><div>I think this should be well defined. C11 says</div><div><br></div><div>6.5.2.3 Structure and union members<br></div><div><div>95) If the member used to read the contents of a union object is not the same as the member last used to</div><div>store a value in the object, the appropriate part of the object representation of the value is reinterpreted</div><div>as an object representation in the new type as described in 6.2.6 (a process sometimes called ‘‘type</div><div>punning’’). This might be a trap representation.</div></div><div><br></div><div>(I'm using this pdf file for the text - <a href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf">http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf</a> )</div><div><br></div><div>I guess peephole optimizations also can lead to the load/store with different types (e.g. memcpy to/from an unsigned char array can be removed if redundant), so the code seems to make sense.</div><div><br></div><div>Best Regards,</div><div>Juneyoung Lee</div></div></div></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Sun, Nov 18, 2018 at 11:03 PM De Azevedo Piovezan, Felipe via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><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_-1388050075638927047WordSection1">
<p class="MsoNormal">Hi,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Does this kind of IR have “undefined behavior” under LLVM semantics or is it acceptable?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">(TLDR: a store of i64 at offset n, followed by a load of i32 at offset n+1.)<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">define void @foo(i32* %A, i64 %n) {<u></u><u></u></p>
<p class="MsoNormal">entry:<u></u><u></u></p>
<p class="MsoNormal"> %arrayidx = getelementptr inbounds i32, i32* %A, i64 %n<u></u><u></u></p>
<p class="MsoNormal"> %arrayidx_cast = bitcast i32* %arrayidx to i64*<u></u><u></u></p>
<p class="MsoNormal"> store i64 0, i64* %arrayidx_cast, align 4<u></u><u></u></p>
<p class="MsoNormal"> %add1 = add i64 %n, 1<u></u><u></u></p>
<p class="MsoNormal"> %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 %add1<u></u><u></u></p>
<p class="MsoNormal"> %0 = load i32, i32* %arrayidx2, align 4<u></u><u></u></p>
<p class="MsoNormal"> ret void<u></u><u></u></p>
<p class="MsoNormal">}<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">The result of Dependence Analysis is:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">opt -analyze -da BitCasts.ll <u></u><u></u></p>
<p class="MsoNormal">Printing analysis 'Dependence Analysis' for function 'z0':<u></u><u></u></p>
<p class="MsoNormal">da analyze - none! <<< this is between the store and itself, ok to be “none”.<u></u><u></u></p>
<p class="MsoNormal">da analyze - none! <<< this is between the store and the load!!!<u></u><u></u></p>
<p class="MsoNormal">da analyze - none! <<< this is between the load and itself, ok to be “none”.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Is dependence analysis right or wrong? This IR likely comes from some C++ code doing funny things with unions…<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">--<u></u><u></u></p>
<p class="MsoNormal">Felipe de Azevedo Piovezan<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</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="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><br></div><font size="1">Juneyoung Lee</font><div><font size="1">Software Foundation Lab, Seoul National University</font></div></div></div>