call-with-alloca-buffer.ll 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ; RUN: llc < %s -march=nvptx64 -mcpu=sm_20 | FileCheck %s
  2. ; Checks how NVPTX lowers alloca buffers and their passing to functions.
  3. ;
  4. ; Produced with the following CUDA code:
  5. ; extern "C" __attribute__((device)) void callee(float* f, char* buf);
  6. ;
  7. ; extern "C" __attribute__((global)) void kernel_func(float* a) {
  8. ; char buf[4 * sizeof(float)];
  9. ; *(reinterpret_cast<float*>(&buf[0])) = a[0];
  10. ; *(reinterpret_cast<float*>(&buf[1])) = a[1];
  11. ; *(reinterpret_cast<float*>(&buf[2])) = a[2];
  12. ; *(reinterpret_cast<float*>(&buf[3])) = a[3];
  13. ; callee(a, buf);
  14. ; }
  15. ; CHECK: .visible .entry kernel_func
  16. define void @kernel_func(float* %a) {
  17. entry:
  18. %buf = alloca [16 x i8], align 4
  19. ; CHECK: .local .align 4 .b8 __local_depot0[16]
  20. ; CHECK: mov.u64 %SPL
  21. ; CHECK: ld.param.u64 %rd[[A_REG:[0-9]+]], [kernel_func_param_0]
  22. ; CHECK: cvta.to.global.u64 %rd[[A1_REG:[0-9]+]], %rd[[A_REG]]
  23. ; FIXME: casting A1_REG to A2_REG is unnecessary; A2_REG is essentially A_REG
  24. ; CHECK: cvta.global.u64 %rd[[A2_REG:[0-9]+]], %rd[[A1_REG]]
  25. ; CHECK: cvta.local.u64 %rd[[SP_REG:[0-9]+]]
  26. ; CHECK: ld.global.f32 %f[[A0_REG:[0-9]+]], [%rd[[A1_REG]]]
  27. ; CHECK: st.local.f32 [{{%rd[0-9]+}}], %f[[A0_REG]]
  28. %0 = load float, float* %a, align 4
  29. %1 = bitcast [16 x i8]* %buf to float*
  30. store float %0, float* %1, align 4
  31. %arrayidx2 = getelementptr inbounds float, float* %a, i64 1
  32. %2 = load float, float* %arrayidx2, align 4
  33. %arrayidx3 = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i64 0, i64 1
  34. %3 = bitcast i8* %arrayidx3 to float*
  35. store float %2, float* %3, align 4
  36. %arrayidx4 = getelementptr inbounds float, float* %a, i64 2
  37. %4 = load float, float* %arrayidx4, align 4
  38. %arrayidx5 = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i64 0, i64 2
  39. %5 = bitcast i8* %arrayidx5 to float*
  40. store float %4, float* %5, align 4
  41. %arrayidx6 = getelementptr inbounds float, float* %a, i64 3
  42. %6 = load float, float* %arrayidx6, align 4
  43. %arrayidx7 = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i64 0, i64 3
  44. %7 = bitcast i8* %arrayidx7 to float*
  45. store float %6, float* %7, align 4
  46. ; CHECK: .param .b64 param0;
  47. ; CHECK-NEXT: st.param.b64 [param0+0], %rd[[A2_REG]]
  48. ; CHECK-NEXT: .param .b64 param1;
  49. ; CHECK-NEXT: st.param.b64 [param1+0], %rd[[SP_REG]]
  50. ; CHECK-NEXT: call.uni
  51. ; CHECK-NEXT: callee,
  52. %arraydecay = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i64 0, i64 0
  53. call void @callee(float* %a, i8* %arraydecay) #2
  54. ret void
  55. }
  56. declare void @callee(float*, i8*)
  57. !nvvm.annotations = !{!0}
  58. !0 = !{void (float*)* @kernel_func, !"kernel", i32 1}