[LLVMdev] GEP vs IntToPtr/PtrToInt
Eli Friedman
eli.friedman at gmail.com
Mon Apr 4 18:54:10 PDT 2011
On Mon, Apr 4, 2011 at 6:38 PM, Arushi Aggarwal <arushi987 at gmail.com> wrote:
> This code is generated for va_arg.
> %6 = getelementptr inbounds %struct.__va_list_tag* %5, i32 0, i32 3 ; <i8**>
> [#uses=1]
> %7 = load i8** %6, align 8 ; <i8*> [#uses=1]
> %8 = getelementptr inbounds [1 x %struct.__va_list_tag]* %ap, i64 0, i64 0
> ; <%struct.__va_list_tag*> [#uses=1]
> %9 = getelementptr inbounds %struct.__va_list_tag* %8, i32 0, i32 0 ;
> <i32*> [#uses=1]
> %10 = load i32* %9, align 8 ; <i32> [#uses=1]
> %11 = inttoptr i32 %10 to i8* ; <i8*> [#uses=1]
> %12 = ptrtoint i8* %7 to i64 ; <i64> [#uses=1]
> %13 = ptrtoint i8* %11 to i64 ; <i64> [#uses=1]
> %14 = add i64 %12, %13 ; <i64> [#uses=1]
> %15 = inttoptr i64 %14 to i8* ; <i8*> [#uses=1]
> store i8* %15, i8** %addr.0, align 8
> and I have optimized one inttoptr to a zext.
> I guess it is safe in this case?
I haven't read your example carefully, but conceptually, the code for
va_arg should be able to use GEP instead of ptrtoint/inttoptr.
-Eli
More information about the llvm-dev
mailing list