[Mlir-commits] [mlir] [mlir][spirv] Fix a crash of typeConverter with non supported type (PR #79955)

Kohei Yamaguchi llvmlistbot at llvm.org
Mon Jan 29 23:21:48 PST 2024


https://github.com/sott0n created https://github.com/llvm/llvm-project/pull/79955

Fixes a crash in the convert-to-spirv-llvm pass caused by unsupported types (e.g., spirv.matrix). This PR fixes it by checking the converted type.

Fixes #60017

>From 4abb2ac407ff9c89d951def478349f924fb7139d Mon Sep 17 00:00:00 2001
From: Kohei Yamaguchi <fix7211 at gmail.com>
Date: Tue, 30 Jan 2024 15:43:57 +0000
Subject: [PATCH] [mlir][spirv] Fix a crash of typeConverter with non supported
 type

---
 mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp b/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
index c62e676efc159..c7c67c04c8919 100644
--- a/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
+++ b/mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
@@ -367,12 +367,13 @@ class AccessChainPattern : public SPIRVToLLVMConversion<spirv::AccessChainOp> {
     Value zero = rewriter.create<LLVM::ConstantOp>(
         op.getLoc(), llvmIndexType, rewriter.getIntegerAttr(indexType, 0));
     indices.insert(indices.begin(), zero);
-    rewriter.replaceOpWithNewOp<LLVM::GEPOp>(
-        op, dstType,
-        typeConverter.convertType(
-            cast<spirv::PointerType>(op.getBasePtr().getType())
-                .getPointeeType()),
-        adaptor.getBasePtr(), indices);
+
+    auto elementType = typeConverter.convertType(
+        cast<spirv::PointerType>(op.getBasePtr().getType()).getPointeeType());
+    if (!elementType)
+      return failure();
+    rewriter.replaceOpWithNewOp<LLVM::GEPOp>(op, dstType, elementType,
+                                             adaptor.getBasePtr(), indices);
     return success();
   }
 };



More information about the Mlir-commits mailing list