[llvm-bugs] [Bug 28956] New: GVN clobbers !invariant metadata when widening loads

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Aug 12 14:37:08 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28956

            Bug ID: 28956
           Summary: GVN clobbers !invariant metadata when widening loads
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: justin.lebar at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

When GVN widens a load, it seems to be erasing !invariant.load metadata.

$ opt -gvn -march=nvptx64 -mcpu=sm_35 -debug -S <<EOF
target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v32:32:32-v64:64:64-v128:128:128-n16:32:64"
target triple = "nvptx64-nvidia-cuda"

; CHECK-LABEL: @foo
define i32 @foo(i32* %ptr) {
  %ptr1 = getelementptr i32, i32* %ptr, i32 1
  %p1 = addrspacecast i32* %ptr1 to i32 addrspace(1)*
  %v0 = load i32, i32* %ptr, align 8, !invariant.load !0
  %v1 = load i32, i32* %ptr1, align 4, !invariant.load !0
  %sum = add i32 %v0, %v1
  ret i32 %sum
}

!0 = !{}
EOF

Results in

  %v0 = load i64, i64* %1, align 8 ;  NOTE: Not !invariant.

CUDA has a special load builtin for invariant data, and eventually this gets
lowered to a special NVPTX instruction that's faster than a regular load. 
Currently clang emits an llvm intrinsic for this load, but I'd like to model
them as !invariant loads, so that we can do smart things with them.

This mostly works, except for a few passes that effectively strip off this
metadata -- particularly GVN.

Since GVN actually makes use of !invariant metadata (by way of memdeps), it
seems like it would be friendly of it to preserve this metadata.

See VectorUtils.h's propagateMetadata helper (which doesn't yet propagate
invariance metadata, but I have a patch).

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160812/e8a3d778/attachment.html>


More information about the llvm-bugs mailing list