@@ -197,6 +197,7 @@ SPDX-License-Identifier: MIT
197
197
#include " llvm/Support/Debug.h"
198
198
199
199
#include < algorithm>
200
+ #include < map>
200
201
#include < vector>
201
202
202
203
using namespace llvm ;
@@ -317,6 +318,7 @@ namespace {
317
318
std::vector<Candidate> NormalCandidates;
318
319
std::vector<CallInst*> Callables;
319
320
std::vector<CopyData> ToCopy;
321
+ std::map<SimpleValue, Value*> CallToRetVal;
320
322
std::unordered_map<Instruction *, Value *> CopyCoalesced;
321
323
322
324
public:
@@ -508,6 +510,7 @@ bool GenXCoalescing::runOnFunctionGroup(FunctionGroup &FG)
508
510
CopyCandidates.clear ();
509
511
NormalCandidates.clear ();
510
512
Callables.clear ();
513
+ CallToRetVal.clear ();
511
514
ToCopy.clear ();
512
515
CopyCoalesced.clear ();
513
516
return true ;
@@ -1400,9 +1403,10 @@ void GenXCoalescing::processCalls(FunctionGroup *FG)
1400
1403
showCoalesceFail (SimpleValue (CI, StructIdx), CI->getDebugLoc (),
1401
1404
" ret postcopy" , DestLR, SourceLR);
1402
1405
unsigned Num = Numbering->getRetPostCopyNumber (CI, StructIdx);
1406
+ SimpleValue Source (CI, StructIdx);
1403
1407
Instruction *NewCopy =
1404
- insertCopy (SimpleValue (CI, StructIdx), DestLR, InsertBefore,
1405
- " retval.postcopy " , Num) ;
1408
+ insertCopy (Source, DestLR, InsertBefore, " retval.postcopy " , Num);
1409
+ CallToRetVal[Source] = NewCopy ;
1406
1410
IGC_ASSERT (NewCopy);
1407
1411
if (AllUsesAreExtract) {
1408
1412
// For a struct ret value where all the uses are non-struct
@@ -2039,6 +2043,9 @@ SortedCopies GenXCoalescing::getSortedCopyData() {
2039
2043
Instruction *GenXCoalescing::createCopy (const CopyData &CD) {
2040
2044
LiveRange *DestLR = Liveness->getLiveRange (CD.Dest );
2041
2045
LiveRange *SourceLR = Liveness->getLiveRange (CD.Source );
2046
+ SimpleValue Source = CD.Source ;
2047
+ if (auto It = CallToRetVal.find (Source); It != CallToRetVal.end ())
2048
+ Source = SimpleValue{It->second };
2042
2049
Instruction *NewCopy = nullptr ;
2043
2050
switch (CD.CopyT ) {
2044
2051
case PHICOPY:
@@ -2052,7 +2059,7 @@ Instruction *GenXCoalescing::createCopy(const CopyData &CD) {
2052
2059
: Numbering->getNumber (CD.InsertPoint );
2053
2060
showCoalesceFail (CD.Dest , CD.InsertPoint ->getDebugLoc (), " phi" , DestLR,
2054
2061
SourceLR);
2055
- NewCopy = insertCopy (CD. Source , DestLR, CD.InsertPoint , " phicopy" , Num);
2062
+ NewCopy = insertCopy (Source, DestLR, CD.InsertPoint , " phicopy" , Num);
2056
2063
Phi->setIncomingValue (CD.UseInDest ->getOperandNo (), NewCopy);
2057
2064
break ;
2058
2065
}
@@ -2063,7 +2070,7 @@ Instruction *GenXCoalescing::createCopy(const CopyData &CD) {
2063
2070
Instruction *DestInst = cast<Instruction>(CD.Dest .getValue ());
2064
2071
showCoalesceFail (CD.Dest , DestInst->getDebugLoc (), " two address" , DestLR,
2065
2072
SourceLR);
2066
- NewCopy = insertCopy (CD. Source , DestLR, DestInst, " twoaddr" ,
2073
+ NewCopy = insertCopy (Source, DestLR, DestInst, " twoaddr" ,
2067
2074
Numbering->getNumber (DestInst) - 1 );
2068
2075
NewCopy =
2069
2076
insertIntoStruct (CD.Dest .getValue ()->getType (), CD.Dest .getIndex (),
0 commit comments