@@ -672,12 +672,17 @@ void DACLoopSpawning::implementDACIterSpawnOnHelper(
672
672
IRBuilder<> Builder (&(RecurDet->front ()));
673
673
SetVector<Value*> RecurInputs;
674
674
Function::arg_iterator AI = Helper->arg_begin ();
675
+ // Handle an initial sret argument, if necessary. Based on how
676
+ // the Helper function is created, any sret parameter will be the
677
+ // first parameter.
678
+ if (Helper->hasParamAttribute (0 , Attribute::StructRet))
679
+ RecurInputs.insert (&*AI++);
675
680
assert (cast<Argument>(CanonicalIVInput) == &*AI &&
676
- " First argument does not match original input to canonical IV." );
681
+ " First non-sret argument does not match original input to canonical IV." );
677
682
RecurInputs.insert (CanonicalIVStart);
678
683
++AI;
679
684
assert (Limit == &*AI &&
680
- " Second argument does not match original input to the loop limit." );
685
+ " Second non-sret argument does not match original input to the loop limit." );
681
686
RecurInputs.insert (MidIter);
682
687
++AI;
683
688
for (Function::arg_iterator AE = Helper->arg_end (); AI != AE; ++AI)
@@ -1103,6 +1108,7 @@ bool DACLoopSpawning::processLoop() {
1103
1108
SetVector<Value *> BodyInputs, BodyOutputs;
1104
1109
ValueToValueMapTy VMap, InputMap;
1105
1110
std::vector<BasicBlock *> LoopBlocks;
1111
+ Value *SRetInput = nullptr ;
1106
1112
1107
1113
// Get the sync region containing this Tapir loop.
1108
1114
const Instruction *InputSyncRegion;
@@ -1134,6 +1140,23 @@ bool DACLoopSpawning::processLoop() {
1134
1140
findInputsOutputs (Blocks, BodyInputs, BodyOutputs, &HandledExits, DT);
1135
1141
}
1136
1142
1143
+ // Scan for any sret parameters in BodyInputs and add them first.
1144
+ if (F->hasStructRetAttr ()) {
1145
+ Function::arg_iterator ArgIter = F->arg_begin ();
1146
+ if (F->hasParamAttribute (0 , Attribute::StructRet))
1147
+ if (BodyInputs.count (&*ArgIter))
1148
+ SRetInput = &*ArgIter;
1149
+ if (F->hasParamAttribute (1 , Attribute::StructRet)) {
1150
+ ++ArgIter;
1151
+ if (BodyInputs.count (&*ArgIter))
1152
+ SRetInput = &*ArgIter;
1153
+ }
1154
+ }
1155
+ if (SRetInput) {
1156
+ DEBUG (dbgs () << " sret input " << *SRetInput << " \n " );
1157
+ Inputs.insert (SRetInput);
1158
+ }
1159
+
1137
1160
// Add argument for start of CanonicalIV.
1138
1161
DEBUG ({
1139
1162
Value *CanonicalIVInput =
@@ -1407,6 +1430,9 @@ bool DACLoopSpawning::processLoop() {
1407
1430
{
1408
1431
// Setup arguments for call.
1409
1432
SmallVector<Value *, 4 > TopCallArgs;
1433
+ // Add sret input, if it exists.
1434
+ if (SRetInput)
1435
+ TopCallArgs.push_back (SRetInput);
1410
1436
// Add start iteration 0.
1411
1437
assert (CanonicalSCEV->getStart ()->isZero () &&
1412
1438
" Canonical IV does not start at zero." );
0 commit comments