Explorar o código

Disable alloca merge when inline to make remove alloca easy. (#2349)

* Disable alloca merge when inline to make remove alloca easy.
Xiang Li %!s(int64=6) %!d(string=hai) anos
pai
achega
7264e48bcb

+ 7 - 0
lib/Transforms/IPO/Inliner.cpp

@@ -153,6 +153,12 @@ static bool InlineCallIfPossible(CallSite CS, InlineFunctionInfo &IFI,
 
   AdjustCallerSSPLevel(Caller, Callee);
 
+  // HLSL Change Begin- not merge allocas.
+  // Merge alloca will make alloca which has one def become multi def.
+  // SROA will fail to remove the merged allocas.
+  return true;
+  // HLSL Change End.
+#if 0 // HLSL Change - disable unused code.
   // Look at all of the allocas that we inlined through this call site.  If we
   // have already inlined other allocas through other calls into this function,
   // then we know that they have disjoint lifetimes and that we can merge them.
@@ -269,6 +275,7 @@ static bool InlineCallIfPossible(CallSite CS, InlineFunctionInfo &IFI,
   }
   
   return true;
+#endif
 }
 
 unsigned Inliner::getInlineThreshold(CallSite CS) const {

+ 2 - 4
tools/clang/test/CodeGenHLSL/batch/declarations/hoist_constant_array/11.hlsl

@@ -1,9 +1,7 @@
 // RUN: %dxc -Emain -Tps_6_0 %s | %FileCheck %s
-// CHECK: alloca [3 x i32]
+// CHECK-NOT: alloca [3 x i32]
 
-// We could get hoist the arrays individually but the two allocas are
-// merged by inlining and that prevents hoisting. It becomes a good
-// negative test because different constants are written to the alloca.
+// We disabled alloca merge when inline, now the allocas will be removed.
 
 int foo(int i) {
     int A[] = {1,2,3};

+ 36 - 0
tools/clang/test/CodeGenHLSL/batch/expressions/argument_passing/array_arg_alloca_merge.hlsl

@@ -0,0 +1,36 @@
+// RUN: %dxc -E main -T ps_6_0  %s | FileCheck %s
+
+// Tests that no alloca is left for copy parameter.
+// CHECK-NOT: alloca
+
+float4 buf[20];
+float4 buf2[20];
+
+float4 BufLd(float4 b[20], int i) {
+
+  return b[i];
+
+}
+
+float4 BufLd2(float4 b[20], int i) {
+
+  return b[i] + BufLd(buf2, i+1);
+
+}
+
+float4 BufLd3(int i) {
+
+ return BufLd2(buf, i);
+
+}
+
+
+float4 BufLd4(int i) {
+
+ return BufLd2(buf, i+1);
+
+}
+
+float4 main(int i:I) : SV_Target {
+  return BufLd3(i) + BufLd4(i*2);
+}

+ 40 - 0
tools/clang/test/CodeGenHLSL/batch/expressions/argument_passing/buf_arg_alloca_merge.hlsl

@@ -0,0 +1,40 @@
+// RUN: %dxc -E main -T ps_6_0  %s | FileCheck %s
+
+// Tests that no alloca is left for copy parameter.
+// CHECK-NOT: alloca
+// CHECK:call %dx.types.ResRet.f32 @dx.op.bufferLoad.f32(i32 68
+// CHECK:call %dx.types.ResRet.f32 @dx.op.bufferLoad.f32(i32 68
+// CHECK:call %dx.types.ResRet.f32 @dx.op.bufferLoad.f32(i32 68
+// CHECK:call %dx.types.ResRet.f32 @dx.op.bufferLoad.f32(i32 68
+
+Buffer<float4> buf[10];
+Buffer<float4> buf2[20];
+
+float4 BufLd(Buffer<float4> b[], int i) {
+
+  return b[i][i];
+
+}
+
+float4 BufLd2(Buffer<float4> b[], int i) {
+
+  return b[i][i] + BufLd(buf2, i+1);
+
+}
+
+float4 BufLd3(int i) {
+
+ return BufLd2(buf, i);
+
+}
+
+
+float4 BufLd4(int i) {
+
+ return BufLd2(buf, i+1);
+
+}
+
+float4 main(int i:I) : SV_Target {
+  return BufLd3(i) + BufLd4(i*2);
+}