[PATCH] D131268: [HLSL] Generate buffer subscript operators

Chris Bieneman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 5 12:09:03 PDT 2022

beanz added inline comments.

Comment at: clang/lib/Sema/HLSLExternalSemaSource.cpp:220
+    // Const subscript operators return copies of elements, non-const return a
+    // reference so that they are assignable.
python3kgae wrote:
> If we reuse this function for StructuredBuffer, then const subscript return a const reference could be better?
Why? Since this should get inlined return value optimization should eliminate the redundant copies.

Comment at: clang/test/CodeGenHLSL/buffer-array-operator.hlsl:4
+const RWBuffer<float> In;
+RWBuffer<float> Out;
python3kgae wrote:
> Maybe change In to RWBuffer<float4>
> And Out[Idx] = In[Idx].z;
> So we also test vector case?
None of the added code here depends on the template parameter type. Putting a vector in increases the complexity of the output, but I'm unsure it extends the test coverage meaningfully.

Comment at: clang/test/CodeGenHLSL/buffer-array-operator.hlsl:16
+// CHECK: float @"??A?$RWBuffer at M@hlsl@@QBAMI at Z"
+// CHECK: %this1 = load ptr, ptr %this.addr, align 4
+// CHECK-NEXT: %h = getelementptr inbounds %"class.hlsl::RWBuffer", ptr %this1, i32 0, i32 0
python3kgae wrote:
> Where is the this.addr coming from?
That is how clang generates stored locations for input parameters.

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list