[llvm] LICM: use PatternMatch, IRBuilder in hoist BO assoc (PR #106978)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 2 07:54:33 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))) ||
----------------
artagnon wrote:
For the PatternMatch change: we can just turn this into `m_c_BinOp` to handle the other cases, no?
https://github.com/llvm/llvm-project/pull/106978
More information about the llvm-commits
mailing list