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

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 21 04:58:16 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)))))
----------------
vfdff wrote:

here's an example https://gcc.godbolt.org/z/fz9GT3r7Y, we hope to combine the `high`(todo) and `low` part 

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


More information about the llvm-commits mailing list