[Mlir-commits] [mlir] 1ef32e7 - [mlir][Arithmetic] Fix printing larger integer attributes in arith.const

Uday Bondhugula llvmlistbot at llvm.org
Sun Jul 24 20:15:51 PDT 2022


Author: Marius Hillenbrand
Date: 2022-07-25T08:37:51+05:30
New Revision: 1ef32e78284bc758112632e9e190b6683ea5b95b

URL: https://github.com/llvm/llvm-project/commit/1ef32e78284bc758112632e9e190b6683ea5b95b
DIFF: https://github.com/llvm/llvm-project/commit/1ef32e78284bc758112632e9e190b6683ea5b95b.diff

LOG: [mlir][Arithmetic] Fix printing larger integer attributes in arith.const

For arith.constant operations of integer type, the operation generates
result names that include the value of the constant (i.e., the
IntegerAttr that defines the constant's value). That code currently
assumes integer widths of 64 bits or less and hits an assert with wider
constants or would create truncated and potentially ambiguous names when
built with assertions disabled.

To enable printing arith.constant ops for arbitrarily wide integer
types, change to use the IntegerAttr's function getValue() when
generating result names.

Also, add a regression test.

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D129930

Added: 
    

Modified: 
    mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp
    mlir/test/Dialect/Arithmetic/ops.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp b/mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp
index d3e7258c568e1..f2a88e2e2416d 100644
--- a/mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp
+++ b/mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp
@@ -95,10 +95,10 @@ void arith::ConstantOp::getAsmResultNames(
     if (intType && intType.getWidth() == 1)
       return setNameFn(getResult(), (intCst.getInt() ? "true" : "false"));
 
-    // Otherwise, build a compex name with the value and type.
+    // Otherwise, build a complex name with the value and type.
     SmallString<32> specialNameBuffer;
     llvm::raw_svector_ostream specialName(specialNameBuffer);
-    specialName << 'c' << intCst.getInt();
+    specialName << 'c' << intCst.getValue();
     if (intType)
       specialName << '_' << type;
     setNameFn(getResult(), specialName.str());

diff  --git a/mlir/test/Dialect/Arithmetic/ops.mlir b/mlir/test/Dialect/Arithmetic/ops.mlir
index 2a8df86122335..fe241ba1d1736 100644
--- a/mlir/test/Dialect/Arithmetic/ops.mlir
+++ b/mlir/test/Dialect/Arithmetic/ops.mlir
@@ -924,6 +924,12 @@ func.func @test_constant() -> () {
   // CHECK: %false = arith.constant false
   %8 = arith.constant false
 
+  // CHECK: %c-1_i128 = arith.constant -1 : i128
+  %9 = arith.constant 340282366920938463463374607431768211455 : i128
+
+  // CHECK: %c85070591730234615865843651857942052864_i128 = arith.constant 85070591730234615865843651857942052864 : i128
+  %10 = arith.constant 85070591730234615865843651857942052864 : i128
+
   return
 }
 


        


More information about the Mlir-commits mailing list