25 Commits

Author SHA1 Message Date
jacquesguan
6c295a932d [mlir][Arith] Fold integer shift op with zero.
This revision folds arith.shrui, arith.shrsi and arith.shli with zero
rhs to lhs.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D140749
2022-12-30 17:19:23 +08:00
jacquesguan
e345d42025 [mlir][Arith] Remove redundant defination, NFC.
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D140774
2022-12-30 17:08:36 +08:00
liqinweng
f8f4fc11d1 [MLIR][Arith][NFC] Use the interface of 'getElementTypeOrSelf' to get the resType
Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D140608
2022-12-30 11:54:06 +08:00
Ben Shi
5c3c1098c6 Revert "[MLIR][Arith] Remove unused assertions"
This reverts commit 50e6c306b1cb03fe398aebc41d1bef5b6c9d9bb0.
2022-12-29 08:54:01 +08:00
liqinweng
50e6c306b1 [MLIR][Arith] Remove unused assertions
We shouldn't be checking things that are guaranteed by the op's verifier.

Reviewed By: benshi001

Differential Revision: https://reviews.llvm.org/D140610
2022-12-23 16:01:51 +08:00
liqinweng
00fd6958fb [MLIR][Arith] Canonicalize xor with ext
Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D139307
2022-12-23 12:40:30 +08:00
Ramkumar Ramachandra
22426110c5 mlir/tblgen: use std::optional in generation
This is part of an effort to migrate from llvm::Optional to
std::optional. This patch changes the way mlir-tblgen generates .inc
files, and modifies tests and documentation appropriately. It is a "no
compromises" patch, and doesn't leave the user with an unpleasant mix of
llvm::Optional and std::optional.

A non-trivial change has been made to ControlFlowInterfaces to split one
constructor into two, relating to a build failure on Windows.

See also: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716

Signed-off-by: Ramkumar Ramachandra <r@artagnon.com>

Differential Revision: https://reviews.llvm.org/D138934
2022-12-17 11:13:26 +01:00
Jakub Kuderski
dbf42f0b12 Reland "[mlir][arith] Add canonicalization patterns for 'mul*i_extended'"
- Add a fold for `mulsi_extended(x, 1)`
- Add folds to demote wide integer multiplication to `mul*i_extended` when the result is shifted
   and truncated: `trunci(shrui(mul(*ext(x), *ext(y)), c)) -> mul*i_extended(x, y)`

Reviewed By: Mogball, jpienaar

Differential Revision: https://reviews.llvm.org/D139778
2022-12-13 14:33:31 -05:00
Jakub Kuderski
2c33031e1b Revert "[mlir][arith] Add canonicalization patterns for 'mul*i_extended'"
This reverts commit 834c17f618ce87b14446e42250d924b8d5f01abe.

Revert to properly address post-commit comments by @jpienaar
under https://reviews.llvm.org/D139778.
2022-12-13 11:08:39 -05:00
Jakub Kuderski
834c17f618 [mlir][arith] Add canonicalization patterns for 'mul*i_extended'
- Add a fold for `mulsi_extended(x, 1)`
- Add folds to demote wide integer multiplication to `mul*i_extended` when the result is shifted
   and truncated: `trunci(shrui(mul(*ext(x), *ext(y)), c)) -> mul*i_extended(x, y)`

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D139778
2022-12-13 10:49:15 -05:00
Jakub Kuderski
285d321a85 [mlir][arith] Define mulsi_extended op
Extend D139688 with the signed version of the extended multiplication
op. Add conversion to the SPIR-V and LLVM dialects.

This was originally proposed in:
https://discourse.llvm.org/t/rfc-arith-add-extended-multiplication-ops/66869.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D139743
2022-12-09 20:25:31 -05:00
Jakub Kuderski
b4bdcea214 [mlir][arith] Define mului_extended op
Add conversion to the SPIR-V and LLVM dialects.

This was originally proposed in:
https://discourse.llvm.org/t/rfc-arith-add-extended-multiplication-ops/66869.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D139688
2022-12-09 17:37:06 -05:00
Jakub Kuderski
1dc9047bda [mlir][arith] Add canon pattern: addui_extended -> addi
Demote `arith.addui_extended` to `arith.addi` when the 'overflow'
result has no uses.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D139722
2022-12-09 14:40:05 -05:00
Jakub Kuderski
bafc3a2b22 [mlir][arith] Fix comment typo. NFC. 2022-12-07 17:21:41 -05:00
Jakub Kuderski
28246b7e75 [mlir][arith] Rename addui_carry to addui_extended
The goal is to make the naming of the future `_extended` ops more
consistent. With unsigned addition, the carry value/flag and overflow
bit are the same, but this is not true when it comes to signed addition.

