This code is generated for va_arg. <div><div>%6 = getelementptr inbounds %struct.__va_list_tag* %5, i32 0, i32 3 ; <i8**> [#uses=1]</div><div> %7 = load i8** %6, align 8 ; <i8*> [#uses=1]</div>
<div> %8 = getelementptr inbounds [1 x %struct.__va_list_tag]* %ap, i64 0, i64 0 ; <%struct.__va_list_tag*> [#uses=1]</div></div><div><div> %9 = getelementptr inbounds %struct.__va_list_tag* %8, i32 0, i32 0 ; <i32*> [#uses=1]</div>
<div> %10 = load i32* %9, align 8 ; <i32> [#uses=1]</div><div> %11 = inttoptr i32 %10 to i8* ; <i8*> [#uses=1]</div><div> %12 = ptrtoint i8* %7 to i64 ; <i64> [#uses=1]</div>
<div> %13 = ptrtoint i8* %11 to i64 ; <i64> [#uses=1]</div><div> %14 = add i64 %12, %13 ; <i64> [#uses=1]</div><div> %15 = inttoptr i64 %14 to i8* ; <i8*> [#uses=1]</div>
<div> store i8* %15, i8** %addr.0, align 8</div><div><br></div>and I have optimized one inttoptr to a zext.</div><div><br></div><div>I guess it is safe in this case?</div><div><br></div><div><br><div class="gmail_quote">
On Mon, Apr 4, 2011 at 9:10 AM, John Criswell <span dir="ltr"><<a href="mailto:criswell@illinois.edu">criswell@illinois.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On 4/4/2011 6:45 PM, Eli Friedman wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Mon, Apr 4, 2011 at 5:02 PM, Arushi Aggarwal<<a href="mailto:arushi987@gmail.com" target="_blank">arushi987@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
Is it correct to convert,<br>
%196 = load i32* %195, align 8 ;<i32> [#uses=1]<br>
%197 = zext i32 %196 to i64 ;<i64> [#uses=1]<br>
%198 = ptrtoint i8* %193 to i64 ;<i64> [#uses=1]<br>
%199 = add i64 %198, %197 ;<i64> [#uses=1]<br>
%200 = inttoptr i64 %199 to i8* ;<i8*> [#uses=1]<br>
into<br>
%200 = getelementptr %193, %196<br>
Reducing the unnecessary casts of converting to integers and then back?<br>
Thanks,<br>
Arushi<br>
<br>
</blockquote></blockquote>
See <a href="http://llvm.org/docs/LangRef.html#pointeraliasing" target="_blank">http://llvm.org/docs/LangRef.html#pointeraliasing</a> ; it's not<br>
correct in general. It is correct if %196 isn't dependent on the<br>
address of any memory object, though.<br>
</blockquote>
<br></div></div>
Can you clarify why the transform isn't correct? Is it because in the original code, %200 is based on both the originally cast pointer (%193) and the indexed offset from it (%197) while the transformed code is only based on %193?<br>
<br>
Arushi, is some transform converting a GEP into this ptrtoint/inttoptr sequence and thereby adding "based on" relationships that didn't exist previously in the code?<br>
<br>
-- John T.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
-Eli<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote>
<br>
</blockquote></div><br></div>