[llvm] LICM: use PatternMatch, IRBuilder in hoist BO assoc (PR #106978)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 03:00:52 PDT 2024


================
@@ -2816,40 +2816,43 @@ static bool hoistBOAssociation(Instruction &I, Loop &L,
                                ICFLoopSafetyInfo &SafetyInfo,
                                MemorySSAUpdater &MSSAU, AssumptionCache *AC,
                                DominatorTree *DT) {
-  auto *BO = dyn_cast<BinaryOperator>(&I);
-  if (!BO || !BO->isAssociative())
-    return false;
+  using namespace PatternMatch;
 
-  // Only fold ADDs for now.
+  // Transform "(LV op C1) op C2" ==> "LV op (C1 op C2)"
+  Value *LV, *C1, *C2;
+  if (!match(&I, m_BinOp(m_BinOp(m_Value(LV), m_Value(C1)), m_Value(C2))) ||
----------------
nikic wrote:

Still not convinced.

https://github.com/llvm/llvm-project/pull/106978


More information about the llvm-commits mailing list