Ver código fonte

Don't add nested loop for HLSL when loop has multiple back edge. (#1557)

Xiang Li 7 anos atrás
pai
commit
98e3d19d7c

+ 3 - 1
lib/Transforms/Utils/LoopSimplify.cpp

@@ -583,7 +583,9 @@ ReprocessLoop:
     // If this is really a nested loop, rip it out into a child loop.  Don't do
     // this for loops with a giant number of backedges, just factor them into a
     // common backedge instead.
-    if (L->getNumBackEdges() < 8) {
+    if (L->getNumBackEdges() < 8
+        && false // HLSL Change - don't add nested loop.
+        ) {
       if (Loop *OuterL =
               separateNestedLoop(L, Preheader, AA, DT, LI, SE, PP, AC)) {
         ++NumNested;

+ 25 - 0
tools/clang/test/CodeGenHLSL/quick-ll-test/no_nest_loop.hlsl

@@ -0,0 +1,25 @@
+// RUN: %dxc -E main -T ps_6_0 %s | %opt -loops -analyze -S | FileCheck %s
+
+// Make sure no nested loop.
+// CHECK-NOT: Loop at depth 2
+// CHECK: Loop at depth 1
+
+uint c;
+Buffer<uint> buf;
+Buffer<float2> buf2;
+float main(float a:A, float b:B) : SV_Target {
+   float r = c;
+   uint idx = buf[0];
+   while (idx)  {
+     idx >>= 1;
+
+     float2 data = buf2[idx];
+     if (all(data > 0.5)) {
+       r += sin(data.x);
+       r *= cos(data.y);
+     }
+  }
+
+  return r;
+
+}