Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mlir][llvm] Replace NullOp by ZeroOp #67183

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions flang/lib/Optimizer/CodeGen/CodeGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ computeElementDistance(mlir::Location loc, mlir::Type ptrTy, mlir::Type idxTy,
// *)0 + 1)' trick for all types. The generated instructions are optimized
// into constant by the first pass of InstCombine, so it should not be a
// performance issue.
auto nullPtr = rewriter.create<mlir::LLVM::NullOp>(loc, ptrTy);
auto nullPtr = rewriter.create<mlir::LLVM::ZeroOp>(loc, ptrTy);
auto gep = rewriter.create<mlir::LLVM::GEPOp>(
loc, ptrTy, nullPtr, llvm::ArrayRef<mlir::LLVM::GEPArg>{1});
return rewriter.create<mlir::LLVM::PtrToIntOp>(loc, idxTy, gep);
Expand Down Expand Up @@ -1431,7 +1431,7 @@ struct EmboxCommonConversion : public FIROpConversion<OP> {
name, Fortran::semantics::typeInfoBuiltinModule))
fir::emitFatalError(
loc, "runtime derived type info descriptor was not generated");
return rewriter.create<mlir::LLVM::NullOp>(
return rewriter.create<mlir::LLVM::ZeroOp>(
loc, ::getVoidPtrType(mod.getContext()));
}

