@@ -2341,7 +2341,7 @@ void CodeGenRegBank::inferSubClassWithSubReg(CodeGenRegisterClass *RC) {
23412341void CodeGenRegBank::inferMatchingSuperRegClass (
23422342 CodeGenRegisterClass *RC,
23432343 std::list<CodeGenRegisterClass>::iterator FirstSubRegRC) {
2344- DenseMap< const CodeGenRegister *, std::vector< const CodeGenRegister *>>
2344+ std::vector<std::pair< const CodeGenRegister *, const CodeGenRegister *>>
23452345 SubToSuperRegs;
23462346 BitVector TopoSigs (getNumTopoSigs ());
23472347
@@ -2353,15 +2353,17 @@ void CodeGenRegBank::inferMatchingSuperRegClass(
23532353 if (RC->getSubClassWithSubReg (&SubIdx) != RC)
23542354 continue ;
23552355
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.
23572358 SubToSuperRegs.clear ();
23582359 TopoSigs.reset ();
23592360 for (const auto Super : RC->getMembers ()) {
23602361 const CodeGenRegister *Sub = Super->getSubRegs ().find (&SubIdx)->second ;
23612362 assert (Sub && " Missing sub-register" );
2362- SubToSuperRegs[Sub]. push_back ( Super);
2363+ SubToSuperRegs. emplace_back (Sub, Super);
23632364 TopoSigs.set (Sub->getTopoSig ());
23642365 }
2366+ sort (SubToSuperRegs, on_first<deref<std::less<>>>());
23652367
23662368 // Iterate over sub-register class candidates. Ignore classes created by
23672369 // this loop. They will never be useful.
@@ -2376,14 +2378,17 @@ void CodeGenRegBank::inferMatchingSuperRegClass(
23762378 // Topological shortcut: SubRC members have the wrong shape.
23772379 if (!TopoSigs.anyCommon (SubRC.getTopoSigs ()))
23782380 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.
23802383 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);
23872392 }
23882393
23892394 if (SubSetVec.empty ())
0 commit comments