Also rename the second result from `carry` to `overflow`.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D139569
2022-12-07 17:15:56 -05:00
Kazu Hirata
1a36588ec6 [mlir] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03 18:50:27 -08:00
Ivan Butygin
adf795dc7c [mlir][arith] Fold and(a, and(a, b)) to and(a, b)
Differential Revision: https://reviews.llvm.org/D137647
2022-11-16 22:57:41 +01:00
Sanjoy Das
ed39825be4 Model UB in integer division operations in the arith dialect
Before this commit `arith.{ceil}div{u|s}i` were marked `Pure` which is
incorrect because these operations invoke UB on certain inputs.

Fixes: https://github.com/llvm/llvm-project/issues/58700

Reviewed By: kuhar

Differential Revision: https://reviews.llvm.org/D137814
2022-11-11 10:42:31 -08:00
Mahesh Ravishankar
38f34e587d [mlir][Arith] Fix folder of CmpIOp to not fail when element type is not integer.
The folder used `cast<IntegerType>`  which would segfault if the type were
a vector type. Handle this case appropriately and avoid failure.

Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D137345
2022-11-03 20:38:34 +00:00
rkayaith
69112d0d2d [mlir][arith] Use declarative asm format for fastmath flags
Switch to using an optional group in the assembly format instead of a
custom directive. There's no change to the actual printed format.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D137087
2022-11-02 12:51:28 -04:00
Jeremy Furtek
b56e65d318 [mlir][arith] Initial support for fastmath flag attributes in the Arithmetic dialect (v2)
This diff adds initial (partial) support for "fastmath" attributes for floating
point operations in the arithmetic dialect. The "fastmath" attributes are
implemented using a default-valued bit enum. The defined flags currently mirror
the fastmath flags in the LLVM dialect (and in LLVM itself). Extending the
set of flags (if necessary) is left as a future task.

In this diff:
- Definition of FastMathAttr as a custom attribute in the Arithmetic dialect
  that inherits from the EnumAttr class.
- Definition of ArithFastMathInterface, which is an interface that is
  implemented by operations that have an arith::fastmath attribute.
- Declaration of a default-valued fastmath attribute for unary and (some) binary
  floating point operations in the Arithmetic dialect.
- Conversion code to lower arithmetic fastmath flags to LLVM fastmath flags

NOT in this diff (but planned or currently in progress):
- Documentation of flag meanings
- Addition of FastMathAttr attributes to other dialects that might lower to the
  Arithmetic dialect (e.g. Math and Complex)
- Folding/rewrite implementations that are enabled by fastmath flags
- Specification of fastmath values from Python bindings (pending other in-
  progress diffs)

Reviewed By: mehdi_amini, vzakhari

Differential Revision: https://reviews.llvm.org/D126305
2022-10-26 11:56:16 -07:00
River Riddle
cdfeeb8a40 [mlir:ODS] Generate unwrapped operation attribute setters
This allows for setting an attribute using the underlying C++ type,
which is generally much nicer to interact with than the attribute type.

Differential Revision: https://reviews.llvm.org/D135838
2022-10-14 15:57:51 -07:00
Thomas Raoux
b9a0eb6106 [mlir][arithmetic] Add tests for IndexCast folding ops and fix assert
Fix assert in IndexCastUI folding and add tests for both IndexCastOp and
IndexCastUIOp folding

Differential Revision: https://reviews.llvm.org/D135098
2022-10-03 20:28:09 +00:00
Thomas Raoux
f8fafe99a4 [mlir] Add unsigned version of index_cast
This is required to be able to cast integer type to a potential larger index using zero-extend cast.

There is a larger change under discussion to move index ops in a separate dialect: https://discourse.llvm.org/t/rfc-index-dialect/65540/
Based on timing of this work this patch can be included as part of this effort but as a short term solution we may want to add this op to arithmetic dialect for now in order to fill the gap.

Reviewed By: Mogball, stellaraccident

Differential Revision: https://reviews.llvm.org/D135089
2022-10-03 18:51:15 +00:00
Jakub Kuderski
abc362a107 [mlir][arith] Change dialect name from Arithmetic to Arith
Suggested by @lattner in https://discourse.llvm.org/t/rfc-define-precise-arith-semantics/65507/22.

Tested with:
`ninja check-mlir check-mlir-integration check-mlir-mlir-spirv-cpu-runner check-mlir-mlir-vulkan-runner check-mlir-examples`

and `bazel build --config=generic_clang @llvm-project//mlir:all`.

Reviewed By: lattner, Mogball, rriddle, jpienaar, mehdi_amini

Differential Revision: https://reviews.llvm.org/D134762
2022-09-29 11:23:28 -04:00