Skip to content

Commit 7a5d9f2

Browse files
committed
Use fpext and fptrunc instead
1 parent 0c9c48c commit 7a5d9f2

File tree

6 files changed

+10
-21
lines changed

6 files changed

+10
-21
lines changed

clang/lib/CodeGen/TargetBuiltins/RISCV.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -415,11 +415,9 @@ Value *CodeGenFunction::EmitRISCVBuiltinExpr(unsigned BuiltinID,
415415

416416
// XAndesBFHCvt
417417
case RISCV::BI__builtin_riscv_nds_fcvt_s_bf16:
418-
ID = Intrinsic::riscv_nds_fcvt_s_bf16;
419-
break;
418+
return Builder.CreateFPExt(Ops[0], FloatTy);
420419
case RISCV::BI__builtin_riscv_nds_fcvt_bf16_s:
421-
ID = Intrinsic::riscv_nds_fcvt_bf16_s;
422-
break;
420+
return Builder.CreateFPTrunc(Ops[0], BFloatTy);
423421

424422
// Vector builtins are handled from here.
425423
#include "clang/Basic/riscv_vector_builtin_cg.inc"

clang/test/CodeGen/RISCV/riscv-xandesbfhcvt-c-api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
// CHECK-LABEL: @test_fcvt_s_bf16(
1010
// CHECK-NEXT: entry:
11-
// CHECK-NEXT: [[TMP0:%.*]] = call float @llvm.riscv.nds.fcvt.s.bf16(bfloat [[BF:%.*]])
11+
// CHECK-NEXT: [[TMP0:%.*]] = fpext bfloat [[BF:%.*]] to float
1212
// CHECK-NEXT: ret float [[TMP0]]
1313
//
1414
float test_fcvt_s_bf16(__bf16 bf) {
@@ -17,7 +17,7 @@ float test_fcvt_s_bf16(__bf16 bf) {
1717

1818
// CHECK-LABEL: @test_fcvt_bf16_s(
1919
// CHECK-NEXT: entry:
20-
// CHECK-NEXT: [[TMP0:%.*]] = call bfloat @llvm.riscv.nds.fcvt.bf16.s(float [[SF:%.*]])
20+
// CHECK-NEXT: [[TMP0:%.*]] = fptrunc float [[SF:%.*]] to bfloat
2121
// CHECK-NEXT: ret bfloat [[TMP0]]
2222
//
2323
__bf16 test_fcvt_bf16_s(float sf) {

clang/test/CodeGen/RISCV/riscv-xandesbfhcvt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
// CHECK-LABEL: @test_fcvt_s_bf16(
88
// CHECK-NEXT: entry:
9-
// CHECK-NEXT: [[TMP0:%.*]] = call float @llvm.riscv.nds.fcvt.s.bf16(bfloat [[BF:%.*]])
9+
// CHECK-NEXT: [[TMP0:%.*]] = fpext bfloat [[BF:%.*]] to float
1010
// CHECK-NEXT: ret float [[TMP0]]
1111
//
1212
float test_fcvt_s_bf16(__bf16 bf) {
@@ -15,7 +15,7 @@ float test_fcvt_s_bf16(__bf16 bf) {
1515

1616
// CHECK-LABEL: @test_fcvt_bf16_s(
1717
// CHECK-NEXT: entry:
18-
// CHECK-NEXT: [[TMP0:%.*]] = call bfloat @llvm.riscv.nds.fcvt.bf16.s(float [[SF:%.*]])
18+
// CHECK-NEXT: [[TMP0:%.*]] = fptrunc float [[SF:%.*]] to bfloat
1919
// CHECK-NEXT: ret bfloat [[TMP0]]
2020
//
2121
__bf16 test_fcvt_bf16_s(float sf) {

llvm/include/llvm/IR/IntrinsicsRISCVXAndes.td

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
let TargetPrefix = "riscv" in {
14-
// Andes Scalar BFloat16 Conversion Extension
15-
def int_riscv_nds_fcvt_s_bf16
16-
: DefaultAttrsIntrinsic<[llvm_float_ty], [llvm_bfloat_ty],
17-
[IntrNoMem, IntrSpeculatable]>;
18-
19-
def int_riscv_nds_fcvt_bf16_s
20-
: DefaultAttrsIntrinsic<[llvm_bfloat_ty], [llvm_float_ty],
21-
[IntrNoMem, IntrSpeculatable]>;
22-
2314
// Andes Vector BFloat16 Conversion Extension
2415
def int_riscv_nds_vfwcvt_s_bf16 : RISCVConversionUnMasked;
2516
def int_riscv_nds_vfncvt_bf16_s : RISCVConversionUnMaskedRoundingMode;

llvm/lib/Target/RISCV/RISCVInstrInfoXAndes.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,9 @@ def : Sh3AddPat<NDS_LEA_D_ZE>;
768768
} // Predicates = [HasVendorXAndesPerf, IsRV64]
769769

770770
let Predicates = [HasVendorXAndesBFHCvt] in {
771-
def : Pat<(int_riscv_nds_fcvt_s_bf16 (bf16 FPR16:$rs)),
771+
def : Pat<(fpextend (bf16 FPR16:$rs)),
772772
(NDS_FCVT_S_BF16 (bf16 FPR16:$rs))>;
773-
def : Pat<(bf16 (int_riscv_nds_fcvt_bf16_s FPR32:$rs)),
773+
def : Pat<(bf16 (fpround FPR32:$rs)),
774774
(NDS_FCVT_BF16_S FPR32:$rs)>;
775775
} // Predicates = [HasVendorXAndesBFHCvt]
776776

llvm/test/CodeGen/RISCV/xandesbfhcvt.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ define float @fcvt_s_bf16(bfloat %a) nounwind {
1111
; CHECK: # %bb.0:
1212
; CHECK-NEXT: nds.fcvt.s.bf16 fa0, fa0
1313
; CHECK-NEXT: ret
14-
%1 = call float @llvm.riscv.nds.fcvt.s.bf16(bfloat %a)
14+
%1 = fpext bfloat %a to float
1515
ret float %1
1616
}
1717

@@ -22,6 +22,6 @@ define bfloat @fcvt_bf16_s(float %a) nounwind {
2222
; CHECK: # %bb.0:
2323
; CHECK-NEXT: nds.fcvt.bf16.s fa0, fa0
2424
; CHECK-NEXT: ret
25-
%1 = call bfloat @llvm.riscv.nds.fcvt.bf16.s(float %a)
25+
%1 = fptrunc float %a to bfloat
2626
ret bfloat %1
2727
}

0 commit comments

Comments
 (0)