[PATCH] D76231: Make ConstantOp::getAsmResultNames() handle signfull constants

Frej Drejhammar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 16 07:03:15 PDT 2020


frej created this revision.
frej added a reviewer: antiagainst.
Herald added subscribers: llvm-commits, Joonsoo, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, shauheen, burmako, jpienaar, rriddle, mehdi_amini.
Herald added a project: LLVM.

Since IntegerAttr::getInt() was updated in
35b685270b410f6a1351c2a527021f22330c25b9 <https://reviews.llvm.org/rG35b685270b410f6a1351c2a527021f22330c25b9> to only apply to signless
integers, trying to round trip an explicitly signed/unsigned constant
through mlir-opt as triggered an assert when
ConstantOp::getAsmResultNames() calls IntegerAttr::getInt().

This patch extends ConstantOp::getAsmResultNames() to deal with
signfull integers.
-


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76231

Files:
  mlir/lib/Dialect/StandardOps/IR/Ops.cpp
  mlir/test/IR/core-ops.mlir


Index: mlir/test/IR/core-ops.mlir
===================================================================
--- mlir/test/IR/core-ops.mlir
+++ mlir/test/IR/core-ops.mlir
@@ -98,6 +98,12 @@
   // CHECK: %cst = constant 4.300000e+01 : bf16
   %9 = constant 43.0 : bf16
 
+  // CHECK: %c42_si32 = constant 42 : si32
+  %c42_si32 = constant 42 : si32
+
+  // CHECK: %c42_ui32 = constant 42 : ui32
+  %c42_ui32 = constant 42 : ui32
+
   // CHECK: %f = constant @func_with_ops : (f32) -> ()
   %10 = constant @func_with_ops : (f32) -> ()
 
Index: mlir/lib/Dialect/StandardOps/IR/Ops.cpp
===================================================================
--- mlir/lib/Dialect/StandardOps/IR/Ops.cpp
+++ mlir/lib/Dialect/StandardOps/IR/Ops.cpp
@@ -878,7 +878,14 @@
     // 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';
+    if (intTy && intTy.isSigned())
+      specialName << intCst.getSInt();
+    else if (intTy && intTy.isUnsigned())
+      specialName << intCst.getUInt();
+    else
+      specialName << intCst.getInt();
+
     if (intTy)
       specialName << '_' << type;
     setNameFn(getResult(), specialName.str());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76231.250552.patch
Type: text/x-patch
Size: 1298 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200316/303fff25/attachment.bin>


More information about the llvm-commits mailing list