[PATCH] D20206: GlobalsAA: Don't assume that intrinsics can't access global variables
Tom Stellard via llvm-commits
llvm-commits at lists.llvm.org
Thu May 12 08:12:15 PDT 2016
tstellarAMD created this revision.
tstellarAMD added a reviewer: hfinkel.
tstellarAMD added a subscriber: llvm-commits.
The Gobals Alias Analysis was assuming that intrinsics could never read
or write global variables unless the variable was passed as one of the
arguments to the intrinsic.
I can't find this property of intrinsics documented anywhere, so the
code has been updated to treat intrinsics the same as normal function
calls when analyzing usage of global variables.
This fixes a bug in the AMDGPU backend where this incorrect analysis
was causing to the GVN pass to hoist a load across a barrier intrinsic.
http://reviews.llvm.org/D20206
Files:
lib/Analysis/GlobalsModRef.cpp
test/Analysis/GlobalsModRef/intrinsic-global.ll
Index: test/Analysis/GlobalsModRef/intrinsic-global.ll
===================================================================
--- /dev/null
+++ test/Analysis/GlobalsModRef/intrinsic-global.ll
@@ -0,0 +1,34 @@
+; RUN: opt < %s -globals-aa -gvn -S | FileCheck %s
+
+; Check that gvn will not hoist the load past the @llvm.amdgcn.s.barrier
+; intrinsic, which should be assumed to read/write all global variables
+; since it does not have any attributes that describe its interaction with
+; memory.
+
+ at global = internal addrspace(3) global i32 undef, align 4
+ at global.1 = internal addrspace(3) global i32 undef, align 4
+
+; CHECK-LABEL: @widget
+; CHECK: bb5:
+; CHECK-NEXT: call void @llvm.amdgcn.s.barrier()
+; CHECK-NEXT: %tmp6 = load i32, i32 addrspace(3)* @global.1
+define void @widget(i32 %arg, i32 %arg1, i32 %arg2) #0 {
+bb:
+ %tmp3 = icmp eq i32 %arg2, 0
+ br i1 %tmp3, label %bb4, label %bb5
+
+bb4: ; preds = %bb
+ store i32 0, i32 addrspace(3)* @global.1, align 4
+ br label %bb5
+
+bb5: ; preds = %bb4, %bb
+ call void @llvm.amdgcn.s.barrier() #0
+ %tmp6 = load i32, i32 addrspace(3)* @global.1, align 4
+ store i32 %tmp6, i32 addrspace(3)* @global, align 4
+ ret void
+}
+
+; Function Attrs: convergent nounwind
+declare void @llvm.amdgcn.s.barrier() #0
+
+attributes #0 = { convergent nounwind }
Index: lib/Analysis/GlobalsModRef.cpp
===================================================================
--- lib/Analysis/GlobalsModRef.cpp
+++ lib/Analysis/GlobalsModRef.cpp
@@ -504,9 +504,7 @@
FI.setMayReadAnyGlobal();
} else {
FI.addModRefInfo(MRI_ModRef);
- // Can't say anything useful unless it's an intrinsic - they don't
- // read or write global variables of the kind considered here.
- KnowNothing = !F->isIntrinsic();
+ KnowNothing = true;
}
continue;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D20206.57040.patch
Type: text/x-patch
Size: 1969 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160512/2ed14a76/attachment.bin>
More information about the llvm-commits
mailing list