[llvm] [InstCombine] Add one-use limitation to box multiply fold (PR #72876)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 21 00:25:04 PST 2023


================
@@ -1405,6 +1405,14 @@ static Instruction *foldBoxMultiply(BinaryOperator &I) {
   // ResLo = (CrossSum << HalfBits) + (YLo * XLo)
   Value *XLo, *YLo;
   Value *CrossSum;
+  
+  // Checking the operands of I is used in no more than one place,
+  // which can not be deleted, cause a mul instruction has far more weight than
+  // add and shl instruction in IR, thus this method cannot achieve the goal of
+  // simplifying instructions, just return null.
+  if ((!I.getOperand(0)->hasOneUser() || !I.getOperand(1)->hasOneUser()))
+    return nullptr;
+
   if (!match(&I, m_c_Add(m_Shl(m_Value(CrossSum), m_SpecificInt(HalfBits)),
                          m_Mul(m_Value(YLo), m_Value(XLo)))))
----------------
JeffHDF wrote:

> I think applying the one-use constraint on mul inst is enough. See also https://reviews.llvm.org/D136015#3865898.

I think the purpose of box multiply fold optimization is to minimize the number of mul instruction. If the shl instruction does not guarantee one-use, the number of mul instruction will not decrease in the end. The meaning of the combine does not achieve the expected effect.

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


More information about the llvm-commits mailing list