<div dir="ltr"><div>Hi Johannes,</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 9 Jul 2019 at 01:01, Doerfert, Johannes <<a href="mailto:jdoerfert@anl.gov">jdoerfert@anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The whole object "escapes" into bar as it can be defined similar to the code below:<br>
<br>
void bar(int *x) {<br>
struct st *ST = ((char*)x) - offsetof(struct st, b));<br>
ptr = &ST->a;<br>
*ptr = 999; // Initial upper bound, overwritten by ptr[0] = 0;<br>
}<br>
<br></blockquote><div><br></div><div>Yes I was trying to do this. Thank you. </div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
---------------------------------------<br>
Johannes Doerfert<br>
Researcher<br>
<br>
Argonne National Laboratory<br>
Lemont, IL 60439, USA<br>
<br>
<a href="mailto:jdoerfert@anl.gov" target="_blank">jdoerfert@anl.gov</a><br><br></blockquote><div>regards,</div><div>Venkat. </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
________________________________________<br>
From: llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>> on behalf of Venkataramanan Kumar via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
Sent: Monday, July 8, 2019 13:31<br>
To: llvm-dev<br>
Subject: [llvm-dev] Question on Aliasing and invariant load hoisting<br>
<br>
Hi,<br>
<br>
I have the below test case.<br>
--snip--<br>
struct st {<br>
int a;<br>
int b;<br>
};<br>
<br>
int * ptr;<br>
int x,y;<br>
<br>
void bar(int *x);<br>
<br>
void foo() {<br>
struct st obj;<br>
bar(&obj.b);<br>
if(x)<br>
obj.a =x;<br>
else<br>
obj.a =y;<br>
<br>
for (int i=0; i<obj.a;i++)<br>
ptr[i]=i;<br>
}<br>
--snip--<br>
<br>
LLVM IR produced at -O3 is shown below.<br>
ref: <a href="https://godbolt.org/z/WPlmfr" rel="noreferrer" target="_blank">https://godbolt.org/z/WPlmfr</a><br>
<br>
--Snip--<br>
%8 = getelementptr inbounds %<a href="http://struct.st" rel="noreferrer" target="_blank">struct.st</a><<a href="http://struct.st" rel="noreferrer" target="_blank">http://struct.st</a>>, %<a href="http://struct.st" rel="noreferrer" target="_blank">struct.st</a><<a href="http://struct.st" rel="noreferrer" target="_blank">http://struct.st</a>>* %1, i64 0, i32 0, !dbg !39<br>
store i32 %7, i32* %8, align 4, !dbg !40<br>
call void @llvm.dbg.value(metadata i32 0, metadata !26, metadata !DIExpression()), !dbg !41<br>
%9 = icmp sgt i32 %7, 0, !dbg !42<br>
br i1 %9, label %10, label %12, !dbg !44<br>
<br>
%11 = load i32*, i32** @ptr, align 8, !tbaa !45<br>
br label %13, !dbg !44<br>
<br>
call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %2) #4, !dbg !47<br>
ret void, !dbg !47<br>
<br>
%14 = phi i64 [ 0, %10 ], [ %17, %13 ]<br>
call void @llvm.dbg.value(metadata i64 %14, metadata !26, metadata !DIExpression()), !dbg !41<br>
%15 = getelementptr inbounds i32, i32* %11, i64 %14, !dbg !48<br>
%16 = trunc i64 %14 to i32, !dbg !49<br>
store i32 %16, i32* %15, align 4, !dbg !49, !tbaa !33<br>
%17 = add nuw nsw i64 %14, 1, !dbg !50<br>
call void @llvm.dbg.value(metadata i32 undef, metadata !26, metadata !DIExpression(DW_OP_plus_uconst, 1, DW_OP_stack_value)), !dbg !41<br>
%18 = load i32, i32* %8, align 4, !dbg !51, !tbaa !52<br>
%19 = sext i32 %18 to i64, !dbg !42<br>
%20 = icmp slt i64 %17, %19, !dbg !42<br>
br i1 %20, label %13, label %12, !dbg !44, !llvm.loop !54<br>
}<br>
--Snip---<br>
<br>
Question is why the load IR and sext IR (obj.a) is not getting hoisted out of the loop?<br>
--Snip--<br>
%18 = load i32, i32* %8, align 4, !dbg !51, !tbaa !52<br>
%19 = sext i32 %18 to i64, !dbg !42<br>
--Snip<br>
<br>
is it because the "obj.a" can alias with "ptr" ?<br>
We are passing only "&obj.b" to bar. But still variable "ptr" is considered to be aliasing with "obj.a" ?<br>
<br>
regards,<br>
Venkat.<br>
</blockquote></div></div>