<div dir="ltr">So this is an interesting question.<div>Outside of very specific intrinsics (barriers), or intrinsics passed global variables, which intrinsics do you believe can affect global variables and why?<br><br></div><div>:)</div><div><br></div><div>(Because if the answer is "none", we should probably make the ability to read/write non-passed-in globals an intrinsic property that folks have to opt-in to) </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 12, 2016 at 8:12 AM, Tom Stellard via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">tstellarAMD created this revision.<br>
tstellarAMD added a reviewer: hfinkel.<br>
tstellarAMD added a subscriber: llvm-commits.<br>
<br>
The Gobals Alias Analysis was assuming that intrinsics could never read<br>
or write global variables unless the variable was passed as one of the<br>
arguments to the intrinsic.<br>
<br>
I can't find this property of intrinsics documented anywhere, so the<br>
code has been updated to treat intrinsics the same as normal function<br>
calls when analyzing usage of global variables.<br>
<br>
This fixes a bug in the AMDGPU backend where this incorrect analysis<br>
was causing to the GVN pass to hoist a load across a barrier intrinsic.<br>
<br>
<a href="http://reviews.llvm.org/D20206" rel="noreferrer" target="_blank">http://reviews.llvm.org/D20206</a><br>
<br>
Files:<br>
  lib/Analysis/GlobalsModRef.cpp<br>
  test/Analysis/GlobalsModRef/intrinsic-global.ll<br>
<br>
Index: test/Analysis/GlobalsModRef/intrinsic-global.ll<br>
===================================================================<br>
--- /dev/null<br>
+++ test/Analysis/GlobalsModRef/intrinsic-global.ll<br>
@@ -0,0 +1,34 @@<br>
+; RUN: opt < %s -globals-aa -gvn -S | FileCheck %s<br>
+<br>
+; Check that gvn will not hoist the load past the @llvm.amdgcn.s.barrier<br>
+; intrinsic, which should be assumed to read/write all global variables<br>
+; since it does not have any attributes that describe its interaction with<br>
+; memory.<br>
+<br>
+@global = internal  addrspace(3) global i32 undef, align 4<br>
+@global.1 = internal  addrspace(3) global i32 undef, align 4<br>
+<br>
+; CHECK-LABEL: @widget<br>
+; CHECK: bb5:<br>
+; CHECK-NEXT: call void @llvm.amdgcn.s.barrier()<br>
+; CHECK-NEXT: %tmp6 = load i32, i32 addrspace(3)* @global.1<br>
+define void @widget(i32 %arg, i32 %arg1, i32 %arg2) #0 {<br>
+bb:<br>
+  %tmp3 = icmp eq i32 %arg2, 0<br>
+  br i1 %tmp3, label %bb4, label %bb5<br>
+<br>
+bb4:                                              ; preds = %bb<br>
+  store i32 0, i32 addrspace(3)* @global.1, align 4<br>
+  br label %bb5<br>
+<br>
+bb5:                                              ; preds = %bb4, %bb<br>
+  call void @llvm.amdgcn.s.barrier() #0<br>
+  %tmp6 = load i32, i32 addrspace(3)* @global.1, align 4<br>
+  store i32 %tmp6, i32 addrspace(3)* @global, align 4<br>
+  ret void<br>
+}<br>
+<br>
+; Function Attrs: convergent nounwind<br>
+declare void @llvm.amdgcn.s.barrier() #0<br>
+<br>
+attributes #0 = { convergent nounwind }<br>
Index: lib/Analysis/GlobalsModRef.cpp<br>
===================================================================<br>
--- lib/Analysis/GlobalsModRef.cpp<br>
+++ lib/Analysis/GlobalsModRef.cpp<br>
@@ -504,9 +504,7 @@<br>
             FI.setMayReadAnyGlobal();<br>
         } else {<br>
           FI.addModRefInfo(MRI_ModRef);<br>
-          // Can't say anything useful unless it's an intrinsic - they don't<br>
-          // read or write global variables of the kind considered here.<br>
-          KnowNothing = !F->isIntrinsic();<br>
+          KnowNothing = true;<br>
         }<br>
         continue;<br>
       }<br>
<br>
<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>