[Mlir-commits] [mlir] [mlir][arith] Fix canon pattern for large ints in chained arith (PR #68900)

Markus Böck llvmlistbot at llvm.org
Thu Oct 12 11:53:34 PDT 2023


================
@@ -39,26 +39,35 @@ using namespace mlir::arith;
 static IntegerAttr
 applyToIntegerAttrs(PatternRewriter &builder, Value res, Attribute lhs,
                     Attribute rhs,
-                    function_ref<int64_t(int64_t, int64_t)> binFn) {
-  return builder.getIntegerAttr(res.getType(),
-                                binFn(llvm::cast<IntegerAttr>(lhs).getInt(),
-                                      llvm::cast<IntegerAttr>(rhs).getInt()));
+                    function_ref<APInt(APInt, APInt&)> binFn) {
----------------
zero9178 wrote:

```suggestion
                    function_ref<APInt(const APInt&, const APInt&)> binFn) {
```
`APInt` is a larger non-trivial type that is not cheap to copy and should therefore be passed by const ref

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


More information about the Mlir-commits mailing list