<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [NVPTX] byval parameters are incorrectly lowered"
   href="http://llvm.org/bugs/show_bug.cgi?id=21465">21465</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[NVPTX] byval parameters are incorrectly lowered
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Backend: PTX
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>wujingyue@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The current backend treats the base address of a byval parameter as a generic
pointer. However, generic loads don't actually work with a pointer to the
parameter space. Here's a small test case to reproduce this issue:

CUDA:

struct S {
  int a, b;
};

__attribute__((global)) void TakesStruct(S input, int *output) {
  *output = input.b;
}

LLVM IR:

target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
target triple = "nvptx64-unknown-unknown"

%struct.S = type { i32, i32 }

; Function Attrs: nounwind
define void @_Z11TakesStruct1SPi(%struct.S* byval nocapture readonly %input,
i32* nocapture %output) #0 {
entry:
  %b = getelementptr inbounds %struct.S* %input, i64 0, i32 1
  %0 = load i32* %b, align 4, !tbaa !2
  store i32 %0, i32* %output, align 4, !tbaa !7
  ret void
}

attributes #0 = { nounwind "less-precise-fpmad"="false"
"no-frame-pointer-elim"="false" "no-infs-fp-math"="false"
"no-nans-fp-math"="false" "stack-protector-buffer-size"="8"
"unsafe-fp-math"="false" "use-soft-float"="false" }

!nvvm.annotations = !{!0}
!llvm.ident = !{!1}

!0 = metadata !{void (%struct.S*, i32*)* @_Z11TakesStruct1SPi, metadata
!"kernel", i32 1}
!1 = metadata !{metadata !"clang version 3.6.0 (<a href="http://llvm.org/git/clang.git">http://llvm.org/git/clang.git</a>
1f064ca0a944bf0279b0d6508268a4ea0a354b8e) (<a href="http://llvm.org/git/llvm.git">http://llvm.org/git/llvm.git</a>
8744520b533617fbbd55ef12ea936961f5225cf5)"}
!2 = metadata !{metadata !3, metadata !4, i64 4}
!3 = metadata !{metadata !"_ZTS1S", metadata !4, i64 0, metadata !4, i64 4}
!4 = metadata !{metadata !"int", metadata !5, i64 0}
!5 = metadata !{metadata !"omnipotent char", metadata !6, i64 0}
!6 = metadata !{metadata !"Simple C/C++ TBAA"}
!7 = metadata !{metadata !4, metadata !4, i64 0}

PTX (sm_35):

//
// Generated by LLVM NVPTX Back-End
//

.version 3.2
.target sm_35
.address_size 64

    // .globl    _Z11TakesStruct1SPi
                                        // @_Z11TakesStruct1SPi
.visible .entry _Z11TakesStruct1SPi(
    .param .align 4 .b8 _Z11TakesStruct1SPi_param_0[8],
    .param .u64 _Z11TakesStruct1SPi_param_1
)
{
    .reg .s32     %r<2>;
    .reg .s64     %rd<3>;

// BB#0:                                // %entry
    mov.b64    %rd1, _Z11TakesStruct1SPi_param_0;
    ld.param.u64     %rd2, [_Z11TakesStruct1SPi_param_1];
    ld.u32     %r1, [%rd1+4];
    st.u32     [%rd2], %r1;
    ret;
}

The problematic instructions are:
    mov.b64    %rd1, _Z11TakesStruct1SPi_param_0;
    ld.u32     %r1, [%rd1+4];
The compiled kernel crashes because the ld.u32 loads from a pointer to the
parameter space.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>