Skip to content

Commit 1cf7b8f

Browse files
committed
Revert "[mlir][llvm] Fix elem type passing into getelementptr (#68136)"
This reverts commit fe283a1. Bot is broken.
1 parent 87c6ff6 commit 1cf7b8f

File tree

3 files changed

+5
-22
lines changed

3 files changed

+5
-22
lines changed

mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td

+2-7
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,8 @@ def LLVM_GEPOp : LLVM_Op<"getelementptr", [Pure,
303303
indices.push_back(
304304
builder.getInt32(valueOrAttr.get<IntegerAttr>().getInt()));
305305
}
306-
307-
Type elemTypeFromAttr = op.getSourceElementType();
308-
auto ptrType = ::llvm::cast<LLVMPointerType>(op.getType());
309-
Type elemTypeFromPtrType = ptrType.getElementType();
310-
311-
llvm::Type *elementType = moduleTranslation.convertType(
312-
elemTypeFromAttr ? elemTypeFromAttr : elemTypeFromPtrType);
306+
Type baseElementType = op.getSourceElementType();
307+
llvm::Type *elementType = moduleTranslation.convertType(baseElementType);
313308
$res = builder.CreateGEP(elementType, $base, indices, "", $inbounds);
314309
}];
315310
let assemblyFormat = [{

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -287,17 +287,14 @@ ParseResult AllocaOp::parse(OpAsmParser &parser, OperationState &result) {
287287
}
288288

289289
/// Checks that the elemental type is present in either the pointer type or
290-
/// the attribute, but not in none or both.
290+
/// the attribute, but not both.
291291
static LogicalResult verifyOpaquePtr(Operation *op, LLVMPointerType ptrType,
292292
std::optional<Type> ptrElementType) {
293-
bool typePresentInPointerType = !ptrType.isOpaque();
294-
bool typePresentInAttribute = ptrElementType.has_value();
295-
296-
if (!typePresentInPointerType && !typePresentInAttribute) {
293+
if (ptrType.isOpaque() && !ptrElementType.has_value()) {
297294
return op->emitOpError() << "expected '" << kElemTypeAttrName
298295
<< "' attribute if opaque pointer type is used";
299296
}
300-
if (typePresentInPointerType && typePresentInAttribute) {
297+
if (!ptrType.isOpaque() && ptrElementType.has_value()) {
301298
return op->emitOpError()
302299
<< "unexpected '" << kElemTypeAttrName
303300
<< "' attribute when non-opaque pointer type is used";

mlir/test/Target/LLVMIR/opaque-ptr.mlir

-9
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ llvm.func @opaque_ptr_gep_struct(%arg0: !llvm.ptr, %arg1: i32) -> !llvm.ptr {
4242
llvm.return %0 : !llvm.ptr
4343
}
4444

45-
// CHECK-LABEL: @opaque_ptr_elem_type
46-
llvm.func @opaque_ptr_elem_type(%0: !llvm.ptr) -> !llvm.ptr {
47-
// CHECK: getelementptr ptr, ptr
48-
%1 = llvm.getelementptr %0[0] { elem_type = !llvm.ptr } : (!llvm.ptr) -> !llvm.ptr
49-
// CHECK: getelementptr ptr, ptr
50-
%2 = llvm.getelementptr %0[0] : (!llvm.ptr) -> !llvm.ptr<ptr>
51-
llvm.return %1 : !llvm.ptr
52-
}
53-
5445
// CHECK-LABEL: @opaque_ptr_matrix_load_store
5546
llvm.func @opaque_ptr_matrix_load_store(%ptr: !llvm.ptr, %stride: i64) -> vector<48 x f32> {
5647
// CHECK: call <48 x float> @llvm.matrix.column.major.load.v48f32.i64

0 commit comments

Comments
 (0)