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; } 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. + +@global = internal addrspace(3) global i32 undef, align 4 +@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 }