[LLVMdev] TBAA metadata

Daniel Berlin dberlin at dberlin.org
Thu Apr 9 16:01:03 PDT 2015


On Thu, Apr 9, 2015 at 3:58 PM, Xin Tong <trent.tong at gmail.com> wrote:
> On Thu, Apr 9, 2015 at 1:58 PM, Daniel Berlin <dberlin at dberlin.org> wrote:
>> On Thu, Apr 9, 2015 at 1:11 PM, Xin Tong <trent.tong at gmail.com> wrote:
>>> Hi
>>>
>>> I do not really understand why frontend generated TBAA metadata is
>>> needed for the TBAA pass to work. It seems to me that we can always go
>>> up the IR chain and find the base type from which the pointer is
>>> derived from. Take the following example.
>>>
>>
>> LLVM Types != C types
>>
>>
>>> I know %0 = load i32, i32* %a, align 4, !tbaa !1 and   store i32
>>> %i.02, i32* %b, align 4, !tbaa !6
>>> do not alias as their metadata !1 = !{!2, !3, i64 0} and !6 = !{!7,
>>> !3, i64 0} tell me that they are derived from different (incompatible)
>>> basetypes.
>>> However i can also walk up the IR chain and find out %a is
>>> point to basetype object of struct A and %b pointing to basetype
>>> object of  struct B.
>>
>> Which tells you precisely nothing since LLVM has no inherent language,
>> and thus, no inherent rules about aliasing :)
>>
>> It is perfectly legal to inttoptr, cast, whatever.
>
> I see, but should not users be discouraged (or prohibited) from
> writing a LLVM function in which they cast a struct A* to a struct B*
> or vice versa and then linking with a LLVM IR generated from a C
> program and still claim this is strict-C-aliasing compliant ?

???
The right thing will happen here.
The parts it can optimize, it will optimize, the parts it can't, it own't.

>
> I guess i am not getting how this is possible, the only ways i can
> think of are to write something in LLVM IR directly or compile some C
> programs (with castings) with fno-strict-aliasing and then link it
> with a C program compiled with strict-aliasing.

Or you know, don't use C?



More information about the llvm-dev mailing list