Skip to content

Commit

Permalink
Add CIR floating-point type lowering test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancern committed Jan 15, 2024
1 parent 56e87cc commit 5ab552d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,10 @@ class CIRConstantLowering
typeConverter->convertType(op.getType()),
op.getValue().cast<mlir::cir::IntAttr>().getValue());
} else if (op.getType().isa<mlir::cir::FloatType>()) {
// TODO(cir): ppcfp128 format floating-point type is lowered to the
// llvm.ppc_fp128 type, which is not supported by mlir::FloatAttr. How to
// lower a constant op with a value of such type to LLVMIR?
assert(!op.getType().cast<mlir::cir::FloatType>().isPpcFp128() && "NYI");
attr = rewriter.getFloatAttr(
typeConverter->convertType(op.getType()),
op.getValue().cast<mlir::cir::FloatAttr>().getValue());
Expand Down
20 changes: 20 additions & 0 deletions clang/test/CIR/Lowering/float.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: cir-opt %s -cir-to-llvm -o %t.mlir
// RUN: FileCheck %s --input-file=%t.mlir

module {
cir.func @test() {
%0 = cir.const(#cir.float<1.0> : !cir.float<bin16>) : !cir.float<bin16>
// CHECK: %0 = llvm.mlir.constant(1.000000e+00 : f16) : f16
%1 = cir.const(#cir.float<1.0> : !cir.float<bin32>) : !cir.float<bin32>
// CHECK: %1 = llvm.mlir.constant(1.000000e+00 : f32) : f32
%2 = cir.const(#cir.float<1.0> : !cir.float<bin64>) : !cir.float<bin64>
// CHECK: %2 = llvm.mlir.constant(1.000000e+00 : f64) : f64
%3 = cir.const(#cir.float<1.0> : !cir.float<bin128>) : !cir.float<bin128>
// CHECK: %3 = llvm.mlir.constant(1.000000e+00 : f128) : f128
%4 = cir.const(#cir.float<1.0> : !cir.float<x86fp80>) : !cir.float<x86fp80>
// CHECK: %4 = llvm.mlir.constant(1.000000e+00 : f80) : f80
%5 = cir.const(#cir.float<1.0> : !cir.float<bf16>) : !cir.float<bf16>
// CHECK: %5 = llvm.mlir.constant(1.000000e+00 : bf16) : bf16
cir.return
}
}

0 comments on commit 5ab552d

Please sign in to comment.