[clang] 41b951c - [RISCV] Fix int16 -> __fp16 conversion code gen
Kito Cheng via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 29 20:10:50 PDT 2022
Author: Kito Cheng
Date: 2022-04-30T11:10:44+08:00
New Revision: 41b951c92931b65c25485b224901d8cb00163b8e
URL: https://github.com/llvm/llvm-project/commit/41b951c92931b65c25485b224901d8cb00163b8e
DIFF: https://github.com/llvm/llvm-project/commit/41b951c92931b65c25485b224901d8cb00163b8e.diff
LOG: [RISCV] Fix int16 -> __fp16 conversion code gen
clang emit wrong code sequence for `int16`(`short`) to `__fp16` conversion,
and that should fix the code gen directly is the right way I think,
but I found there is a FIXME comment in clang/Basic/TargetInfo.h say
that's should be removed in future so I think just let swich to using
generic LLVM IR rather than llvm.convert.to.fp16 intrinsics code gen
path is enough.
```
/// Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used
/// to convert to and from __fp16.
/// FIXME: This function should be removed once all targets stop using the
/// conversion intrinsics.
virtual bool useFP16ConversionIntrinsics() const {
return true;
}
```
Reviewed By: craig.topper
Differential Revision: https://reviews.llvm.org/D124509
Added:
Modified:
clang/lib/Basic/Targets/RISCV.h
clang/test/CodeGen/RISCV/__fp16-convert.c
Removed:
################################################################################
diff --git a/clang/lib/Basic/Targets/RISCV.h b/clang/lib/Basic/Targets/RISCV.h
index 5331ed4a50aef..7817e6e81e26a 100644
--- a/clang/lib/Basic/Targets/RISCV.h
+++ b/clang/lib/Basic/Targets/RISCV.h
@@ -96,6 +96,10 @@ class RISCVTargetInfo : public TargetInfo {
DiagnosticsEngine &Diags) override;
bool hasBitIntType() const override { return true; }
+
+ bool useFP16ConversionIntrinsics() const override {
+ return false;
+ }
};
class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
public:
diff --git a/clang/test/CodeGen/RISCV/__fp16-convert.c b/clang/test/CodeGen/RISCV/__fp16-convert.c
index cdb666617553a..36c746df7d340 100644
--- a/clang/test/CodeGen/RISCV/__fp16-convert.c
+++ b/clang/test/CodeGen/RISCV/__fp16-convert.c
@@ -6,10 +6,10 @@ __fp16 y;
short z;
// CHECK-LABEL: @bar1(
// CHECK-NEXT: entry:
-// CHECK-NEXT: [[TMP0:%.*]] = load i16, ptr @y, align 2
-// CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.convert.from.fp16.f32(i16 [[TMP0]])
-// CHECK-NEXT: [[CONV:%.*]] = fptosi float [[TMP1]] to i16
-// CHECK-NEXT: store i16 [[CONV]], ptr @z, align 2
+// CHECK-NEXT: [[TMP0:%.*]] = load half, ptr @y, align 2
+// CHECK-NEXT: [[CONV:%.*]] = fpext half [[TMP0]] to float
+// CHECK-NEXT: [[CONV1:%.*]] = fptosi float [[CONV]] to i16
+// CHECK-NEXT: store i16 [[CONV1]], ptr @z, align 2
// CHECK-NEXT: ret void
//
void bar1(){
@@ -18,7 +18,9 @@ void bar1(){
// CHECK-LABEL: @bar2(
// CHECK-NEXT: entry:
// CHECK-NEXT: [[TMP0:%.*]] = load i16, ptr @z, align 2
-// CHECK-NEXT: store i16 [[TMP0]], ptr @y, align 2
+// CHECK-NEXT: [[CONV:%.*]] = sitofp i16 [[TMP0]] to float
+// CHECK-NEXT: [[CONV1:%.*]] = fptrunc float [[CONV]] to half
+// CHECK-NEXT: store half [[CONV1]], ptr @y, align 2
// CHECK-NEXT: ret void
//
void bar2(){
More information about the cfe-commits
mailing list