[flang-commits] [flang] [mlir][arith] Fix canon pattern for large ints in chained arith (PR #68900)
Rik Huijzer via flang-commits
flang-commits at lists.llvm.org
Fri Oct 13 02:48:51 PDT 2023
================
@@ -39,26 +39,29 @@ 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(const APInt &, const APInt &)> binFn) {
+ APInt lhsVal = llvm::cast<IntegerAttr>(lhs).getValue();
+ APInt rhsVal = llvm::cast<IntegerAttr>(rhs).getValue();
+ APInt value = binFn(lhsVal, rhsVal);
+ return IntegerAttr::get(res.getType(), value);
}
static IntegerAttr addIntegerAttrs(PatternRewriter &builder, Value res,
Attribute lhs, Attribute rhs) {
- return applyToIntegerAttrs(builder, res, lhs, rhs, std::plus<int64_t>());
+ auto binFn = [](const APInt &a, const APInt &b) -> APInt { return a + b; };
+ return applyToIntegerAttrs(builder, res, lhs, rhs, binFn);
----------------
rikhuijzer wrote:
Well spotted 👍
https://github.com/llvm/llvm-project/pull/68900
More information about the flang-commits
mailing list