[clang] [HLSL] get inout/out ABI for array parameters working (PR #111047)
Chris B via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 4 12:49:53 PST 2024
================
@@ -0,0 +1,134 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -disable-llvm-passes -emit-llvm -finclude-default-header -o - %s | FileCheck %s
+
+// CHECK-LABEL: increment
+void increment(inout int Arr[2]) {
+ for (int I = 0; I < 2; I++)
+ Arr[0] += 2;
+}
+
+// CHECK-LABEL: arrayCall
+// CHECK: [[A:%.*]] = alloca [2 x i32], align 4
+// CHECK-NEXT: [[Tmp:%.*]] = alloca [2 x i32], align 4
+// CHECK-NEXT: [[Tmp2:%.*]] = alloca [2 x i32], align 4
+// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[A]], ptr align 4 @{{.*}}, i32 8, i1 false)
+// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[Tmp]], ptr align 4 [[A]], i32 8, i1 false)
+// CHECK-NEXT: store ptr [[Tmp]], ptr [[Tmp2]], align 4
----------------
llvm-beanz wrote:
This looks wrong... This is storing the address of `Tmp` to the memory pointed to by `Tmp2`.
I'm not entirely sure what is going on to cause this many temporaries to be generated, or what is happening here.
We should have IR something like:
```llvm
%A = alloca [2 x i32]
%Tmp = alloca [2 x i32]
; Initialize A from a global
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %A, ptr align 4 @SOME_GLOBAL_VARIABLE, i32 8, i1 false)
; Initialize Tmp from A
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %Tmp, ptr align 4 %A, i32 8, i1 false)
; Call increment on the temporary array
call void @increment(ptr Tmp)
; copy back the array from Tmp to A
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %A, ptr align 4 %Tmp, i32 8, i1 false)
```
https://github.com/llvm/llvm-project/pull/111047
More information about the cfe-commits
mailing list