[llvm-dev] MayAlias in MemorySSA

Alina Sbirlea via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 9 12:27:47 PST 2021


Hi,

1. Alias information is only informative. It is displayed for accesses that
have been optimized and it is stored as part of the memory access that
displays it.
2. MayAlias for that instruction means the load instruction reads from a
location that may overlap with locations written to by `call void @foo`.
In your example foo only reads to I suspect that if you add `readnone` to
its attribute list, `MemoryUse(6) MayAlias` will become `MemoryUse(4)
MustAlias`.

Best,
Alina

On Tue, Mar 9, 2021 at 10:16 AM sushant gokhale via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> For the following C code:
>
> __attribute__((noinline)) void foo(int i,int j){    printf("%d %d",i,j);}int main(){    int j;    int k;    scanf("%d%d",&j,&k);    j+=10;    k-=3;    //func call to force the stores    foo(j,k);    //func call to force the loads    printf("%d %d",j,k);}
>
>
> The MemSSA generated is:
> define dso_local i32 @main() #2 {
>   %1 = alloca i32, align 4
>   %2 = alloca i32, align 4
>   %3 = bitcast i32* %1 to i8*
> ; 1 = MemoryDef(liveOnEntry)
>   call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %3) #5
>   %4 = bitcast i32* %2 to i8*
> ; 2 = MemoryDef(1)
>   call void @llvm.lifetime.start.p0i8(i64 4, i8* nonnull %4) #5
>   %5 = getelementptr inbounds [5 x i8], [5 x i8]* @.str.1, i64 0, i64 0
> ; 3 = MemoryDef(2)
>   %6 = call i32 (i8*, ...) @__isoc99_scanf(i8* %5, i32* nonnull %1, i32*
> nonnull %2)
> ; MemoryUse(3) MayAlias
>   %7 = load i32, i32* %1, align 4, !tbaa !5
>   %8 = add nsw i32 %7, 10
> ; 4 = MemoryDef(3)
>   store i32 %8, i32* %1, align 4, !tbaa !5
> ; MemoryUse(3) MayAlias
>   %9 = load i32, i32* %2, align 4, !tbaa !5
>   %10 = add nsw i32 %9, -3
> ; 5 = MemoryDef(4)
>   store i32 %10, i32* %2, align 4, !tbaa !5
> ; 6 = MemoryDef(5)
>   call void @foo(i32 %8, i32 %10)
> ; MemoryUse(6) MayAlias
>   %11 = load i32, i32* %1, align 4, !tbaa !5
> ; MemoryUse(6) MayAlias
>   %12 = load i32, i32* %2, align 4, !tbaa !5
>   %13 = getelementptr inbounds [6 x i8], [6 x i8]* @.str, i64 0, i64 0
> ; 7 = MemoryDef(6)
>   %14 = call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) %13,
> i32 %11, i32 %12)
>
> Now, considering the block:
> MemoryUse(6) MayAlias
>   %11 = load i32, i32* %1, align 4, !tbaa !5
>
> I have 2 questions:
> 1.why is Alias information shown alongwith MemSSA graph?
> 2. what does MayAlias mean here? Does it mean that this load may depend
> upon operand being referred/modified  in 6 = MemoryDef(5) ?  Or is it
> something else?
>
> Regards
> Sushant
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210309/25ed296e/attachment.html>


More information about the llvm-dev mailing list