[Mlir-commits] [mlir] Add 'exact' flag to arith.shrui/shrsi/divsi/divui operations (PR #165923)
Jakub Kuderski
llvmlistbot at llvm.org
Wed Nov 5 18:07:57 PST 2025
================
@@ -82,23 +79,37 @@ template <typename SourceOp, typename TargetOp>
class AttrConvertOverflowToLLVM {
public:
AttrConvertOverflowToLLVM(SourceOp srcOp) {
+ using IntegerOverflowFlagsAttr = LLVM::IntegerOverflowFlagsAttr;
+
// Copy the source attributes.
convertedAttr = NamedAttrList{srcOp->getAttrs()};
// Get the name of the arith overflow attribute.
StringRef arithAttrName = SourceOp::getIntegerOverflowAttrName();
- // Remove the source overflow attribute.
+ // Remove the source overflow attribute from the set that will be present
+ // in the target.
if (auto arithAttr = dyn_cast_if_present<arith::IntegerOverflowFlagsAttr>(
convertedAttr.erase(arithAttrName))) {
- overflowFlags = convertArithOverflowFlagsToLLVM(arithAttr.getValue());
+ auto llvmFlag = convertArithOverflowFlagsToLLVM(arithAttr.getValue());
+ // Create a dictionary attribute holding the overflow flags property.
+ // (In the LLVM dialect, the overflow flags are a property, not an
+ // attribute.)
+ MLIRContext *ctx = srcOp.getOperation()->getContext();
+ Builder b(ctx);
+ auto llvmFlagAttr = IntegerOverflowFlagsAttr::get(ctx, llvmFlag);
+ StringRef llvmAttrName = TargetOp::getOverflowFlagsAttrName();
+ SmallVector<NamedAttribute> attrs;
+ attrs.push_back(b.getNamedAttr(llvmAttrName, llvmFlagAttr));
+ // Set the properties attribute of the operation state so that the
+ // property can be updated when the operation is created.
+ propertiesAttr = b.getDictionaryAttr(attrs);
----------------
kuhar wrote:
You don't need a vector just to create a single-element array ref:
```suggestion
// Set the properties attribute of the operation state so that the
// property can be updated when the operation is created.
NamedAttribute attr{llvmAttrName, llvmFlagAttr};
propertiesAttr = b.getDictionaryAttr(ArrayRef(attr));
```
https://github.com/llvm/llvm-project/pull/165923
More information about the Mlir-commits
mailing list