Skip to content

Commit 81aca3f

Browse files
committed
[mlir][llvm] Replace NullOp by ZeroOp
This revision replaces the LLVM dialect NullOp by the recently introduced ZeroOp. The ZeroOp is more generic in the sense that it represents zero values of any LLVM type rather than null pointers only. This is a follow to #65508
1 parent d7359bc commit 81aca3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+134
-160
lines changed

flang/lib/Optimizer/CodeGen/CodeGen.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -1150,7 +1150,7 @@ computeElementDistance(mlir::Location loc, mlir::Type ptrTy, mlir::Type idxTy,
11501150
// *)0 + 1)' trick for all types. The generated instructions are optimized
11511151
// into constant by the first pass of InstCombine, so it should not be a
11521152
// performance issue.
1153-
auto nullPtr = rewriter.create<mlir::LLVM::NullOp>(loc, ptrTy);
1153+
auto nullPtr = rewriter.create<mlir::LLVM::ZeroOp>(loc, ptrTy);
11541154
auto gep = rewriter.create<mlir::LLVM::GEPOp>(
11551155
loc, ptrTy, nullPtr, llvm::ArrayRef<mlir::LLVM::GEPArg>{1});
11561156
return rewriter.create<mlir::LLVM::PtrToIntOp>(loc, idxTy, gep);
@@ -1431,7 +1431,7 @@ struct EmboxCommonConversion : public FIROpConversion<OP> {
14311431
name, Fortran::semantics::typeInfoBuiltinModule))
14321432
fir::emitFatalError(
14331433
loc, "runtime derived type info descriptor was not generated");
1434-
return rewriter.create<mlir::LLVM::NullOp>(
1434+
return rewriter.create<mlir::LLVM::ZeroOp>(
14351435
loc, ::getVoidPtrType(mod.getContext()));
14361436
}
14371437