Expand Down Expand Up @@ -1474,7 +1474,7 @@ struct EmboxCommonConversion : public FIROpConversion<OP> {
} else {
// Unlimited polymorphic type descriptor with no record type. Set
// type descriptor address to a clean state.
typeDesc = rewriter.create<mlir::LLVM::NullOp>(
typeDesc = rewriter.create<mlir::LLVM::ZeroOp>(
loc, ::getVoidPtrType(mod.getContext()));
}
} else {
Expand Down Expand Up @@ -3407,7 +3407,7 @@ struct ZeroOpConversion : public FIROpConversion<fir::ZeroOp> {
mlir::ConversionPatternRewriter &rewriter) const override {
mlir::Type ty = convertType(zero.getType());
if (ty.isa<mlir::LLVM::LLVMPointerType>()) {
rewriter.replaceOpWithNewOp<mlir::LLVM::NullOp>(zero, ty);
rewriter.replaceOpWithNewOp<mlir::LLVM::ZeroOp>(zero, ty);
} else if (ty.isa<mlir::IntegerType>()) {
rewriter.replaceOpWithNewOp<mlir::LLVM::ConstantOp>(
zero, ty, mlir::IntegerAttr::get(ty, 0));
Expand Down Expand Up @@ -3470,7 +3470,7 @@ struct IsPresentOpConversion : public FIROpConversion<fir::IsPresentOp> {
};

/// Create value signaling an absent optional argument in a call, e.g.
/// `fir.absent !fir.ref<i64>` --> `llvm.mlir.null : !llvm.ptr<i64>`
/// `fir.absent !fir.ref<i64>` --> `llvm.mlir.zero : !llvm.ptr<i64>`
struct AbsentOpConversion : public FIROpConversion<fir::AbsentOp> {
using FIROpConversion::FIROpConversion;

Expand All @@ -3485,11 +3485,11 @@ struct AbsentOpConversion : public FIROpConversion<fir::AbsentOp> {
assert(!structTy.isOpaque() && !structTy.getBody().empty());
auto undefStruct = rewriter.create<mlir::LLVM::UndefOp>(loc, ty);
auto nullField =
rewriter.create<mlir::LLVM::NullOp>(loc, structTy.getBody()[0]);
rewriter.create<mlir::LLVM::ZeroOp>(loc, structTy.getBody()[0]);
rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(
absent, undefStruct, nullField, 0);
} else {
rewriter.replaceOpWithNewOp<mlir::LLVM::NullOp>(absent, ty);
rewriter.replaceOpWithNewOp<mlir::LLVM::ZeroOp>(absent, ty);
}
return mlir::success();
}
Expand Down
36 changes: 18 additions & 18 deletions flang/test/Fir/convert-to-llvm.fir
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func.func @zero_test_ptr() {
return
}

// CHECK: %{{.*}} = llvm.mlir.null : !llvm.ptr<f32>
// CHECK: %{{.*}} = llvm.mlir.zero : !llvm.ptr<f32>
// CHECK-NOT: fir.zero_bits

// -----
Expand Down Expand Up @@ -201,7 +201,7 @@ func.func @test_alloc_and_freemem_one() {
}

// CHECK-LABEL: llvm.func @test_alloc_and_freemem_one() {
// CHECK-NEXT: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<i32>
// CHECK-NEXT: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<i32>
// CHECK-NEXT: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
// CHECK-NEXT: %[[N:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<i32> to i64
// CHECK-NEXT: llvm.call @malloc(%[[N]])
Expand All @@ -220,7 +220,7 @@ func.func @test_alloc_and_freemem_several() {
}

// CHECK-LABEL: llvm.func @test_alloc_and_freemem_several() {
// CHECK: [[NULL:%.*]] = llvm.mlir.null : !llvm.ptr<array<100 x f32>>
// CHECK: [[NULL:%.*]] = llvm.mlir.zero : !llvm.ptr<array<100 x f32>>
// CHECK: [[PTR:%.*]] = llvm.getelementptr [[NULL]][{{.*}}] : (!llvm.ptr<array<100 x f32>>) -> !llvm.ptr<array<100 x f32>>
// CHECK: [[N:%.*]] = llvm.ptrtoint [[PTR]] : !llvm.ptr<array<100 x f32>> to i64
// CHECK: [[MALLOC:%.*]] = llvm.call @malloc([[N]])
Expand All @@ -238,7 +238,7 @@ func.func @test_with_shape(%ncols: index, %nrows: index) {

// CHECK-LABEL: llvm.func @test_with_shape
// CHECK-SAME: %[[NCOLS:.*]]: i64, %[[NROWS:.*]]: i64
// CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<f32>
// CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<f32>
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
// CHECK: %[[FOUR:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<f32> to i64
// CHECK: %[[DIM1_SIZE:.*]] = llvm.mul %[[FOUR]], %[[NCOLS]] : i64
Expand All @@ -258,7 +258,7 @@ func.func @test_string_with_shape(%len: index, %nelems: index) {

// CHECK-LABEL: llvm.func @test_string_with_shape
// CHECK-SAME: %[[LEN:.*]]: i64, %[[NELEMS:.*]]: i64)
// CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<i8>
// CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<i8>
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
// CHECK: %[[ONE:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<i8> to i64
// CHECK: %[[LEN_SIZE:.*]] = llvm.mul %[[ONE]], %[[LEN]] : i64
Expand Down Expand Up @@ -750,7 +750,7 @@ func.func @convert_from_i1(%arg0 : i1) {

// CHECK-LABEL: convert_from_i1(
// CHECK-SAME: %[[ARG0:.*]]: i1
// CHECK: %{{.*}} = llvm.zext %[[ARG0]] : i1 to i32
// CHECK: %{{.*}} = llvm.zext %[[ARG0]] : i1 to i32

// -----

Expand Down Expand Up @@ -1403,7 +1403,7 @@ func.func @test_absent_i64() -> () {
}

// CHECK-LABEL: @test_absent_i64
// CHECK-NEXT: %{{.*}} = llvm.mlir.null : !llvm.ptr<i64>
// CHECK-NEXT: %{{.*}} = llvm.mlir.zero : !llvm.ptr<i64>
// CHECK-NEXT: llvm.return
// CHECK-NEXT: }

Expand All @@ -1412,7 +1412,7 @@ func.func @test_absent_box() -> () {
return
}
// CHECK-LABEL: @test_absent_box
// CHECK-NEXT: %{{.*}} = llvm.mlir.null : !llvm.ptr<struct<(ptr<f32>, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)>>
// CHECK-NEXT: %{{.*}} = llvm.mlir.zero : !llvm.ptr<struct<(ptr<f32>, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)>>
// CHECK-NEXT: llvm.return
// CHECK-NEXT: }

Expand Down Expand Up @@ -1442,7 +1442,7 @@ func.func @absent() -> i1 {

// CHECK-LABEL: @absent
// CHECK-SAME: () -> i1
// CHECK-NEXT: %[[ptr:.*]] = llvm.mlir.null : !llvm.ptr<i64>
// CHECK-NEXT: %[[ptr:.*]] = llvm.mlir.zero : !llvm.ptr<i64>
// CHECK-NEXT: %[[ret_val:.*]] = llvm.call @is_present(%[[ptr]]) : (!llvm.ptr<i64>) -> i1
// CHECK-NEXT: llvm.return %[[ret_val]] : i1

Expand Down Expand Up @@ -1525,7 +1525,7 @@ func.func @box_tdesc(%arg0: !fir.box<!fir.type<dtdesc{a:i32}>>) {

// CHECK-LABEL: llvm.func @box_tdesc(
// CHECK-SAME: %[[ARG0:.*]]: !llvm.ptr<struct<(ptr<struct<"dtdesc", (i{{.*}})>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr<i{{.*}}>, array<1 x i{{.*}}>)>>) {
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[ARG0]][0, 7] : (!llvm.ptr<struct<(ptr<struct<"dtdesc", (i{{.*}})>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr<i{{.*}}>, array<1 x i{{.*}}>)>>) -> !llvm.ptr<ptr<i8>>
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[ARG0]][0, 7] : (!llvm.ptr<struct<(ptr<struct<"dtdesc", (i{{.*}})>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr<i{{.*}}>, array<1 x i{{.*}}>)>>) -> !llvm.ptr<ptr<i8>>
// CHECK: %[[LOAD:.*]] = llvm.load %[[GEP]] : !llvm.ptr<ptr<i{{.*}}>>

// -----
Expand All @@ -1547,7 +1547,7 @@ func.func @embox0(%arg0: !fir.ref<!fir.array<100xi32>>) {
// CHECK: %[[C1:.*]] = llvm.mlir.constant(1 : i32) : i32
// CHECK: %[[ALLOCA:.*]] = llvm.alloca %[[C1]] x !llvm.struct<(ptr<array<100 x i32>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}})> {alignment = 8 : i64} : (i32) -> !llvm.ptr<struct<(ptr<array<100 x i32>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}})>>
// CHECK: %[[TYPE_CODE:.*]] = llvm.mlir.constant(9 : i32) : i32
// CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<i32>
// CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<i32>
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
// CHECK: %[[I64_ELEM_SIZE:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<i32> to i64
// CHECK: %[[DESC:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<array<100 x i32>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}})>
Expand Down Expand Up @@ -1771,7 +1771,7 @@ func.func @xembox0(%arg0: !fir.ref<!fir.array<?xi32>>) {
// CHECK: %[[ALLOCA:.*]] = llvm.alloca %[[ALLOCA_SIZE]] x !llvm.struct<(ptr<i32>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i64>>)> {alignment = 8 : i64} : (i32) -> !llvm.ptr<struct<(ptr<i32>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i64>>)>>
// CHECK: %[[C0:.*]] = llvm.mlir.constant(0 : i64) : i64
// CHECK: %[[TYPE:.*]] = llvm.mlir.constant(9 : i32) : i32
// CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<i32>
// CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<i32>
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
// CHECK: %[[ELEM_LEN_I64:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<i32> to i64
// CHECK: %[[BOX0:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<i32>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i64>>)>
Expand Down Expand Up @@ -1820,7 +1820,7 @@ func.func @xembox1(%arg0: !fir.ref<!fir.array<?x!fir.char<1, 10>>>) {

// CHECK-LABEL: llvm.func @xembox1(%{{.*}}: !llvm.ptr<array<10 x i8>>) {
// CHECK: %[[C0:.*]] = llvm.mlir.constant(0 : i64) : i64
// CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<array<10 x i8>>
// CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<array<10 x i8>>
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
// CHECK: %[[ELEM_LEN_I64:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<array<10 x i8>> to i64
// CHECK: %{{.*}} = llvm.insertvalue %[[ELEM_LEN_I64]], %{{.*}}[1] : !llvm.struct<(ptr<array<10 x i8>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i64>>)>
Expand Down Expand Up @@ -1870,7 +1870,7 @@ func.func private @_QPxb(!fir.box<!fir.array<?x?xf64>>)
// CHECK: %[[ARR_SIZE:.*]] = llvm.mul %[[ARR_SIZE_TMP1]], %[[N2]] : i64
// CHECK: %[[ARR:.*]] = llvm.alloca %[[ARR_SIZE]] x f64 {bindc_name = "arr", in_type = !fir.array<?x?xf64>, operandSegmentSizes = array<i32: 0, 2>, uniq_name = "_QFsbEarr"} : (i64) -> !llvm.ptr<f64>
// CHECK: %[[TYPE_CODE:.*]] = llvm.mlir.constant(28 : i32) : i32
// CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<f64>
// CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<f64>
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
// CHECK: %[[ELEM_LEN_I64:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<f64> to i64
// CHECK: %[[BOX0:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<f64>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<2 x array<3 x i64>>)>
Expand Down Expand Up @@ -1949,7 +1949,7 @@ func.func private @_QPtest_dt_callee(%arg0: !fir.box<!fir.array<?xi32>>)
// CHECK: %[[ALLOCA_SIZE_X:.*]] = llvm.mlir.constant(1 : i64) : i64
// CHECK: %[[X:.*]] = llvm.alloca %[[ALLOCA_SIZE_X]] x !llvm.array<20 x struct<"_QFtest_dt_sliceTt", (i32, i32)>> {bindc_name = "x", in_type = !fir.array<20x!fir.type<_QFtest_dt_sliceTt{i:i32,j:i32}>>, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFtest_dt_sliceEx"} : (i64) -> !llvm.ptr<array<20 x struct<"_QFtest_dt_sliceTt", (i32, i32)>>>
// CHECK: %[[TYPE_CODE:.*]] = llvm.mlir.constant(9 : i32) : i32
// CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<i32>
// CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<i32>
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
// CHECK: %[[ELEM_LEN_I64:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<i32> to i64
// CHECK: %[[BOX0:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<i32>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i64>>)>
Expand All @@ -1969,7 +1969,7 @@ func.func private @_QPtest_dt_callee(%arg0: !fir.box<!fir.array<?xi32>>)
// CHECK: %[[BOX6:.*]] = llvm.insertvalue %[[F18ADDENDUM_I8]], %[[BOX5]][6] : !llvm.struct<(ptr<i32>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i64>>)>
// CHECK: %[[ZERO:.*]] = llvm.mlir.constant(0 : i64) : i64
// CHECK: %[[ONE:.*]] = llvm.mlir.constant(1 : i64) : i64
// CHECK: %[[ELE_TYPE:.*]] = llvm.mlir.null : !llvm.ptr<struct<"_QFtest_dt_sliceTt", (i32, i32)>>
// CHECK: %[[ELE_TYPE:.*]] = llvm.mlir.zero : !llvm.ptr<struct<"_QFtest_dt_sliceTt", (i32, i32)>>
// CHECK: %[[GEP_DTYPE_SIZE:.*]] = llvm.getelementptr %[[ELE_TYPE]][1] : (!llvm.ptr<struct<"_QFtest_dt_sliceTt", (i32, i32)>>) -> !llvm.ptr<struct<"_QFtest_dt_sliceTt", (i32, i32)>>
// CHECK: %[[PTRTOINT_DTYPE_SIZE:.*]] = llvm.ptrtoint %[[GEP_DTYPE_SIZE]] : !llvm.ptr<struct<"_QFtest_dt_sliceTt", (i32, i32)>> to i64
// CHECK: %[[ADJUSTED_OFFSET:.*]] = llvm.sub %[[C1]], %[[ONE]] : i64
Expand Down Expand Up @@ -2261,7 +2261,7 @@ func.func @test_rebox_1(%arg0: !fir.box<!fir.array<?x?xf32>>) {
//CHECK: %[[SIX:.*]] = llvm.mlir.constant(6 : index) : i64
//CHECK: %[[EIGHTY:.*]] = llvm.mlir.constant(80 : index) : i64
//CHECK: %[[FLOAT_TYPE:.*]] = llvm.mlir.constant(27 : i32) : i32
//CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<f32>
//CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<f32>
//CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
//CHECK: %[[ELEM_SIZE_I64:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<f32> to i64
//CHECK: %[[RBOX:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<f32>, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)>
Expand Down Expand Up @@ -2334,7 +2334,7 @@ func.func @foo(%arg0: !fir.box<!fir.array<?x!fir.type<t{i:i32,c:!fir.char<1,10>}
//CHECK: %[[COMPONENT_OFFSET_1:.*]] = llvm.mlir.constant(1 : i64) : i64
//CHECK: %[[ELEM_COUNT:.*]] = llvm.mlir.constant(7 : i64) : i64
//CHECK: %[[TYPE_CHAR:.*]] = llvm.mlir.constant(40 : i32) : i32
//CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<i8>
//CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<i8>
//CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
//CHECK: %[[CHAR_SIZE:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<i8> to i64
//CHECK: %[[ELEM_SIZE:.*]] = llvm.mul %[[CHAR_SIZE]], %[[ELEM_COUNT]]
Expand Down
4 changes: 2 additions & 2 deletions flang/test/Fir/embox-char.fir
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// CHECK: %[[VAL_30_ST0:.*]] = llvm.load %[[VAL_29]] : !llvm.ptr<i64>
// CHECK: %[[VAL_31_LEN:.*]] = llvm.sdiv %[[VAL_16_BYTESIZE]], %[[VAL_13_WIDTH]] : i64
// CHECK: %[[VAL_32:.*]] = llvm.mlir.constant(44 : i32) : i32
// CHECK: %[[VAL_33:.*]] = llvm.mlir.null : !llvm.ptr<i32>
// CHECK: %[[VAL_33:.*]] = llvm.mlir.zero : !llvm.ptr<i32>
// CHECK: %[[VAL_34:.*]] = llvm.getelementptr %[[VAL_33]][1] : (!llvm.ptr<i32>) -> !llvm.ptr<i32>
// CHECK: %[[VAL_35:.*]] = llvm.ptrtoint %[[VAL_34]] : !llvm.ptr<i32> to i64
// CHECK: %[[VAL_36_BYTESIZE:.*]] = llvm.mul %[[VAL_35]], %[[VAL_31_LEN]] : i64
Expand Down Expand Up @@ -137,7 +137,7 @@ func.func @test_char4(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?x!fir.cha
// CHECK: %[[VAL_29:.*]] = llvm.getelementptr %[[VAL_10]][0, 7, %[[VAL_11]], 2] : (!llvm.ptr<struct<(ptr<i8>, i64, i32, i8, i8, i8, i8, array<2 x array<3 x i64>>)>>, i64) -> !llvm.ptr<i64>
// CHECK: %[[VAL_30_ST0:.*]] = llvm.load %[[VAL_29]] : !llvm.ptr<i64>
// CHECK: %[[VAL_32:.*]] = llvm.mlir.constant(40 : i32) : i32
// CHECK: %[[VAL_33:.*]] = llvm.mlir.null : !llvm.ptr<i8>
// CHECK: %[[VAL_33:.*]] = llvm.mlir.zero : !llvm.ptr<i8>
// CHECK: %[[VAL_34:.*]] = llvm.getelementptr %[[VAL_33]][1] : (!llvm.ptr<i8>) -> !llvm.ptr<i8>
// CHECK: %[[VAL_35:.*]] = llvm.ptrtoint %[[VAL_34]] : !llvm.ptr<i8> to i64
// CHECK: %[[VAL_36_BYTESIZE:.*]] = llvm.mul %[[VAL_35]], %[[VAL_16_BYTESIZE]] : i64
Expand Down
2 changes: 1 addition & 1 deletion flang/test/Fir/embox-substring.fir
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func.func private @dump(!fir.box<!fir.array<2x!fir.char<1>>>)
// CHECK-SAME: %[[VAL_1:.*]]: i64) {
// CHECK: %[[VAL_5:.*]] = llvm.mlir.constant(1 : index) : i64
// CHECK: llvm.getelementptr
// CHECK: %[[VAL_28:.*]] = llvm.mlir.null : !llvm.ptr<i8>
// CHECK: %[[VAL_28:.*]] = llvm.mlir.zero : !llvm.ptr<i8>
// CHECK: %[[VAL_29:.*]] = llvm.getelementptr %[[VAL_28]][1] : (!llvm.ptr<i8>) -> !llvm.ptr<i8>
// CHECK: %[[VAL_30:.*]] = llvm.ptrtoint %[[VAL_29]] : !llvm.ptr<i8> to i64
// CHECK: %[[VAL_31:.*]] = llvm.mul %[[VAL_30]], %[[VAL_1]] : i64
Expand Down
4 changes: 2 additions & 2 deletions flang/test/Fir/tbaa.fir
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ module {

// CHECK-LABEL: llvm.mlir.global internal @_QFEx() {addr_space = 0 : i32} : !llvm.struct<(ptr<struct<()>>, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>, ptr<i8>, array<1 x i64>)> {
// CHECK: %[[VAL_0:.*]] = llvm.mlir.constant(0 : index) : i64
// CHECK: %[[VAL_1:.*]] = llvm.mlir.null : !llvm.ptr<struct<()>>
// CHECK: %[[VAL_1:.*]] = llvm.mlir.zero : !llvm.ptr<struct<()>>
// CHECK: %[[VAL_2:.*]] = llvm.mlir.constant(0 : i64) : i64
// CHECK: %[[VAL_3:.*]] = llvm.mlir.constant(-1 : i32) : i32
// CHECK: %[[VAL_4:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<struct<()>>, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>, ptr<i8>, array<1 x i64>)>
Expand All @@ -223,7 +223,7 @@ module {
// CHECK: %[[VAL_16:.*]] = llvm.mlir.constant(1 : i32) : i32
// CHECK: %[[VAL_17:.*]] = llvm.trunc %[[VAL_16]] : i32 to i8
// CHECK: %[[VAL_18:.*]] = llvm.insertvalue %[[VAL_17]], %[[VAL_15]][6] : !llvm.struct<(ptr<struct<()>>, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>, ptr<i8>, array<1 x i64>)>
// CHECK: %[[VAL_19:.*]] = llvm.mlir.null : !llvm.ptr<i8>
// CHECK: %[[VAL_19:.*]] = llvm.mlir.zero : !llvm.ptr<i8>
// CHECK: %[[VAL_20:.*]] = llvm.bitcast %[[VAL_19]] : !llvm.ptr<i8> to !llvm.ptr<i8>
// CHECK: %[[VAL_21:.*]] = llvm.insertvalue %[[VAL_20]], %[[VAL_18]][8] : !llvm.struct<(ptr<struct<()>>, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>, ptr<i8>, array<1 x i64>)>
// CHECK: %[[VAL_22:.*]] = llvm.mlir.constant(0 : i64) : i64
Expand Down
17 changes: 9 additions & 8 deletions mlir/docs/Dialects/LLVM.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ Some value kinds in LLVM IR, such as constants and undefs, are uniqued in
context and used directly in relevant operations. MLIR does not support such
values for thread-safety and concept parsimony reasons. Instead, regular values
are produced by dedicated operations that have the corresponding semantics:
[`llvm.mlir.constant`](#llvmmlirconstant-mlirllvmconstantop),
[`llvm.mlir.undef`](#llvmmlirundef-mlirllvmundefop),
[`llvm.mlir.poison`](#llvmmlirpoison-mlirllvmpoisonop),
[`llvm.mlir.null`](#llvmmlirnull-mlirllvmnullop). Note how these operations are
[`llvm.mlir.constant`](#llvmmlirconstant-llvmconstantop),
[`llvm.mlir.undef`](#llvmmlirundef-llvmundefop),
[`llvm.mlir.poison`](#llvmmlirpoison-llvmpoisonop),
[`llvm.mlir.zero`](#llvmmlirzero-llvmzeroop). Note how these operations are
prefixed with `mlir.` to indicate that they don't belong to LLVM IR but are only
necessary to model it in MLIR. The values produced by these operations are
usable just like any other value.
Expand All @@ -118,11 +118,12 @@ Examples:
// by a float.
%0 = llvm.mlir.undef : !llvm.struct<(i32, f32)>

// Null pointer to i8.
%1 = llvm.mlir.null : !llvm.ptr<i8>
// Null pointer.
%1 = llvm.mlir.zero : !llvm.ptr

// Null pointer to a function with signature void().
%2 = llvm.mlir.null : !llvm.ptr<func<void ()>>
// Create an zero initialized value of structure type with a 32-bit integer
// followed by a float.
%2 = llvm.mlir.zero : !llvm.struct<(i32, f32)>

// Constant 42 as i32.
%3 = llvm.mlir.constant(42 : i32) : i32
Expand Down
2 changes: 1 addition & 1 deletion mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ConvertToLLVMPattern : public ConversionPattern {
/// `strides[1]` = llvm.mlir.constant(1 : index) : i64
/// `strides[0]` = `sizes[0]`
/// %size = llvm.mul `sizes[0]`, `sizes[1]` : i64
/// %nullptr = llvm.mlir.null : !llvm.ptr<f32>
/// %nullptr = llvm.mlir.zero : !llvm.ptr<f32>
/// %gep = llvm.getelementptr %nullptr[%size]
/// : (!llvm.ptr<f32>, i64) -> !llvm.ptr<f32>
/// `sizeBytes` = llvm.ptrtoint %gep : !llvm.ptr<f32> to i64
Expand Down
Loading