浏览代码

Fixed lack of constant folding sometimes putting instructions before PHI's. (#2683)

Adam Yang 5 年之前
父节点
当前提交
76e34cc27d
共有 1 个文件被更改,包括 10 次插入0 次删除
  1. 10 0
      lib/Transforms/Scalar/Scalarizer.cpp

+ 10 - 0
lib/Transforms/Scalar/Scalarizer.cpp

@@ -331,6 +331,16 @@ Scatterer Scalarizer::scatter(Instruction *Point, Value *V) {
                      V, AllowFolding, &Scattered[V]);
 #endif // HLSL Change
   }
+  // HLSL Change - Begin
+  // Allow constant folding for Constant cases, so we don't
+  // put an instruction before a PHI node.
+  if (Constant *C = dyn_cast<Constant>(V)) {
+    if (isa<PHINode>(Point)) {
+      return Scatterer(Point->getParent(), Point,
+                    V, /* allowFolding */ true, &Scattered[V]);
+    }
+  }
+  // HLSL Change - End
   // In the fallback case, just put the scattered before Point and
   // keep the result local to Point.
   // return Scatterer(Point->getParent(), Point, V); // HLSL Change