Ver código fonte

Fix memcpy replacement removing memcpy to output argument (#4456)

Tex Riddell 3 anos atrás
pai
commit
ed717499a7

+ 2 - 1
lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

@@ -3856,8 +3856,9 @@ bool SROA_Helper::LowerMemcpy(Value *V, DxilFieldAnnotation *annotation,
         // For GEP, the ptr could have other GEP read/write.
         // For GEP, the ptr could have other GEP read/write.
         // Only scan one GEP is not enough.
         // Only scan one GEP is not enough.
         // And resource ptr should not be replaced.
         // And resource ptr should not be replaced.
+        // Nor should (output) argument ptr be replaced.
         if (!isa<GEPOperator>(Dest) && !isa<CallInst>(Dest) &&
         if (!isa<GEPOperator>(Dest) && !isa<CallInst>(Dest) &&
-            !isa<BitCastOperator>(Dest)) {
+            !isa<BitCastOperator>(Dest) && !isa<Argument>(Dest)) {
           // Need to make sure Dest not updated after current memcpy.
           // Need to make sure Dest not updated after current memcpy.
           // Check Dest only have 1 store now.
           // Check Dest only have 1 store now.
           hlutil::PointerStatus DestPS(Dest, size, /*bLdStOnly*/ false);
           hlutil::PointerStatus DestPS(Dest, size, /*bLdStOnly*/ false);

+ 18 - 0
tools/clang/test/HLSLFileCheck/hlsl/functions/return_type/array/lib_function.hlsl

@@ -0,0 +1,18 @@
+// RUN: %dxc -T lib_6_3 %s | FileCheck %s
+// RUN: %dxc -T lib_6_6 %s | FileCheck %s
+
+// Tests that non-entry point functions can return arrays in library profile.
+
+// CHECK: define void
+// CHECK-SAME: getA
+// CHECK-SAME: ([2 x i32]* noalias nocapture sret %[[result:.*]])
+export int getA() [2]
+{
+  // CHECK: %[[gep1:.*]] = getelementptr inbounds [2 x i32], [2 x i32]* %[[result]], i32 0, i32 0
+  // CHECK: store i32 1, i32* %[[gep1]]
+  // CHECK: %[[gep2:.*]] = getelementptr inbounds [2 x i32], [2 x i32]* %[[result]], i32 0, i32 1
+  // CHECK: store i32 2, i32* %[[gep2]]
+  int a[2] = { 1, 2 };
+  return a;
+}
+// CHECK: ret void