[llvm] [LICM] Make an integer version of hoistFPAssociation. (PR #67736)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 12 09:43:55 PST 2024


================
@@ -2661,21 +2670,31 @@ static bool hoistAddSub(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo,
   return false;
 }
 
+static BinaryOperator *isReassociableOp(BinaryOperator *BO, unsigned Opcode1,
+                                        unsigned Opcode2) {
+  if (BO->getOpcode() == Opcode1 || BO->getOpcode() == Opcode2)
+    if (!isa<FPMathOperator>(BO) ||
+        (BO->hasAllowReassoc() && BO->hasNoSignedZeros()))
+      return BO;
+  return nullptr;
+}
+
 /// Try to reassociate expressions like ((A1 * B1) + (A2 * B2) + ...) * C where
 /// A1, A2, ... and C are loop invariants into expressions like
 /// ((A1 * C * B1) + (A2 * C * B2) + ...) and hoist the (A1 * C), (A2 * C), ...
 /// invariant expressions. This functions returns true only if any hoisting has
 /// actually occured.
-static bool hoistFPAssociation(Instruction &I, Loop &L,
-                               ICFLoopSafetyInfo &SafetyInfo,
-                               MemorySSAUpdater &MSSAU, AssumptionCache *AC,
-                               DominatorTree *DT) {
+static bool hoistMulAddAssociation(Instruction &I, Loop &L,
+                                   ICFLoopSafetyInfo &SafetyInfo,
+                                   MemorySSAUpdater &MSSAU, AssumptionCache *AC,
+                                   DominatorTree *DT) {
   using namespace PatternMatch;
-  Value *VariantOp = nullptr, *InvariantOp = nullptr;
 
-  if (!match(&I, m_FMul(m_Value(VariantOp), m_Value(InvariantOp))) ||
-      !I.hasAllowReassoc() || !I.hasNoSignedZeros())
+  if (auto *BO = dyn_cast<BinaryOperator>(&I);
+      !BO || !isReassociableOp(BO, Instruction::Mul, Instruction::FMul))
----------------
topperc wrote:

BinaryOperator::getOperand generates less code than Instruction::getOperand.

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


More information about the llvm-commits mailing list