[Mlir-commits] [mlir] [mlir][ptr] Add constantop convertion (PR #204846)

Fabian Mora llvmlistbot at llvm.org
Fri Jun 19 09:07:39 PDT 2026


================
@@ -370,6 +380,35 @@ LogicalResult TypeOffsetOpConversion::matchAndRewrite(
   return success();
 }
 
+//===----------------------------------------------------------------------===//
+// ConstantOpConversion
+//===----------------------------------------------------------------------===//
+
+LogicalResult ConstantOpConversion::matchAndRewrite(
+    ptr::ConstantOp op, OpAdaptor adaptor,
+    ConversionPatternRewriter &rewriter) const {
+  mlir::TypedAttr value = op.getValue();
+  Type resultType = getTypeConverter()->convertType(op.getType());
+  if (!resultType)
+    return rewriter.notifyMatchFailure(op, "Couldn't convert the result type");
+
+  if (llvm::dyn_cast<ptr::NullAttr>(value)) {
+    rewriter.replaceOpWithNewOp<LLVM::ZeroOp>(op, resultType);
+    return llvm::success();
+  }
+
----------------
fabianmcg wrote:

This assumes that the only attributes constant accepts is address or null, if something changes this can crash in the future.

https://github.com/llvm/llvm-project/pull/204846


More information about the Mlir-commits mailing list