@@ -324,11 +324,6 @@ class Vectorizer {
324324      Instruction *ChainElem, Instruction *ChainBegin,
325325      const  DenseMap<Instruction *, APInt /* OffsetFromLeader*/ 
326326
327-   // / Merges the equivalence classes if they have underlying objects that differ
328-   // / by one level of indirection (i.e., one is a getelementptr and the other is
329-   // / the base pointer in that getelementptr).
330-   void  mergeEquivalenceClasses (EquivalenceClassMap &EQClasses) const ;
331- 
332327  // / Collects loads and stores grouped by "equivalence class", where:
333328  // /   - all elements in an eq class are a load or all are a store,
334329  // /   - they all load/store the same element size (it's OK to have e.g. i8 and
@@ -1310,123 +1305,6 @@ std::optional<APInt> Vectorizer::getConstantOffsetSelects(
13101305  return  std::nullopt ;
13111306}
13121307
1313- void  Vectorizer::mergeEquivalenceClasses (EquivalenceClassMap &EQClasses) const  {
1314-   if  (EQClasses.size () < 2 ) //  There is nothing to merge.
1315-     return ;
1316- 
1317-   //  The reduced key has all elements of the ECClassKey except the underlying
1318-   //  object. Check that EqClassKey has 4 elements and define the reduced key.
1319-   static_assert (std::tuple_size_v<EqClassKey> == 4 ,
1320-                 " EqClassKey has changed - EqClassReducedKey needs changes too" 
1321-   using  EqClassReducedKey =
1322-       std::tuple<std::tuple_element_t <1 , EqClassKey> /*  AddrSpace */ 
1323-                  std::tuple_element_t <2 , EqClassKey> /*  Element size */ 
1324-                  std::tuple_element_t <3 , EqClassKey> /*  IsLoad; */ 
1325-   using  ECReducedKeyToUnderlyingObjectMap =
1326-       MapVector<EqClassReducedKey,
1327-                 SmallPtrSet<std::tuple_element_t <0 , EqClassKey>, 4 >>;
1328- 
1329-   //  Form a map from the reduced key (without the underlying object) to the
1330-   //  underlying objects: 1 reduced key to many underlying objects, to form
1331-   //  groups of potentially merge-able equivalence classes.
1332-   ECReducedKeyToUnderlyingObjectMap RedKeyToUOMap;
1333-   bool  FoundPotentiallyOptimizableEC = false ;
1334-   for  (const  auto  &EC : EQClasses) {
1335-     const  auto  &Key = EC.first ;
1336-     EqClassReducedKey RedKey{std::get<1 >(Key), std::get<2 >(Key),
1337-                              std::get<3 >(Key)};
1338-     RedKeyToUOMap[RedKey].insert (std::get<0 >(Key));
1339-     if  (RedKeyToUOMap[RedKey].size () > 1 )
1340-       FoundPotentiallyOptimizableEC = true ;
1341-   }
1342-   if  (!FoundPotentiallyOptimizableEC)
1343-     return ;
1344- 
1345-   LLVM_DEBUG ({
1346-     dbgs () << " LSV: mergeEquivalenceClasses: before merging:\n " 
1347-     for  (const  auto  &EC : EQClasses) {
1348-       dbgs () << "     Key: ([" 0 >(EC.first )
1349-              << " ]: " 0 >(EC.first ) << " , " 1 >(EC.first )
1350-              << " , " 2 >(EC.first ) << " , " 
1351-              << static_cast <int >(std::get<3 >(EC.first )) << " )\n " 
1352-       for  (const  auto  &Inst : EC.second )
1353-         dbgs () << " \t Inst: " ' \n ' 
1354-     }
1355-   });
1356-   LLVM_DEBUG ({
1357-     dbgs () << " LSV: mergeEquivalenceClasses: RedKeyToUOMap:\n " 
1358-     for  (const  auto  &RedKeyToUO : RedKeyToUOMap) {
1359-       dbgs () << "     Reduced key: (" 0 >(RedKeyToUO.first ) << " , " 
1360-              << std::get<1 >(RedKeyToUO.first ) << " , " 
1361-              << static_cast <int >(std::get<2 >(RedKeyToUO.first )) << " ) --> " 
1362-              << RedKeyToUO.second .size () << "  underlying objects:\n " 
1363-       for  (auto  UObject : RedKeyToUO.second )
1364-         dbgs () << "     [" " ]: " ' \n ' 
1365-     }
1366-   });
1367- 
1368-   using  UObjectToUObjectMap = DenseMap<const  Value *, const  Value *>;
1369- 
1370-   //  Compute the ultimate targets for a set of underlying objects.
1371-   auto  GetUltimateTargets =
1372-       [](SmallPtrSetImpl<const  Value *> &UObjects) -> UObjectToUObjectMap {
1373-     UObjectToUObjectMap IndirectionMap;
1374-     for  (const  auto  *UObject : UObjects) {
1375-       const  unsigned  MaxLookupDepth = 1 ; //  look for 1-level indirections only
1376-       const  auto  *UltimateTarget = getUnderlyingObject (UObject, MaxLookupDepth);
1377-       if  (UltimateTarget != UObject)
1378-         IndirectionMap[UObject] = UltimateTarget;
1379-     }
1380-     UObjectToUObjectMap UltimateTargetsMap;
1381-     for  (const  auto  *UObject : UObjects) {
1382-       auto  Target = UObject;
1383-       auto  It = IndirectionMap.find (Target);
1384-       for  (; It != IndirectionMap.end (); It = IndirectionMap.find (Target))
1385-         Target = It->second ;
1386-       UltimateTargetsMap[UObject] = Target;
1387-     }
1388-     return  UltimateTargetsMap;
1389-   };
1390- 
1391-   //  For each item in RedKeyToUOMap, if it has more than one underlying object,
1392-   //  try to merge the equivalence classes.
1393-   for  (auto  &[RedKey, UObjects] : RedKeyToUOMap) {
1394-     if  (UObjects.size () < 2 )
1395-       continue ;
1396-     auto  UTMap = GetUltimateTargets (UObjects);
1397-     for  (const  auto  &[UObject, UltimateTarget] : UTMap) {
1398-       if  (UObject == UltimateTarget)
1399-         continue ;
1400- 
1401-       EqClassKey KeyFrom{UObject, std::get<0 >(RedKey), std::get<1 >(RedKey),
1402-                          std::get<2 >(RedKey)};
1403-       EqClassKey KeyTo{UltimateTarget, std::get<0 >(RedKey), std::get<1 >(RedKey),
1404-                        std::get<2 >(RedKey)};
1405-       const  auto  &VecFrom = EQClasses[KeyFrom];
1406-       const  auto  &VecTo = EQClasses[KeyTo];
1407-       SmallVector<Instruction *, 8 > MergedVec;
1408-       std::merge (VecFrom.begin (), VecFrom.end (), VecTo.begin (), VecTo.end (),
1409-                  std::back_inserter (MergedVec),
1410-                  [](Instruction *A, Instruction *B) {
1411-                    return  A && B && A->comesBefore (B);
1412-                  });
1413-       EQClasses[KeyTo] = std::move (MergedVec);
1414-       EQClasses.erase (KeyFrom);
1415-     }
1416-   }
1417-   LLVM_DEBUG ({
1418-     dbgs () << " LSV: mergeEquivalenceClasses: after merging:\n " 
1419-     for  (const  auto  &EC : EQClasses) {
1420-       dbgs () << "     Key: ([" 0 >(EC.first )
1421-              << " ]: " 0 >(EC.first ) << " , " 1 >(EC.first )
1422-              << " , " 2 >(EC.first ) << " , " 
1423-              << static_cast <int >(std::get<3 >(EC.first )) << " )\n " 
1424-       for  (const  auto  &Inst : EC.second )
1425-         dbgs () << " \t Inst: " ' \n ' 
1426-     }
1427-   });
1428- }
1429- 
14301308EquivalenceClassMap
14311309Vectorizer::collectEquivalenceClasses (BasicBlock::iterator Begin,
14321310                                      BasicBlock::iterator End) {
@@ -1499,7 +1377,6 @@ Vectorizer::collectEquivalenceClasses(BasicBlock::iterator Begin,
14991377        .emplace_back (&I);
15001378  }
15011379
1502-   mergeEquivalenceClasses (Ret);
15031380  return  Ret;
15041381}
15051382
0 commit comments