[Mlir-commits] [llvm] [mlir] [ADT] Add implementations for mulhs and mulhu to APInt (PR #84609)

Jakub Kuderski llvmlistbot at llvm.org
Sat Mar 9 13:26:51 PST 2024


================
@@ -433,11 +433,8 @@ arith::MulSIExtendedOp::fold(FoldAdaptor adaptor,
           [](const APInt &a, const APInt &b) { return a * b; })) {
     // Invoke the constant fold helper again to calculate the 'high' result.
     Attribute highAttr = constFoldBinaryOp<IntegerAttr>(
-        adaptor.getOperands(), [](const APInt &a, const APInt &b) {
-          unsigned bitWidth = a.getBitWidth();
-          APInt fullProduct = a.sext(bitWidth * 2) * b.sext(bitWidth * 2);
-          return fullProduct.extractBits(bitWidth, bitWidth);
-        });
+        adaptor.getOperands(),
+        [](const APInt &a, const APInt &b) { return APIntOps::mulhs(a, b); });
----------------
kuhar wrote:

Can we use:
```suggestion
        &APIntOps::mulhs(a, b);
```
if this works?

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


More information about the Mlir-commits mailing list