[Mlir-commits] [mlir] [mlir][LLVM] Add exact flag (PR #115327)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Nov 7 06:53:05 PST 2024
=?utf-8?q?Léon?= Frenot <leon.frenot at ens-lyon.fr>,
=?utf-8?q?Léon?= Frenot <leon.frenot at ens-lyon.fr>,
=?utf-8?q?Léon?= Frenot <leon.frenot at ens-lyon.fr>,
=?utf-8?q?Léon?= Frenot <leon.frenot at ens-lyon.fr>,
=?utf-8?q?Léon?= Frenot <leon.frenot at ens-lyon.fr>,
=?utf-8?q?Léon?= Frenot <leon.frenot at ens-lyon.fr>,
=?utf-8?q?Léon?= Frenot <leon.frenot at ens-lyon.fr>,
=?utf-8?q?Léon?= Frenot <leon.frenot at ens-lyon.fr>,
=?utf-8?q?Léon?= Frenot <leon.frenot at ens-lyon.fr>,Leon Frenot
<leon.frenot at ens-lyon.fr>,
=?utf-8?q?Léon?= Frenot <leon.frenot at ens-lyon.fr>,
=?utf-8?q?Léon?= Frenot <leon.frenot at ens-lyon.fr>
Message-ID: <llvm.org/llvm/llvm-project/pull/115327 at github.com>
In-Reply-To:
https://github.com/lfrenot created https://github.com/llvm/llvm-project/pull/115327
The implementation is mostly based on the one existing for the nsw and nuw flags.
If the exact flag is present, the corresponding operation returns a poison value when the result is not exact. (For a division, if rounding happens; for a right shift, if a non-zero bit is shifted out.)
@zero9178, @gysit and @Dinistro, could you take a look?
>From aef52f564fc60d4936f6c56d94b0440547a37e24 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9on=20Frenot?= <leon.frenot at ens-lyon.fr>
Date: Wed, 6 Nov 2024 14:35:46 +0000
Subject: [PATCH 01/13] Added LLVM_IntArithmeticOpWithIsExact and unit tests
---
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 27 ++++++++++++++++++---
mlir/test/Dialect/LLVMIR/roundtrip.mlir | 10 ++++++++
2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index d5def510a904d3..574cdc0f29f1b7 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -76,6 +76,25 @@ class LLVM_IntArithmeticOpWithOverflowFlag<string mnemonic, string instName,
"$res = builder.Create" # instName #
"($lhs, $rhs, /*Name=*/\"\", op.hasNoUnsignedWrap(), op.hasNoSignedWrap());";
}
+class LLVM_IntArithmeticOpWithIsExact<string mnemonic, string instName,
+ list<Trait> traits = []> :
+ LLVM_ArithmeticOpBase<AnySignlessInteger, mnemonic, instName, traits> {
+ let arguments = !con(commonArgs, (ins UnitAttr:$isExact));
+
+ string mlirBuilder = [{
+ auto op = $_builder.create<$_qualCppClassName>($_location, $lhs, $rhs);
+ if ($isExact) {
+ op.setIsExact();
+ }
+ $res = op;
+ }];
+ let assemblyFormat = [{
+ (`exact` $isExact^)? $lhs `,` $rhs custom<LLVMOpAttrs>(attr-dict) `:` type($res)
+ }];
+ string llvmBuilder =
+ "$res = builder.Create" # instName #
+ "($lhs, $rhs, /*Name=*/\"\", op.hasIsExact());";
+}
class LLVM_FloatArithmeticOp<string mnemonic, string instName,
list<Trait> traits = []> :
LLVM_ArithmeticOpBase<LLVM_AnyFloat, mnemonic, instName,
@@ -116,8 +135,8 @@ def LLVM_AddOp : LLVM_IntArithmeticOpWithOverflowFlag<"add", "Add",
def LLVM_SubOp : LLVM_IntArithmeticOpWithOverflowFlag<"sub", "Sub", []>;
def LLVM_MulOp : LLVM_IntArithmeticOpWithOverflowFlag<"mul", "Mul",
[Commutative]>;
-def LLVM_UDivOp : LLVM_IntArithmeticOp<"udiv", "UDiv">;
-def LLVM_SDivOp : LLVM_IntArithmeticOp<"sdiv", "SDiv">;
+def LLVM_UDivOp : LLVM_IntArithmeticOpWithIsExact<"udiv", "UDiv">;
+def LLVM_SDivOp : LLVM_IntArithmeticOpWithIsExact<"sdiv", "SDiv">;
def LLVM_URemOp : LLVM_IntArithmeticOp<"urem", "URem">;
def LLVM_SRemOp : LLVM_IntArithmeticOp<"srem", "SRem">;
def LLVM_AndOp : LLVM_IntArithmeticOp<"and", "And">;
@@ -128,8 +147,8 @@ def LLVM_XOrOp : LLVM_IntArithmeticOp<"xor", "Xor">;
def LLVM_ShlOp : LLVM_IntArithmeticOpWithOverflowFlag<"shl", "Shl", []> {
let hasFolder = 1;
}
-def LLVM_LShrOp : LLVM_IntArithmeticOp<"lshr", "LShr">;
-def LLVM_AShrOp : LLVM_IntArithmeticOp<"ashr", "AShr">;
+def LLVM_LShrOp : LLVM_IntArithmeticOpWithIsExact<"lshr", "LShr">;
+def LLVM_AShrOp : LLVM_IntArithmeticOpWithIsExact<"ashr", "AShr">;
// Base class for compare operations. A compare operation takes two operands
// of the same type and returns a boolean result. If the operands are
diff --git a/mlir/test/Dialect/LLVMIR/roundtrip.mlir b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
index b8ce7db795a1d1..9daad2ef5b0b1b 100644
--- a/mlir/test/Dialect/LLVMIR/roundtrip.mlir
+++ b/mlir/test/Dialect/LLVMIR/roundtrip.mlir
@@ -49,6 +49,16 @@ func.func @ops(%arg0: i32, %arg1: f32,
%mul_flag = llvm.mul %arg0, %arg0 overflow<nsw, nuw> : i32
%shl_flag = llvm.shl %arg0, %arg0 overflow<nuw, nsw> : i32
+// Integer exact
+// CHECK: {{.*}} = llvm.sdiv exact %[[I32]], %[[I32]] : i32
+// CHECK: {{.*}} = llvm.udiv exact %[[I32]], %[[I32]] : i32
+// CHECK: {{.*}} = llvm.ashr exact %[[I32]], %[[I32]] : i32
+// CHECK: {{.*}} = llvm.lshr exact %[[I32]], %[[I32]] : i32
+ %sdiv_flag = llvm.sdiv exact %arg0, %arg0 : i32
+ %udiv_flag = llvm.udiv exact %arg0, %arg0 : i32
+ %ashr_flag = llvm.ashr exact %arg0, %arg0 : i32
+ %lshr_flag = llvm.lshr exact %arg0, %arg0 : i32
+
// Floating point binary operations.
//
// CHECK: {{.*}} = llvm.fadd %[[FLOAT]], %[[FLOAT]] : f32
>From 6b215315834855027515bcc8d9cafa8d5f0ef944 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9on=20Frenot?= <leon.frenot at ens-lyon.fr>
Date: Wed, 6 Nov 2024 14:48:44 +0000
Subject: [PATCH 02/13] fix isExact call
---
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 574cdc0f29f1b7..26cabe51db7d9b 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -83,9 +83,7 @@ class LLVM_IntArithmeticOpWithIsExact<string mnemonic, string instName,
string mlirBuilder = [{
auto op = $_builder.create<$_qualCppClassName>($_location, $lhs, $rhs);
- if ($isExact) {
- op.setIsExact();
- }
+ op.setIsExact($isExact);
$res = op;
}];
let assemblyFormat = [{
>From 547c40ec70dab0dfaa22695b01b9ab53e4bddd3f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9on=20Frenot?= <leon.frenot at ens-lyon.fr>
Date: Wed, 6 Nov 2024 14:52:52 +0000
Subject: [PATCH 03/13] fix hasIsExact call
---
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 26cabe51db7d9b..a8426315ab9797 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -91,7 +91,7 @@ class LLVM_IntArithmeticOpWithIsExact<string mnemonic, string instName,
}];
string llvmBuilder =
"$res = builder.Create" # instName #
- "($lhs, $rhs, /*Name=*/\"\", op.hasIsExact());";
+ "($lhs, $rhs, /*Name=*/\"\", op.getIsExact());";
}
class LLVM_FloatArithmeticOp<string mnemonic, string instName,
list<Trait> traits = []> :
>From 83be047cef34d830c1f8d79cc5974dc88ec752d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9on=20Frenot?= <leon.frenot at ens-lyon.fr>
Date: Wed, 6 Nov 2024 15:18:25 +0000
Subject: [PATCH 04/13] fix printLLVMOpAttrs
---
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index c9bc9533ca2a6b..043cc48c75731e 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -144,7 +144,7 @@ static void printLLVMOpAttrs(OpAsmPrinter &printer, Operation *op,
printer.printOptionalAttrDict(
filteredAttrs, /*elidedAttrs=*/{iface.getOverflowFlagsAttrName()});
} else {
- printer.printOptionalAttrDict(filteredAttrs);
+ printer.printOptionalAttrDict(filteredAttrs, {"isExact"});
}
}
>From 3e4eeae0b5d9044b9347c6a31fec29883ac91562 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9on=20Frenot?= <leon.frenot at ens-lyon.fr>
Date: Thu, 7 Nov 2024 10:47:46 +0000
Subject: [PATCH 05/13] Adding an exact flag interface
---
.../mlir/Dialect/LLVMIR/LLVMInterfaces.td | 27 +++++++++++++++++++
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 5 +++-
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td
index 7e38e0b27fd96b..125e706c25c69e 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td
@@ -87,6 +87,33 @@ def IntegerOverflowFlagsInterface : OpInterface<"IntegerOverflowFlagsInterface">
];
}
+def ExactFlagInterface : OpInterface<"ExactFlagInterface"> {
+ let description = [{
+ This interface defines an LLVM operation with an exact flag and
+ provides a uniform API for accessing it.
+ }];
+
+ let cppNamespace = "::mlir::LLVM";
+
+ let methods = [
+ InterfaceMethod<[{
+ Get the exact flag for the operation.
+ }], "bool", "getIsExact", (ins), [{}], [{
+ return $_op.getIsExact();
+ }]>,
+ InterfaceMethod<[{
+ Set the exact flag for the operation.
+ }], "void", "setIsExact", (ins UnitAttr:$isExact), [{}], [{
+ $_op.setIsExact() = isExact;
+ }]>,
+ StaticInterfaceMethod<[{
+ Get the attribute name of the isExact property.
+ }], "StringRef", "getIsExactName", (ins), [{}], [{
+ return "isExact";
+ }]>,
+ ];
+}
+
def BranchWeightOpInterface : OpInterface<"BranchWeightOpInterface"> {
let description = [{
An interface for operations that can carry branch weights metadata. It
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 043cc48c75731e..03273d306a1875 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -143,8 +143,11 @@ static void printLLVMOpAttrs(OpAsmPrinter &printer, Operation *op,
if (auto iface = dyn_cast<IntegerOverflowFlagsInterface>(op)) {
printer.printOptionalAttrDict(
filteredAttrs, /*elidedAttrs=*/{iface.getOverflowFlagsAttrName()});
+ } else if (auto iface = dyn_cast<ExactFlagInterface>(op)) {
+ printer.printOptionalAttrDict(
+ filteredAttrs, /*elidedAttrs=*/{iface.getIsExactName()});
} else {
- printer.printOptionalAttrDict(filteredAttrs, {"isExact"});
+ printer.printOptionalAttrDict(filteredAttrs);
}
}
>From 824930fc791a385f96522bab3813046cc5bb1fbd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9on=20Frenot?= <leon.frenot at ens-lyon.fr>
Date: Thu, 7 Nov 2024 10:53:19 +0000
Subject: [PATCH 06/13] fix test
---
mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td
index 125e706c25c69e..b7dd858a2ac756 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td
@@ -99,12 +99,12 @@ def ExactFlagInterface : OpInterface<"ExactFlagInterface"> {
InterfaceMethod<[{
Get the exact flag for the operation.
}], "bool", "getIsExact", (ins), [{}], [{
- return $_op.getIsExact();
+ return $_op.getProperties().isExact;
}]>,
InterfaceMethod<[{
Set the exact flag for the operation.
}], "void", "setIsExact", (ins UnitAttr:$isExact), [{}], [{
- $_op.setIsExact() = isExact;
+ $_op.getProperties().isExact = isExact;
}]>,
StaticInterfaceMethod<[{
Get the attribute name of the isExact property.
>From cbe9edf0f6a775d52c67fcd12a2f3ef03bbc284c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9on=20Frenot?= <leon.frenot at ens-lyon.fr>
Date: Thu, 7 Nov 2024 11:02:41 +0000
Subject: [PATCH 07/13] fix 2
---
mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td
index b7dd858a2ac756..12c430df208925 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMInterfaces.td
@@ -103,7 +103,7 @@ def ExactFlagInterface : OpInterface<"ExactFlagInterface"> {
}]>,
InterfaceMethod<[{
Set the exact flag for the operation.
- }], "void", "setIsExact", (ins UnitAttr:$isExact), [{}], [{
+ }], "void", "setIsExact", (ins "bool":$isExact), [{}], [{
$_op.getProperties().isExact = isExact;
}]>,
StaticInterfaceMethod<[{
>From b61ca67b0cd29c951c86e6b46620ce0d2363aecd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9on=20Frenot?= <leon.frenot at ens-lyon.fr>
Date: Thu, 7 Nov 2024 11:18:49 +0000
Subject: [PATCH 08/13] Add interface to Op declaration
---
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index a8426315ab9797..893e5835ceafc4 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -78,7 +78,8 @@ class LLVM_IntArithmeticOpWithOverflowFlag<string mnemonic, string instName,
}
class LLVM_IntArithmeticOpWithIsExact<string mnemonic, string instName,
list<Trait> traits = []> :
- LLVM_ArithmeticOpBase<AnySignlessInteger, mnemonic, instName, traits> {
+ LLVM_ArithmeticOpBase<AnySignlessInteger, mnemonic, instName,
+ !listconcat([DeclareOpInterfaceMethods<ExactFlagInterface>], traits)> {
let arguments = !con(commonArgs, (ins UnitAttr:$isExact));
string mlirBuilder = [{
>From f3d3623842d4f3fd61cffaf6c17ddc16aecc0dea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9on=20Frenot?= <leon.frenot at ens-lyon.fr>
Date: Thu, 7 Nov 2024 13:21:15 +0000
Subject: [PATCH 09/13] possible fix
---
mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 2 +-
mlir/lib/Target/LLVMIR/ModuleImport.cpp | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
index 893e5835ceafc4..b7ce126dbf54dd 100644
--- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
+++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
@@ -84,7 +84,7 @@ class LLVM_IntArithmeticOpWithIsExact<string mnemonic, string instName,
string mlirBuilder = [{
auto op = $_builder.create<$_qualCppClassName>($_location, $lhs, $rhs);
- op.setIsExact($isExact);
+ moduleImport.setExactFlag(inst, op);
$res = op;
}];
let assemblyFormat = [{
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index 1f63519373ecab..d9ab8660a79afe 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -683,6 +683,15 @@ void ModuleImport::setIntegerOverflowFlags(llvm::Instruction *inst,
iface.setOverflowFlags(value);
}
+void ModuleImport::setExactFlag(llvm::Instruction *inst,
+ Operation *op) const {
+ auto iface = cast<ExactFlagInterface>(op);
+
+ bool value = inst->getIsExact();
+
+ iface.setIsExact(value);
+}
+
void ModuleImport::setFastmathFlagsAttr(llvm::Instruction *inst,
Operation *op) const {
auto iface = cast<FastmathFlagsInterface>(op);
>From 51f5bd40b1e314b9eb9175b23d1d24fef6b7f58f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9on=20Frenot?= <leon.frenot at ens-lyon.fr>
Date: Thu, 7 Nov 2024 13:24:23 +0000
Subject: [PATCH 10/13] .h fix
---
mlir/include/mlir/Target/LLVMIR/ModuleImport.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mlir/include/mlir/Target/LLVMIR/ModuleImport.h b/mlir/include/mlir/Target/LLVMIR/ModuleImport.h
index bbb7af58d27393..6c3a500f20e3a9 100644
--- a/mlir/include/mlir/Target/LLVMIR/ModuleImport.h
+++ b/mlir/include/mlir/Target/LLVMIR/ModuleImport.h
@@ -187,6 +187,11 @@ class ModuleImport {
/// operation does not implement the integer overflow flag interface.
void setIntegerOverflowFlags(llvm::Instruction *inst, Operation *op) const;
+ /// Sets the exact flag attribute for the imported operation `op` given
+ /// the original instruction `inst`. Asserts if the operation does not
+ /// implement the exact flag interface.
+ void setExactFlag(llvm::Instruction *inst, Operation *op) const;
+
/// Sets the fastmath flags attribute for the imported operation `op` given
/// the original instruction `inst`. Asserts if the operation does not
/// implement the fastmath interface.
>From 3dcb2a1faab4311dd4357b43d0efb7086ff49d48 Mon Sep 17 00:00:00 2001
From: Leon Frenot <leon.frenot at ens-lyon.fr>
Date: Thu, 7 Nov 2024 13:34:11 +0000
Subject: [PATCH 11/13] Working version
---
mlir/lib/Target/LLVMIR/ModuleImport.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index d9ab8660a79afe..ebc3c0a4695eab 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -687,7 +687,7 @@ void ModuleImport::setExactFlag(llvm::Instruction *inst,
Operation *op) const {
auto iface = cast<ExactFlagInterface>(op);
- bool value = inst->getIsExact();
+ bool value = inst->isExact();
iface.setIsExact(value);
}
>From 92d09e1da69b568484852a84461cf5e139b21491 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9on=20Frenot?= <leon.frenot at ens-lyon.fr>
Date: Thu, 7 Nov 2024 13:55:29 +0000
Subject: [PATCH 12/13] clang format
---
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 4 ++--
mlir/lib/Target/LLVMIR/ModuleImport.cpp | 3 +--
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index 03273d306a1875..6b2d8943bf4885 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -144,8 +144,8 @@ static void printLLVMOpAttrs(OpAsmPrinter &printer, Operation *op,
printer.printOptionalAttrDict(
filteredAttrs, /*elidedAttrs=*/{iface.getOverflowFlagsAttrName()});
} else if (auto iface = dyn_cast<ExactFlagInterface>(op)) {
- printer.printOptionalAttrDict(
- filteredAttrs, /*elidedAttrs=*/{iface.getIsExactName()});
+ printer.printOptionalAttrDict(filteredAttrs,
+ /*elidedAttrs=*/{iface.getIsExactName()});
} else {
printer.printOptionalAttrDict(filteredAttrs);
}
diff --git a/mlir/lib/Target/LLVMIR/ModuleImport.cpp b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
index ebc3c0a4695eab..ccec2034a298b2 100644
--- a/mlir/lib/Target/LLVMIR/ModuleImport.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleImport.cpp
@@ -683,8 +683,7 @@ void ModuleImport::setIntegerOverflowFlags(llvm::Instruction *inst,
iface.setOverflowFlags(value);
}
-void ModuleImport::setExactFlag(llvm::Instruction *inst,
- Operation *op) const {
+void ModuleImport::setExactFlag(llvm::Instruction *inst, Operation *op) const {
auto iface = cast<ExactFlagInterface>(op);
bool value = inst->isExact();
>From 1028933eb8ed72a72894995aadcf82ff08c5bfe5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?L=C3=A9on=20Frenot?= <leon.frenot at ens-lyon.fr>
Date: Thu, 7 Nov 2024 14:10:35 +0000
Subject: [PATCH 13/13] Additional tests
---
mlir/test/Target/LLVMIR/Import/exact.ll | 14 ++++++++++++++
mlir/test/Target/LLVMIR/exact.mlir | 14 ++++++++++++++
2 files changed, 28 insertions(+)
create mode 100644 mlir/test/Target/LLVMIR/Import/exact.ll
create mode 100644 mlir/test/Target/LLVMIR/exact.mlir
diff --git a/mlir/test/Target/LLVMIR/Import/exact.ll b/mlir/test/Target/LLVMIR/Import/exact.ll
new file mode 100644
index 00000000000000..528fee5091d2da
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/Import/exact.ll
@@ -0,0 +1,14 @@
+; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s
+
+; CHECK-LABEL: @exactflag_inst
+define void @exactflag_inst(i64 %arg1, i64 %arg2) {
+ ; CHECK: llvm.udiv exact %{{.*}}, %{{.*}} : i64
+ %1 = udiv exact i64 %arg1, %arg2
+ ; CHECK: llvm.sdiv exact %{{.*}}, %{{.*}} : i64
+ %2 = sdiv exact i64 %arg1, %arg2
+ ; CHECK: llvm.lshr exact %{{.*}}, %{{.*}} : i64
+ %3 = lshr exact i64 %arg1, %arg2
+ ; CHECK: llvm.ashr exact %{{.*}}, %{{.*}} : i64
+ %4 = ashr exact i64 %arg1, %arg2
+ ret void
+}
diff --git a/mlir/test/Target/LLVMIR/exact.mlir b/mlir/test/Target/LLVMIR/exact.mlir
new file mode 100644
index 00000000000000..b6c378c2fdcc94
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/exact.mlir
@@ -0,0 +1,14 @@
+// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
+
+// CHECK-LABEL: define void @exactflag_func
+llvm.func @exactflag_func(%arg0: i64, %arg1: i64) {
+ // CHECK: %{{.*}} = udiv exact i64 %{{.*}}, %{{.*}}
+ %0 = llvm.udiv exact %arg0, %arg1 : i64
+ // CHECK: %{{.*}} = sdiv exact i64 %{{.*}}, %{{.*}}
+ %1 = llvm.sdiv exact %arg0, %arg1 : i64
+ // CHECK: %{{.*}} = lshr exact i64 %{{.*}}, %{{.*}}
+ %2 = llvm.lshr exact %arg0, %arg1 : i64
+ // CHECK: %{{.*}} = ashr exact i64 %{{.*}}, %{{.*}}
+ %3 = llvm.ashr exact %arg0, %arg1 : i64
+ llvm.return
+}
More information about the Mlir-commits
mailing list