Browse Source

When MemcpySplitter::PatchMemCpyWithZeroIdxGEP, not go inside matrix. (#901)

Xiang Li 7 years ago
parent
commit
639e12c118

+ 3 - 0
lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

@@ -2340,6 +2340,9 @@ static unsigned MatchSizeByCheckElementType(Type *Ty, const DataLayout &DL, unsi
   unsigned ptrSize = DL.getTypeAllocSize(Ty);
   // Size match, return current level.
   if (ptrSize == size) {
+    // Not go deeper for matrix.
+    if (HLMatrixLower::IsMatrixType(Ty))
+      return level;
     // For struct, go deeper if size not change.
     // This will leave memcpy to deeper level when flatten.
     if (StructType *ST = dyn_cast<StructType>(Ty)) {

+ 16 - 0
tools/clang/test/CodeGenHLSL/quick-test/field_mat_copy.hlsl

@@ -0,0 +1,16 @@
+// RUN: %dxc -E main -T ps_6_0 %s | FileCheck %s
+
+// Make sure matrix only struct copy works.
+// CHECK: main
+
+struct Mat
+{
+ float2x2 m;
+};
+
+Mat m;
+
+float4 main() :SV_Target {
+    Mat lm = m;
+    return lm.m;
+}