Skip to content

Commit 01c3e25

Browse files
authored
[flang] restrict fir.convert lowering (#172117)
Restrict lowering of fir.convert and exclude core memref types from it. This is in preparation for a lowering that accommodates MemRef dialect.
1 parent 28e9954 commit 01c3e25

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,15 @@ struct ConvertOpConversion : public fir::FIROpConversion<fir::ConvertOp> {
816816
mlir::ConversionPatternRewriter &rewriter) const override {
817817
auto fromFirTy = convert.getValue().getType();
818818
auto toFirTy = convert.getRes().getType();
819+
820+
// Let more specialized conversions (e.g. FIR to memref
821+
// converters) handle fir.convert when either side is a memref. This
822+
// avoids interfering with descriptor-based flows such as fir.box /
823+
// fir.box_addr and keeps this pattern focused on value conversions.
824+
if (mlir::isa<mlir::MemRefType>(fromFirTy) ||
825+
mlir::isa<mlir::MemRefType>(toFirTy))
826+
return mlir::failure();
827+
819828
auto fromTy = convertType(fromFirTy);
820829
auto toTy = convertType(toFirTy);
821830
mlir::Value op0 = adaptor.getOperands()[0];
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: not fir-opt --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s -o - 2>&1 | FileCheck %s
2+
3+
// This test ensures that the FIR CodeGen ConvertOpConversion
4+
// rejects fir.convert when either the source or the destination
5+
// type is a memref (i.e. it fails to legalize those ops).
6+
7+
module {
8+
// CHECK: error: failed to legalize operation 'fir.convert'
9+
func.func @memref_to_ref_convert(%arg0: memref<f32>) {
10+
%0 = fir.convert %arg0 : (memref<f32>) -> !fir.ref<f32>
11+
return
12+
}
13+
}
14+
15+

0 commit comments

Comments
 (0)