|
| 1 | +From af809ec100ef60cdeeef776e54c123e4fc8f1071 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jameson Nash <vtjnash@gmail.com> |
| 3 | +Date: Tue, 15 Dec 2020 10:04:08 -0500 |
| 4 | +Subject: [PATCH] GlobalISel: remove assert that memcpy Src and Dst addrspace |
| 5 | + must be identical |
| 6 | + |
| 7 | +The LangRef does not require these arguments to have the same type. |
| 8 | + |
| 9 | +Differential Revision: https://reviews.llvm.org/D93154 |
| 10 | +--- |
| 11 | + .../lib/CodeGen/GlobalISel/CombinerHelper.cpp | 27 +++++++++++-------- |
| 12 | + 1 file changed, 16 insertions(+), 11 deletions(-) |
| 13 | + |
| 14 | +diff --git llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp |
| 15 | +index 79f74a47d83c..7bd6f8f52c8b 100644 |
| 16 | +--- llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp |
| 17 | ++++ llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp |
| 18 | +@@ -1240,7 +1240,6 @@ bool CombinerHelper::optimizeMemcpy(MachineInstr &MI, Register Dst, |
| 19 | + // of that value loaded. This can result in a sequence of loads and stores |
| 20 | + // mixed types, depending on what the target specifies as good types to use. |
| 21 | + unsigned CurrOffset = 0; |
| 22 | +- LLT PtrTy = MRI.getType(Src); |
| 23 | + unsigned Size = KnownLen; |
| 24 | + for (auto CopyTy : MemOps) { |
| 25 | + // Issuing an unaligned load / store pair that overlaps with the previous |
| 26 | +@@ -1258,15 +1257,20 @@ bool CombinerHelper::optimizeMemcpy(MachineInstr &MI, Register Dst, |
| 27 | + Register LoadPtr = Src; |
| 28 | + Register Offset; |
| 29 | + if (CurrOffset != 0) { |
| 30 | +- Offset = MIB.buildConstant(LLT::scalar(PtrTy.getSizeInBits()), CurrOffset) |
| 31 | +- .getReg(0); |
| 32 | +- LoadPtr = MIB.buildPtrAdd(PtrTy, Src, Offset).getReg(0); |
| 33 | ++ LLT LoadTy = MRI.getType(Src); |
| 34 | ++ Offset = |
| 35 | ++ MIB.buildConstant(LLT::scalar(LoadTy.getSizeInBits()), CurrOffset) |
| 36 | ++ .getReg(0); |
| 37 | ++ LoadPtr = MIB.buildPtrAdd(LoadTy, Src, Offset).getReg(0); |
| 38 | + } |
| 39 | + auto LdVal = MIB.buildLoad(CopyTy, LoadPtr, *LoadMMO); |
| 40 | + |
| 41 | + // Create the store. |
| 42 | +- Register StorePtr = |
| 43 | +- CurrOffset == 0 ? Dst : MIB.buildPtrAdd(PtrTy, Dst, Offset).getReg(0); |
| 44 | ++ Register StorePtr = Dst; |
| 45 | ++ if (CurrOffset != 0) { |
| 46 | ++ LLT StoreTy = MRI.getType(Dst); |
| 47 | ++ StorePtr = MIB.buildPtrAdd(StoreTy, Dst, Offset).getReg(0); |
| 48 | ++ } |
| 49 | + MIB.buildStore(LdVal, StorePtr, *StoreMMO); |
| 50 | + CurrOffset += CopyTy.getSizeInBytes(); |
| 51 | + Size -= CopyTy.getSizeInBytes(); |
| 52 | +@@ -1343,7 +1347,6 @@ bool CombinerHelper::optimizeMemmove(MachineInstr &MI, Register Dst, |
| 53 | + // Apart from that, this loop is pretty much doing the same thing as the |
| 54 | + // memcpy codegen function. |
| 55 | + unsigned CurrOffset = 0; |
| 56 | +- LLT PtrTy = MRI.getType(Src); |
| 57 | + SmallVector<Register, 16> LoadVals; |
| 58 | + for (auto CopyTy : MemOps) { |
| 59 | + // Construct MMO for the load. |
| 60 | +@@ -1353,9 +1356,10 @@ bool CombinerHelper::optimizeMemmove(MachineInstr &MI, Register Dst, |
| 61 | + // Create the load. |
| 62 | + Register LoadPtr = Src; |
| 63 | + if (CurrOffset != 0) { |
| 64 | ++ LLT LoadTy = MRI.getType(Src); |
| 65 | + auto Offset = |
| 66 | +- MIB.buildConstant(LLT::scalar(PtrTy.getSizeInBits()), CurrOffset); |
| 67 | +- LoadPtr = MIB.buildPtrAdd(PtrTy, Src, Offset).getReg(0); |
| 68 | ++ MIB.buildConstant(LLT::scalar(LoadTy.getSizeInBits()), CurrOffset); |
| 69 | ++ LoadPtr = MIB.buildPtrAdd(LoadTy, Src, Offset).getReg(0); |
| 70 | + } |
| 71 | + LoadVals.push_back(MIB.buildLoad(CopyTy, LoadPtr, *LoadMMO).getReg(0)); |
| 72 | + CurrOffset += CopyTy.getSizeInBytes(); |
| 73 | +@@ -1370,9 +1374,10 @@ bool CombinerHelper::optimizeMemmove(MachineInstr &MI, Register Dst, |
| 74 | + |
| 75 | + Register StorePtr = Dst; |
| 76 | + if (CurrOffset != 0) { |
| 77 | ++ LLT StoreTy = MRI.getType(Dst); |
| 78 | + auto Offset = |
| 79 | +- MIB.buildConstant(LLT::scalar(PtrTy.getSizeInBits()), CurrOffset); |
| 80 | +- StorePtr = MIB.buildPtrAdd(PtrTy, Dst, Offset).getReg(0); |
| 81 | ++ MIB.buildConstant(LLT::scalar(StoreTy.getSizeInBits()), CurrOffset); |
| 82 | ++ StorePtr = MIB.buildPtrAdd(StoreTy, Dst, Offset).getReg(0); |
| 83 | + } |
| 84 | + MIB.buildStore(LoadVals[I], StorePtr, *StoreMMO); |
| 85 | + CurrOffset += CopyTy.getSizeInBytes(); |
| 86 | +-- |
| 87 | +2.29.2 |
| 88 | + |
0 commit comments