[PATCH] D20206: GlobalsAA: Don't assume that intrinsics can't access global variables

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Thu May 12 08:20:45 PDT 2016


So this is an interesting question.
Outside of very specific intrinsics (barriers), or intrinsics passed global
variables, which intrinsics do you believe can affect global variables and
why?

:)

(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)

On Thu, May 12, 2016 at 8:12 AM, Tom Stellard via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> 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;
>        }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160512/4fbb9a3c/attachment.html>


More information about the llvm-commits mailing list