@@ -1474,7 +1474,7 @@ struct EmboxCommonConversion : public FIROpConversion<OP> {
14741474
} else {
14751475
// Unlimited polymorphic type descriptor with no record type. Set
14761476
// type descriptor address to a clean state.
1477-
typeDesc = rewriter.create<mlir::LLVM::NullOp>(
1477+
typeDesc = rewriter.create<mlir::LLVM::ZeroOp>(
14781478
loc, ::getVoidPtrType(mod.getContext()));
14791479
}
14801480
} else {
@@ -3407,7 +3407,7 @@ struct ZeroOpConversion : public FIROpConversion<fir::ZeroOp> {
34073407
mlir::ConversionPatternRewriter &rewriter) const override {
34083408
mlir::Type ty = convertType(zero.getType());
34093409
if (ty.isa<mlir::LLVM::LLVMPointerType>()) {
3410-
rewriter.replaceOpWithNewOp<mlir::LLVM::NullOp>(zero, ty);
3410+
rewriter.replaceOpWithNewOp<mlir::LLVM::ZeroOp>(zero, ty);
34113411
} else if (ty.isa<mlir::IntegerType>()) {
34123412
rewriter.replaceOpWithNewOp<mlir::LLVM::ConstantOp>(
34133413
zero, ty, mlir::IntegerAttr::get(ty, 0));
@@ -3470,7 +3470,7 @@ struct IsPresentOpConversion : public FIROpConversion<fir::IsPresentOp> {
34703470
};
34713471

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

@@ -3485,11 +3485,11 @@ struct AbsentOpConversion : public FIROpConversion<fir::AbsentOp> {
34853485
assert(!structTy.isOpaque() && !structTy.getBody().empty());
34863486
auto undefStruct = rewriter.create<mlir::LLVM::UndefOp>(loc, ty);
34873487
auto nullField =
3488-
rewriter.create<mlir::LLVM::NullOp>(loc, structTy.getBody()[0]);
3488+
rewriter.create<mlir::LLVM::ZeroOp>(loc, structTy.getBody()[0]);
34893489
rewriter.replaceOpWithNewOp<mlir::LLVM::InsertValueOp>(
34903490
absent, undefStruct, nullField, 0);
34913491
} else {
3492-
rewriter.replaceOpWithNewOp<mlir::LLVM::NullOp>(absent, ty);
3492+
rewriter.replaceOpWithNewOp<mlir::LLVM::ZeroOp>(absent, ty);
34933493
}
34943494
return mlir::success();
34953495
}

flang/test/Fir/convert-to-llvm.fir

+18-18
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func.func @zero_test_ptr() {
145145
return
146146
}
147147

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

151151
// -----
@@ -201,7 +201,7 @@ func.func @test_alloc_and_freemem_one() {
201201
}
202202

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

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

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

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

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

755755
// -----
756756

@@ -1403,7 +1403,7 @@ func.func @test_absent_i64() -> () {
14031403
}
14041404

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

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

@@ -1442,7 +1442,7 @@ func.func @absent() -> i1 {
14421442

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

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

15261526
// CHECK-LABEL: llvm.func @box_tdesc(
15271527
// CHECK-SAME: %[[ARG0:.*]]: !llvm.ptr<struct<(ptr<struct<"dtdesc", (i{{.*}})>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, ptr<i{{.*}}>, array<1 x i{{.*}}>)>>) {
1528-
// 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>>
1528+
// 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>>
15291529
// CHECK: %[[LOAD:.*]] = llvm.load %[[GEP]] : !llvm.ptr<ptr<i{{.*}}>>
15301530

15311531
// -----
@@ -1547,7 +1547,7 @@ func.func @embox0(%arg0: !fir.ref<!fir.array<100xi32>>) {
15471547
// CHECK: %[[C1:.*]] = llvm.mlir.constant(1 : i32) : i32
15481548
// 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{{.*}})>>
15491549
// CHECK: %[[TYPE_CODE:.*]] = llvm.mlir.constant(9 : i32) : i32
1550-
// CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<i32>
1550+
// CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<i32>
15511551
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
15521552
// CHECK: %[[I64_ELEM_SIZE:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<i32> to i64
15531553
// CHECK: %[[DESC:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<array<100 x i32>>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}})>
@@ -1771,7 +1771,7 @@ func.func @xembox0(%arg0: !fir.ref<!fir.array<?xi32>>) {
17711771
// 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>>)>>
17721772
// CHECK: %[[C0:.*]] = llvm.mlir.constant(0 : i64) : i64
17731773
// CHECK: %[[TYPE:.*]] = llvm.mlir.constant(9 : i32) : i32
1774-
// CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<i32>
1774+
// CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<i32>
17751775
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
17761776
// CHECK: %[[ELEM_LEN_I64:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<i32> to i64
17771777
// CHECK: %[[BOX0:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<i32>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i64>>)>
@@ -1820,7 +1820,7 @@ func.func @xembox1(%arg0: !fir.ref<!fir.array<?x!fir.char<1, 10>>>) {
18201820

18211821
// CHECK-LABEL: llvm.func @xembox1(%{{.*}}: !llvm.ptr<array<10 x i8>>) {
18221822
// CHECK: %[[C0:.*]] = llvm.mlir.constant(0 : i64) : i64
1823-
// CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<array<10 x i8>>
1823+
// CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<array<10 x i8>>
18241824
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
18251825
// CHECK: %[[ELEM_LEN_I64:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<array<10 x i8>> to i64
18261826
// 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>>)>
@@ -1870,7 +1870,7 @@ func.func private @_QPxb(!fir.box<!fir.array<?x?xf64>>)
18701870
// CHECK: %[[ARR_SIZE:.*]] = llvm.mul %[[ARR_SIZE_TMP1]], %[[N2]] : i64
18711871
// 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>
18721872
// CHECK: %[[TYPE_CODE:.*]] = llvm.mlir.constant(28 : i32) : i32
1873-
// CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<f64>
1873+
// CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<f64>
18741874
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
18751875
// CHECK: %[[ELEM_LEN_I64:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<f64> to i64
18761876
// CHECK: %[[BOX0:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<f64>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<2 x array<3 x i64>>)>
@@ -1949,7 +1949,7 @@ func.func private @_QPtest_dt_callee(%arg0: !fir.box<!fir.array<?xi32>>)
19491949
// CHECK: %[[ALLOCA_SIZE_X:.*]] = llvm.mlir.constant(1 : i64) : i64
19501950
// 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)>>>
19511951
// CHECK: %[[TYPE_CODE:.*]] = llvm.mlir.constant(9 : i32) : i32
1952-
// CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<i32>
1952+
// CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<i32>
19531953
// CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
19541954
// CHECK: %[[ELEM_LEN_I64:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<i32> to i64
19551955
// CHECK: %[[BOX0:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<i32>, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i64>>)>
@@ -1969,7 +1969,7 @@ func.func private @_QPtest_dt_callee(%arg0: !fir.box<!fir.array<?xi32>>)
19691969
// 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>>)>
19701970
// CHECK: %[[ZERO:.*]] = llvm.mlir.constant(0 : i64) : i64
19711971
// CHECK: %[[ONE:.*]] = llvm.mlir.constant(1 : i64) : i64
1972-
// CHECK: %[[ELE_TYPE:.*]] = llvm.mlir.null : !llvm.ptr<struct<"_QFtest_dt_sliceTt", (i32, i32)>>
1972+
// CHECK: %[[ELE_TYPE:.*]] = llvm.mlir.zero : !llvm.ptr<struct<"_QFtest_dt_sliceTt", (i32, i32)>>
19731973
// 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)>>
19741974
// CHECK: %[[PTRTOINT_DTYPE_SIZE:.*]] = llvm.ptrtoint %[[GEP_DTYPE_SIZE]] : !llvm.ptr<struct<"_QFtest_dt_sliceTt", (i32, i32)>> to i64
19751975
// CHECK: %[[ADJUSTED_OFFSET:.*]] = llvm.sub %[[C1]], %[[ONE]] : i64
@@ -2261,7 +2261,7 @@ func.func @test_rebox_1(%arg0: !fir.box<!fir.array<?x?xf32>>) {
22612261
//CHECK: %[[SIX:.*]] = llvm.mlir.constant(6 : index) : i64
22622262
//CHECK: %[[EIGHTY:.*]] = llvm.mlir.constant(80 : index) : i64
22632263
//CHECK: %[[FLOAT_TYPE:.*]] = llvm.mlir.constant(27 : i32) : i32
2264-
//CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<f32>
2264+
//CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<f32>
22652265
//CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
22662266
//CHECK: %[[ELEM_SIZE_I64:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<f32> to i64
22672267
//CHECK: %[[RBOX:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<f32>, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)>
@@ -2334,7 +2334,7 @@ func.func @foo(%arg0: !fir.box<!fir.array<?x!fir.type<t{i:i32,c:!fir.char<1,10>}
23342334
//CHECK: %[[COMPONENT_OFFSET_1:.*]] = llvm.mlir.constant(1 : i64) : i64
23352335
//CHECK: %[[ELEM_COUNT:.*]] = llvm.mlir.constant(7 : i64) : i64
23362336
//CHECK: %[[TYPE_CHAR:.*]] = llvm.mlir.constant(40 : i32) : i32
2337-
//CHECK: %[[NULL:.*]] = llvm.mlir.null : !llvm.ptr<i8>
2337+
//CHECK: %[[NULL:.*]] = llvm.mlir.zero : !llvm.ptr<i8>
23382338
//CHECK: %[[GEP:.*]] = llvm.getelementptr %[[NULL]][1]
23392339
//CHECK: %[[CHAR_SIZE:.*]] = llvm.ptrtoint %[[GEP]] : !llvm.ptr<i8> to i64
23402340
//CHECK: %[[ELEM_SIZE:.*]] = llvm.mul %[[CHAR_SIZE]], %[[ELEM_COUNT]]

flang/test/Fir/embox-char.fir

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
// CHECK: %[[VAL_30_ST0:.*]] = llvm.load %[[VAL_29]] : !llvm.ptr<i64>
4141
// CHECK: %[[VAL_31_LEN:.*]] = llvm.sdiv %[[VAL_16_BYTESIZE]], %[[VAL_13_WIDTH]] : i64
4242
// CHECK: %[[VAL_32:.*]] = llvm.mlir.constant(44 : i32) : i32
43-
// CHECK: %[[VAL_33:.*]] = llvm.mlir.null : !llvm.ptr<i32>
43+
// CHECK: %[[VAL_33:.*]] = llvm.mlir.zero : !llvm.ptr<i32>
4444
// CHECK: %[[VAL_34:.*]] = llvm.getelementptr %[[VAL_33]][1] : (!llvm.ptr<i32>) -> !llvm.ptr<i32>
4545
// CHECK: %[[VAL_35:.*]] = llvm.ptrtoint %[[VAL_34]] : !llvm.ptr<i32> to i64
4646
// CHECK: %[[VAL_36_BYTESIZE:.*]] = llvm.mul %[[VAL_35]], %[[VAL_31_LEN]] : i64
@@ -137,7 +137,7 @@ func.func @test_char4(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?x?x!fir.cha
137137
// 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>
138138
// CHECK: %[[VAL_30_ST0:.*]] = llvm.load %[[VAL_29]] : !llvm.ptr<i64>
139139
// CHECK: %[[VAL_32:.*]] = llvm.mlir.constant(40 : i32) : i32
140-
// CHECK: %[[VAL_33:.*]] = llvm.mlir.null : !llvm.ptr<i8>
140+
// CHECK: %[[VAL_33:.*]] = llvm.mlir.zero : !llvm.ptr<i8>
141141
// CHECK: %[[VAL_34:.*]] = llvm.getelementptr %[[VAL_33]][1] : (!llvm.ptr<i8>) -> !llvm.ptr<i8>
142142
// CHECK: %[[VAL_35:.*]] = llvm.ptrtoint %[[VAL_34]] : !llvm.ptr<i8> to i64
143143
// CHECK: %[[VAL_36_BYTESIZE:.*]] = llvm.mul %[[VAL_35]], %[[VAL_16_BYTESIZE]] : i64

flang/test/Fir/embox-substring.fir

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func.func private @dump(!fir.box<!fir.array<2x!fir.char<1>>>)
3030
// CHECK-SAME: %[[VAL_1:.*]]: i64) {
3131
// CHECK: %[[VAL_5:.*]] = llvm.mlir.constant(1 : index) : i64
3232
// CHECK: llvm.getelementptr
33-
// CHECK: %[[VAL_28:.*]] = llvm.mlir.null : !llvm.ptr<i8>
33+
// CHECK: %[[VAL_28:.*]] = llvm.mlir.zero : !llvm.ptr<i8>
3434
// CHECK: %[[VAL_29:.*]] = llvm.getelementptr %[[VAL_28]][1] : (!llvm.ptr<i8>) -> !llvm.ptr<i8>
3535
// CHECK: %[[VAL_30:.*]] = llvm.ptrtoint %[[VAL_29]] : !llvm.ptr<i8> to i64
3636
// CHECK: %[[VAL_31:.*]] = llvm.mul %[[VAL_30]], %[[VAL_1]] : i64

flang/test/Fir/tbaa.fir

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ module {
205205

206206
// 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>)> {
207207
// CHECK: %[[VAL_0:.*]] = llvm.mlir.constant(0 : index) : i64
208-
// CHECK: %[[VAL_1:.*]] = llvm.mlir.null : !llvm.ptr<struct<()>>
208+
// CHECK: %[[VAL_1:.*]] = llvm.mlir.zero : !llvm.ptr<struct<()>>
209209
// CHECK: %[[VAL_2:.*]] = llvm.mlir.constant(0 : i64) : i64
210210
// CHECK: %[[VAL_3:.*]] = llvm.mlir.constant(-1 : i32) : i32
211211
// 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>)>
@@ -223,7 +223,7 @@ module {
223223
// CHECK: %[[VAL_16:.*]] = llvm.mlir.constant(1 : i32) : i32
224224
// CHECK: %[[VAL_17:.*]] = llvm.trunc %[[VAL_16]] : i32 to i8
225225
// 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>)>
226-
// CHECK: %[[VAL_19:.*]] = llvm.mlir.null : !llvm.ptr<i8>
226+
// CHECK: %[[VAL_19:.*]] = llvm.mlir.zero : !llvm.ptr<i8>
227227
// CHECK: %[[VAL_20:.*]] = llvm.bitcast %[[VAL_19]] : !llvm.ptr<i8> to !llvm.ptr<i8>
228228
// 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>)>
229229
// CHECK: %[[VAL_22:.*]] = llvm.mlir.constant(0 : i64) : i64

mlir/docs/Dialects/LLVM.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ Some value kinds in LLVM IR, such as constants and undefs, are uniqued in
103103
context and used directly in relevant operations. MLIR does not support such
104104
values for thread-safety and concept parsimony reasons. Instead, regular values
105105
are produced by dedicated operations that have the corresponding semantics:
106-
[`llvm.mlir.constant`](#llvmmlirconstant-mlirllvmconstantop),
107-
[`llvm.mlir.undef`](#llvmmlirundef-mlirllvmundefop),
108-
[`llvm.mlir.poison`](#llvmmlirpoison-mlirllvmpoisonop),
109-
[`llvm.mlir.null`](#llvmmlirnull-mlirllvmnullop). Note how these operations are
106+
[`llvm.mlir.constant`](#llvmmlirconstant-llvmconstantop),
107+
[`llvm.mlir.undef`](#llvmmlirundef-llvmundefop),
108+
[`llvm.mlir.poison`](#llvmmlirpoison-llvmpoisonop),
109+
[`llvm.mlir.zero`](#llvmmlirzero-llvmzeroop). Note how these operations are
110110
prefixed with `mlir.` to indicate that they don't belong to LLVM IR but are only
111111
necessary to model it in MLIR. The values produced by these operations are
112112
usable just like any other value.
@@ -118,11 +118,12 @@ Examples:
118118
// by a float.
119119
%0 = llvm.mlir.undef : !llvm.struct<(i32, f32)>
120120
121-
// Null pointer to i8.
122-
%1 = llvm.mlir.null : !llvm.ptr<i8>
121+
// Null pointer.
122+
%1 = llvm.mlir.zero : !llvm.ptr
123123
124-
// Null pointer to a function with signature void().
125-
%2 = llvm.mlir.null : !llvm.ptr<func<void ()>>
124+
// Create an zero initialized value of structure type with a 32-bit integer
125+
// followed by a float.
126+
%2 = llvm.mlir.zero : !llvm.struct<(i32, f32)>
126127
127128
// Constant 42 as i32.
128129
%3 = llvm.mlir.constant(42 : i32) : i32

mlir/include/mlir/Conversion/LLVMCommon/Pattern.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class ConvertToLLVMPattern : public ConversionPattern {
8989
/// `strides[1]` = llvm.mlir.constant(1 : index) : i64
9090
/// `strides[0]` = `sizes[0]`
9191
/// %size = llvm.mul `sizes[0]`, `sizes[1]` : i64
92-
/// %nullptr = llvm.mlir.null : !llvm.ptr<f32>
92+
/// %nullptr = llvm.mlir.zero : !llvm.ptr<f32>
9393
/// %gep = llvm.getelementptr %nullptr[%size]
9494
/// : (!llvm.ptr<f32>, i64) -> !llvm.ptr<f32>
9595
/// `sizeBytes` = llvm.ptrtoint %gep : !llvm.ptr<f32> to i64

0 commit comments

Comments
 (0)