[all-commits] [llvm/llvm-project] de2bac: [MLIR] Allow `constFoldBinaryOp` to fold `(T1, T1)...

Matthias Guenther via All-commits all-commits at lists.llvm.org
Thu Aug 7 08:52:24 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: de2bac367ff9da74191bd2de130e4a81db07ae08
      https://github.com/llvm/llvm-project/commit/de2bac367ff9da74191bd2de130e4a81db07ae08
  Author: Matthias Guenther <mrguenther at google.com>
  Date:   2025-08-07 (Thu, 07 Aug 2025)

  Changed paths:
    M mlir/include/mlir/Dialect/CommonFolders.h
    A mlir/test/Dialect/common_folders.mlir
    M mlir/test/lib/Dialect/Test/TestOps.td
    M mlir/test/lib/Dialect/Test/TestPatterns.cpp

  Log Message:
  -----------
  [MLIR] Allow `constFoldBinaryOp` to fold `(T1, T1) -> T2` (#151410)

The `constFoldBinaryOp` helper function had limited support for
different input and output types, but the static type of the underlying
value (e.g. `APInt`) had to match between the inputs and the output.

This worked fine for int comparisons of the form `(intN, intN) -> int1`,
as the static type signature was `(APInt, APInt) -> APInt`. However,
float comparisons map `(floatN, floatN) -> int1`, with a static type
signature of `(APFloat, APFloat) -> APInt`. This use case wasn't
supported by `constFoldBinaryOp`.

`constFoldBinaryOp` now accepts an optional template argument overriding
the return type in case it differs from the input type. If the new
template argument isn't provided, the default behavior is unchanged
(i.e. the return type will be assumed to match the input type).

`constFoldUnaryOp` received similar changes in order to support folding
non-cast ops of the form `(T1) -> T2` (e.g. a `sign` op mapping
`(floatN) -> sint32`).



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list