[Mlir-commits] [mlir] aa2adc1 - [mlir][index] Fix side effect modeling for division by zero ops
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Sep 5 14:45:41 PDT 2023
Author: Mogball
Date: 2023-09-05T21:45:28Z
New Revision: aa2adc1283ec1cd7d54ba3affb43a1f4d16202be
URL: https://github.com/llvm/llvm-project/commit/aa2adc1283ec1cd7d54ba3affb43a1f4d16202be
DIFF: https://github.com/llvm/llvm-project/commit/aa2adc1283ec1cd7d54ba3affb43a1f4d16202be.diff
LOG: [mlir][index] Fix side effect modeling for division by zero ops
Operations that can divide by zero and can have immediate undefined
behaviour should be marked as `NoMemoryEffect` rather than `Pure`.
Depends on D159456
Reviewed By: weiweichen
Differential Revision: https://reviews.llvm.org/D159457
Added:
Modified:
mlir/include/mlir/Dialect/Index/IR/IndexOps.td
Removed:
################################################################################
diff --git a/mlir/include/mlir/Dialect/Index/IR/IndexOps.td b/mlir/include/mlir/Dialect/Index/IR/IndexOps.td
index e45bedc8206f80..61cdf4ed0877a0 100644
--- a/mlir/include/mlir/Dialect/Index/IR/IndexOps.td
+++ b/mlir/include/mlir/Dialect/Index/IR/IndexOps.td
@@ -25,7 +25,7 @@ include "mlir/IR/OpBase.td"
/// Base class for Index dialect operations.
class IndexOp<string mnemonic, list<Trait> traits = []>
: Op<IndexDialect, mnemonic,
- [Pure, DeclareOpInterfaceMethods<InferIntRangeInterface>] # traits>;
+ [DeclareOpInterfaceMethods<InferIntRangeInterface>] # traits>;
//===----------------------------------------------------------------------===//
// IndexBinaryOp
@@ -44,7 +44,7 @@ class IndexBinaryOp<string mnemonic, list<Trait> traits = []>
// AddOp
//===----------------------------------------------------------------------===//
-def Index_AddOp : IndexBinaryOp<"add", [Commutative]> {
+def Index_AddOp : IndexBinaryOp<"add", [Commutative, Pure]> {
let summary = "index addition";
let description = [{
The `index.add` operation takes two index values and computes their sum.
@@ -62,7 +62,7 @@ def Index_AddOp : IndexBinaryOp<"add", [Commutative]> {
// SubOp
//===----------------------------------------------------------------------===//
-def Index_SubOp : IndexBinaryOp<"sub"> {
+def Index_SubOp : IndexBinaryOp<"sub", [Pure]> {
let summary = "index subtraction";
let description = [{
The `index.sub` operation takes two index values and computes the
diff erence
@@ -81,7 +81,7 @@ def Index_SubOp : IndexBinaryOp<"sub"> {
// MulOp
//===----------------------------------------------------------------------===//
-def Index_MulOp : IndexBinaryOp<"mul", [Commutative]> {
+def Index_MulOp : IndexBinaryOp<"mul", [Commutative, Pure]> {
let summary = "index multiplication";
let description = [{
The `index.mul` operation takes two index values and computes their product.
@@ -99,7 +99,7 @@ def Index_MulOp : IndexBinaryOp<"mul", [Commutative]> {
// DivSOp
//===----------------------------------------------------------------------===//
-def Index_DivSOp : IndexBinaryOp<"divs"> {
+def Index_DivSOp : IndexBinaryOp<"divs", [NoMemoryEffect]> {
let summary = "index signed division";
let description = [{
The `index.divs` operation takes two index values and computes their signed
@@ -121,7 +121,7 @@ def Index_DivSOp : IndexBinaryOp<"divs"> {
// DivUOp
//===----------------------------------------------------------------------===//
-def Index_DivUOp : IndexBinaryOp<"divu"> {
+def Index_DivUOp : IndexBinaryOp<"divu", [NoMemoryEffect]> {
let summary = "index unsigned division";
let description = [{
The `index.divu` operation takes two index values and computes their
@@ -143,7 +143,7 @@ def Index_DivUOp : IndexBinaryOp<"divu"> {
// CeilDivSOp
//===----------------------------------------------------------------------===//
-def Index_CeilDivSOp : IndexBinaryOp<"ceildivs"> {
+def Index_CeilDivSOp : IndexBinaryOp<"ceildivs", [NoMemoryEffect]> {
let summary = "index signed ceil division";
let description = [{
The `index.ceildivs` operation takes two index values and computes their
@@ -165,7 +165,7 @@ def Index_CeilDivSOp : IndexBinaryOp<"ceildivs"> {
// CeilDivUOp
//===----------------------------------------------------------------------===//
-def Index_CeilDivUOp : IndexBinaryOp<"ceildivu"> {
+def Index_CeilDivUOp : IndexBinaryOp<"ceildivu", [NoMemoryEffect]> {
let summary = "index unsigned ceil division";
let description = [{
The `index.ceildivu` operation takes two index values and computes their
@@ -187,7 +187,7 @@ def Index_CeilDivUOp : IndexBinaryOp<"ceildivu"> {
// FloorDivSOp
//===----------------------------------------------------------------------===//
-def Index_FloorDivSOp : IndexBinaryOp<"floordivs"> {
+def Index_FloorDivSOp : IndexBinaryOp<"floordivs", [NoMemoryEffect]> {
let summary = "index signed floor division";
let description = [{
The `index.floordivs` operation takes two index values and computes their
@@ -209,7 +209,7 @@ def Index_FloorDivSOp : IndexBinaryOp<"floordivs"> {
// RemSOp
//===----------------------------------------------------------------------===//
-def Index_RemSOp : IndexBinaryOp<"rems"> {
+def Index_RemSOp : IndexBinaryOp<"rems", [NoMemoryEffect]> {
let summary = "index signed remainder";
let description = [{
The `index.rems` operation takes two index values and computes their signed
@@ -228,7 +228,7 @@ def Index_RemSOp : IndexBinaryOp<"rems"> {
// RemUOp
//===----------------------------------------------------------------------===//
-def Index_RemUOp : IndexBinaryOp<"remu"> {
+def Index_RemUOp : IndexBinaryOp<"remu", [NoMemoryEffect]> {
let summary = "index unsigned remainder";
let description = [{
The `index.remu` operation takes two index values and computes their
@@ -248,7 +248,7 @@ def Index_RemUOp : IndexBinaryOp<"remu"> {
// MaxSOp
//===----------------------------------------------------------------------===//
-def Index_MaxSOp : IndexBinaryOp<"maxs", [Commutative]> {
+def Index_MaxSOp : IndexBinaryOp<"maxs", [Commutative, Pure]> {
let summary = "index signed maximum";
let description = [{
The `index.maxs` operation takes two index values and computes their signed
@@ -267,7 +267,7 @@ def Index_MaxSOp : IndexBinaryOp<"maxs", [Commutative]> {
// MaxUOp
//===----------------------------------------------------------------------===//
-def Index_MaxUOp : IndexBinaryOp<"maxu", [Commutative]> {
+def Index_MaxUOp : IndexBinaryOp<"maxu", [Commutative, Pure]> {
let summary = "index unsigned maximum";
let description = [{
The `index.maxu` operation takes two index values and computes their
@@ -287,7 +287,7 @@ def Index_MaxUOp : IndexBinaryOp<"maxu", [Commutative]> {
// MinSOp
//===----------------------------------------------------------------------===//
-def Index_MinSOp : IndexBinaryOp<"mins", [Commutative]> {
+def Index_MinSOp : IndexBinaryOp<"mins", [Commutative, Pure]> {
let summary = "index signed minimum";
let description = [{
The `index.mins` operation takes two index values and computes their signed
@@ -306,7 +306,7 @@ def Index_MinSOp : IndexBinaryOp<"mins", [Commutative]> {
// MinUOp
//===----------------------------------------------------------------------===//
-def Index_MinUOp : IndexBinaryOp<"minu", [Commutative]> {
+def Index_MinUOp : IndexBinaryOp<"minu", [Commutative, Pure]> {
let summary = "index unsigned minimum";
let description = [{
The `index.minu` operation takes two index values and computes their
@@ -326,13 +326,13 @@ def Index_MinUOp : IndexBinaryOp<"minu", [Commutative]> {
// ShlOp
//===----------------------------------------------------------------------===//
-def Index_ShlOp : IndexBinaryOp<"shl"> {
+def Index_ShlOp : IndexBinaryOp<"shl", [Pure]> {
let summary = "index shift left";
let description = [{
The `index.shl` operation shifts an index value to the left by a variable
amount. The low order bits are filled with zeroes. The RHS operand is always
treated as unsigned. If the RHS operand is equal to or greater than the
- index bitwidth, the operation is undefined.
+ index bitwidth, the result is a poison value.
Example:
@@ -347,13 +347,13 @@ def Index_ShlOp : IndexBinaryOp<"shl"> {
// ShrSOp
//===----------------------------------------------------------------------===//
-def Index_ShrSOp : IndexBinaryOp<"shrs"> {
+def Index_ShrSOp : IndexBinaryOp<"shrs", [Pure]> {
let summary = "signed index shift right";
let description = [{
The `index.shrs` operation shifts an index value to the right by a variable
amount. The LHS operand is treated as signed. The high order bits are filled
with copies of the most significant bit. If the RHS operand is equal to or
- greater than the index bitwidth, the operation is undefined.
+ greater than the index bitwidth, the result is a poison value.
Example:
@@ -368,13 +368,13 @@ def Index_ShrSOp : IndexBinaryOp<"shrs"> {
// ShrUOp
//===----------------------------------------------------------------------===//
-def Index_ShrUOp : IndexBinaryOp<"shru"> {
+def Index_ShrUOp : IndexBinaryOp<"shru", [Pure]> {
let summary = "unsigned index shift right";
let description = [{
The `index.shru` operation shifts an index value to the right by a variable
amount. The LHS operand is treated as unsigned. The high order bits are
filled with zeroes. If the RHS operand is equal to or greater than the index
- bitwidth, the operation is undefined.
+ bitwidth, the result is a poison value.
Example:
@@ -389,7 +389,7 @@ def Index_ShrUOp : IndexBinaryOp<"shru"> {
// AndOp
//===----------------------------------------------------------------------===//
-def Index_AndOp : IndexBinaryOp<"and", [Commutative]> {
+def Index_AndOp : IndexBinaryOp<"and", [Commutative, Pure]> {
let summary = "index bitwise and";
let description = [{
The `index.and` operation takes two index values and computes their bitwise
@@ -408,7 +408,7 @@ def Index_AndOp : IndexBinaryOp<"and", [Commutative]> {
// OrOp
//===----------------------------------------------------------------------===//
-def Index_OrOp : IndexBinaryOp<"or", [Commutative]> {
+def Index_OrOp : IndexBinaryOp<"or", [Commutative, Pure]> {
let summary = "index bitwise or";
let description = [{
The `index.or` operation takes two index values and computes their bitwise
@@ -427,7 +427,7 @@ def Index_OrOp : IndexBinaryOp<"or", [Commutative]> {
// XorOp
//===----------------------------------------------------------------------===//
-def Index_XOrOp : IndexBinaryOp<"xor", [Commutative]> {
+def Index_XOrOp : IndexBinaryOp<"xor", [Commutative, Pure]> {
let summary = "index bitwise xor";
let description = [{
The `index.xor` operation takes two index values and computes their bitwise
@@ -446,8 +446,8 @@ def Index_XOrOp : IndexBinaryOp<"xor", [Commutative]> {
// CastSOp
//===----------------------------------------------------------------------===//
-def Index_CastSOp : IndexOp<"casts",
- [DeclareOpInterfaceMethods<CastOpInterface>]> {
+def Index_CastSOp : IndexOp<"casts", [Pure,
+ DeclareOpInterfaceMethods<CastOpInterface>]> {
let summary = "index signed cast";
let description = [{
The `index.casts` operation enables conversions between values of index type
@@ -475,8 +475,8 @@ def Index_CastSOp : IndexOp<"casts",
// CastUOp
//===----------------------------------------------------------------------===//
-def Index_CastUOp : IndexOp<"castu",
- [DeclareOpInterfaceMethods<CastOpInterface>]> {
+def Index_CastUOp : IndexOp<"castu", [Pure,
+ DeclareOpInterfaceMethods<CastOpInterface>]> {
let summary = "index unsigned cast";
let description = [{
The `index.castu` operation enables conversions between values of index type
@@ -504,7 +504,7 @@ def Index_CastUOp : IndexOp<"castu",
// CmpOp
//===----------------------------------------------------------------------===//
-def Index_CmpOp : IndexOp<"cmp"> {
+def Index_CmpOp : IndexOp<"cmp", [Pure]> {
let summary = "index compare";
let description = [{
The `index.cmp` operation takes two index values and compares them according
@@ -549,7 +549,7 @@ def Index_CmpOp : IndexOp<"cmp"> {
// SizeOfOp
//===----------------------------------------------------------------------===//
-def Index_SizeOfOp : IndexOp<"sizeof"> {
+def Index_SizeOfOp : IndexOp<"sizeof", [Pure]> {
let summary = "size in bits of the index type";
let description = [{
The `index.sizeof` operation produces an index-typed SSA value equal to the
@@ -572,7 +572,7 @@ def Index_SizeOfOp : IndexOp<"sizeof"> {
//===----------------------------------------------------------------------===//
def Index_ConstantOp : IndexOp<"constant", [
- ConstantLike,
+ ConstantLike, Pure,
DeclareOpInterfaceMethods<OpAsmOpInterface, ["getAsmResultNames"]>
]> {
let summary = "index constant";
@@ -600,7 +600,7 @@ def Index_ConstantOp : IndexOp<"constant", [
//===----------------------------------------------------------------------===//
def Index_BoolConstantOp : IndexOp<"bool.constant", [
- ConstantLike,
+ ConstantLike, Pure,
DeclareOpInterfaceMethods<OpAsmOpInterface, ["getAsmResultNames"]>
]> {
let summary = "boolean constant";
More information about the Mlir-commits
mailing list