[mlir][Arithmetic] Fix printing larger integer attributes in arith.const
authorMarius Hillenbrand <mhillen@linux.ibm.com>
Mon, 25 Jul 2022 03:07:31 +0000 (08:37 +0530)
committerUday Bondhugula <uday@polymagelabs.com>
Mon, 25 Jul 2022 03:07:51 +0000 (08:37 +0530)
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

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

index d3e7258..f2a88e2 100644 (file)
@@ -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());
index 2a8df86..fe241ba 100644 (file)
@@ -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
 }