Skip to content

Commit 5ab552d

Browse files
committed
Add CIR floating-point type lowering test
1 parent 56e87cc commit 5ab552d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,10 @@ class CIRConstantLowering
10491049
typeConverter->convertType(op.getType()),
10501050
op.getValue().cast<mlir::cir::IntAttr>().getValue());
10511051
} else if (op.getType().isa<mlir::cir::FloatType>()) {
1052+
// TODO(cir): ppcfp128 format floating-point type is lowered to the
1053+
// llvm.ppc_fp128 type, which is not supported by mlir::FloatAttr. How to
1054+
// lower a constant op with a value of such type to LLVMIR?
1055+
assert(!op.getType().cast<mlir::cir::FloatType>().isPpcFp128() && "NYI");
10521056
attr = rewriter.getFloatAttr(
10531057
typeConverter->convertType(op.getType()),
10541058
op.getValue().cast<mlir::cir::FloatAttr>().getValue());

clang/test/CIR/Lowering/float.cir

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: cir-opt %s -cir-to-llvm -o %t.mlir
2+
// RUN: FileCheck %s --input-file=%t.mlir
3+
4+
module {
5+
cir.func @test() {
6+
%0 = cir.const(#cir.float<1.0> : !cir.float<bin16>) : !cir.float<bin16>
7+
// CHECK: %0 = llvm.mlir.constant(1.000000e+00 : f16) : f16
8+
%1 = cir.const(#cir.float<1.0> : !cir.float<bin32>) : !cir.float<bin32>
9+
// CHECK: %1 = llvm.mlir.constant(1.000000e+00 : f32) : f32
10+
%2 = cir.const(#cir.float<1.0> : !cir.float<bin64>) : !cir.float<bin64>
11+
// CHECK: %2 = llvm.mlir.constant(1.000000e+00 : f64) : f64
12+
%3 = cir.const(#cir.float<1.0> : !cir.float<bin128>) : !cir.float<bin128>
13+
// CHECK: %3 = llvm.mlir.constant(1.000000e+00 : f128) : f128
14+
%4 = cir.const(#cir.float<1.0> : !cir.float<x86fp80>) : !cir.float<x86fp80>
15+
// CHECK: %4 = llvm.mlir.constant(1.000000e+00 : f80) : f80
16+
%5 = cir.const(#cir.float<1.0> : !cir.float<bf16>) : !cir.float<bf16>
17+
// CHECK: %5 = llvm.mlir.constant(1.000000e+00 : bf16) : bf16
18+
cir.return
19+
}
20+
}

0 commit comments

Comments
 (0)