@@ -2341,7 +2341,7 @@ void CodeGenRegBank::inferSubClassWithSubReg(CodeGenRegisterClass *RC) {
2341
2341
void CodeGenRegBank::inferMatchingSuperRegClass (
2342
2342
CodeGenRegisterClass *RC,
2343
2343
std::list<CodeGenRegisterClass>::iterator FirstSubRegRC) {
2344
- DenseMap< const CodeGenRegister *, std::vector< const CodeGenRegister *>>
2344
+ std::vector<std::pair< const CodeGenRegister *, const CodeGenRegister *>>
2345
2345
SubToSuperRegs;
2346
2346
BitVector TopoSigs (getNumTopoSigs ());
2347
2347
@@ -2353,15 +2353,17 @@ void CodeGenRegBank::inferMatchingSuperRegClass(
2353
2353
if (RC->getSubClassWithSubReg (&SubIdx) != RC)
2354
2354
continue ;
2355
2355
2356
- // Build list of (Super, Sub) pairs for this SubIdx.
2356
+ // Build list of (Sub, Super) pairs for this SubIdx, sorted by Sub. Note
2357
+ // that the list may contain entries with the same Sub but different Supers.
2357
2358
SubToSuperRegs.clear ();
2358
2359
TopoSigs.reset ();
2359
2360
for (const auto Super : RC->getMembers ()) {
2360
2361
const CodeGenRegister *Sub = Super->getSubRegs ().find (&SubIdx)->second ;
2361
2362
assert (Sub && " Missing sub-register" );
2362
- SubToSuperRegs[Sub]. push_back ( Super);
2363
+ SubToSuperRegs. emplace_back (Sub, Super);
2363
2364
TopoSigs.set (Sub->getTopoSig ());
2364
2365
}
2366
+ sort (SubToSuperRegs, on_first<deref<std::less<>>>());
2365
2367
2366
2368
// Iterate over sub-register class candidates. Ignore classes created by
2367
2369
// this loop. They will never be useful.
@@ -2376,14 +2378,17 @@ void CodeGenRegBank::inferMatchingSuperRegClass(
2376
2378
// Topological shortcut: SubRC members have the wrong shape.
2377
2379
if (!TopoSigs.anyCommon (SubRC.getTopoSigs ()))
2378
2380
continue ;
2379
- // Compute the subset of RC that maps into SubRC.
2381
+ // Compute the subset of RC that maps into SubRC with a single linear scan
2382
+ // through SubToSuperRegs and the members of SubRC.
2380
2383
CodeGenRegister::Vec SubSetVec;
2381
- for (const CodeGenRegister *R : SubRC.getMembers ()) {
2382
- auto It = SubToSuperRegs.find (R);
2383
- if (It != SubToSuperRegs.end ()) {
2384
- const std::vector<const CodeGenRegister *> &SuperRegs = It->second ;
2385
- SubSetVec.insert (SubSetVec.end (), SuperRegs.begin (), SuperRegs.end ());
2386
- }
2384
+ auto SubI = SubRC.getMembers ().begin (), SubE = SubRC.getMembers ().end ();
2385
+ for (auto &[Sub, Super] : SubToSuperRegs) {
2386
+ while (SubI != SubE && **SubI < *Sub)
2387
+ ++SubI;
2388
+ if (SubI == SubE)
2389
+ break ;
2390
+ if (**SubI == *Sub)
2391
+ SubSetVec.push_back (Super);
2387
2392
}
2388
2393
2389
2394
if (SubSetVec.empty ())
0 commit comments