Pārlūkot izejas kodu

Prevent repeated memcpy splitting (#2789)

When splitting a memcpy because of faile dependency checks, any memcpy
created to copy part of the original is going to have the same
characteristics that caused the first to be split. Instead of splitting
repeatedly, just use the alternative code generation built into splitCpy
Greg Roth 5 gadi atpakaļ
vecāks
revīzija
a3ebb138ac

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

@@ -3901,6 +3901,7 @@ bool SROA_Helper::LowerMemcpy(Value *V, DxilFieldAnnotation *annotation,
   unsigned size = DL.getTypeAllocSize(Ty->getPointerElementType());
   unsigned size = DL.getTypeAllocSize(Ty->getPointerElementType());
   PointerStatus PS(size);
   PointerStatus PS(size);
   const bool bStructElt = false;
   const bool bStructElt = false;
+  bool bEltMemcpy = true;
   PointerStatus::analyzePointer(V, PS, typeSys, bStructElt);
   PointerStatus::analyzePointer(V, PS, typeSys, bStructElt);
 
 
   if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
   if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
@@ -3931,8 +3932,11 @@ bool SROA_Helper::LowerMemcpy(Value *V, DxilFieldAnnotation *annotation,
     // full replacement isn't possible without complicated PHI insertion
     // full replacement isn't possible without complicated PHI insertion
     // This will likely replace with ld/st which will be replaced in mem2reg
     // This will likely replace with ld/st which will be replaced in mem2reg
     Instruction *Memcpy = PS.StoringMemcpy;
     Instruction *Memcpy = PS.StoringMemcpy;
-    if (!DominateAllUsers(Memcpy, V))
-        PS.storedType = PointerStatus::StoredType::Stored;
+    if (!DominateAllUsers(Memcpy, V)) {
+      PS.storedType = PointerStatus::StoredType::Stored;
+      // Replacing a memcpy with a memcpy with the same signature will just bring us back here
+      bEltMemcpy = false;
+    }
   }
   }
 
 
   if (bAllowReplace && !PS.HasMultipleAccessingFunctions) {
   if (bAllowReplace && !PS.HasMultipleAccessingFunctions) {
@@ -4008,7 +4012,7 @@ bool SROA_Helper::LowerMemcpy(Value *V, DxilFieldAnnotation *annotation,
   }
   }
 
 
   for (MemCpyInst *MC : PS.memcpySet) {
   for (MemCpyInst *MC : PS.memcpySet) {
-    MemcpySplitter::SplitMemCpy(MC, DL, annotation, typeSys);
+    MemcpySplitter::SplitMemCpy(MC, DL, annotation, typeSys, bEltMemcpy);
   }
   }
   return false;
   return false;
 }
 }