[LLVMdev] GEP vs IntToPtr/PtrToInt
Arushi Aggarwal
arushi987 at gmail.com
Mon Apr 4 18:38:20 PDT 2011
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?
On Mon, Apr 4, 2011 at 9:10 AM, John Criswell <criswell at illinois.edu> wrote:
> On 4/4/2011 6:45 PM, Eli Friedman wrote:
>
>> On Mon, Apr 4, 2011 at 5:02 PM, Arushi Aggarwal<arushi987 at gmail.com>
>> wrote:
>>
>>>
>>> Hi,
>>>> Is it correct to convert,
>>>> %196 = load i32* %195, align 8 ;<i32> [#uses=1]
>>>> %197 = zext i32 %196 to i64 ;<i64> [#uses=1]
>>>> %198 = ptrtoint i8* %193 to i64 ;<i64> [#uses=1]
>>>> %199 = add i64 %198, %197 ;<i64> [#uses=1]
>>>> %200 = inttoptr i64 %199 to i8* ;<i8*> [#uses=1]
>>>> into
>>>> %200 = getelementptr %193, %196
>>>> Reducing the unnecessary casts of converting to integers and then back?
>>>> Thanks,
>>>> Arushi
>>>>
>>>> See http://llvm.org/docs/LangRef.html#pointeraliasing ; it's not
>> correct in general. It is correct if %196 isn't dependent on the
>> address of any memory object, though.
>>
>
> 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?
>
> 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?
>
> -- John T.
>
> -Eli
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110404/627a2144/attachment.html>
More information about the llvm-dev
mailing list