[llvm] [AggressiveInstCombine] Match long high-half multiply (PR #168396)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 19 06:24:28 PST 2025
================
@@ -1466,6 +1466,307 @@ static bool foldLibCalls(Instruction &I, TargetTransformInfo &TTI,
return false;
}
+/// Match high part of long multiplication.
+///
+/// Considering a multiply made up of high and low parts, we can split the
+/// multiply into:
+/// x * y == (xh*T + xl) * (yh*T + yl)
+/// where xh == x>>32 and xl == x & 0xffffffff. T = 2^32.
+/// This expands to
+/// xh*yh*T*T + xh*yl*T + xl*yh*T + xl*yl
+/// which can be drawn as
+/// [ xh*yh ]
+/// [ xh*yl ]
+/// [ xl*yh ]
+/// [ xl*yl ]
+/// We are looking for the "high" half, which is xh*yh + xh*yl>>32 + xl*yh>>32 +
+/// some carrys. The carry makes this difficult and there are multiple ways of
+/// representing it. The ones we attempt to support here are:
+/// Carry: xh*yh + carry + lowsum
+/// carry = lowsum < xh*yl ? 0x1000000 : 0
+/// lowsum = xh*yl + xl*yh + (xl*yl>>32)
+/// Ladder: xh*yh + c2>>32 + c3>>32
+/// c2 = xh*yl + (xl*yl>>32); c3 = c2&0xffffffff + xl*yh
----------------
dtcxzyw wrote:
Here is another variant that is a bit different from this pattern: https://github.com/Cyan4973/xxHash/blob/136cc1f8fe4d5ea62a7c16c8424d4fa5158f6d68/xxhash.h#L4568-L4582
https://github.com/llvm/llvm-project/pull/168396
More information about the llvm-commits
mailing list