Skip to content

Commit 560065b

Browse files
committed
[clang][RISCV] Set HasLegalHalfType to true if zfh is enabled
The desired semantics for HasLegalHalfType are slightly unclear in that the comment for HasLegalHalfType says "True if the backend supports operations on the half LLVM IR type." Which operations? We get very limited scalar operations with zfhmin, more with zfh, and vector support with zvfh. While the comment for hasLegalHalfType() says "Determine whether _Float16 is supported on this target." This patch sets HasLegalHalfType to true for zfh. Differential Revision: https://reviews.llvm.org/D145071
1 parent c7cd7a0 commit 560065b

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,9 @@ bool RISCVTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
320320
if (ABI.empty())
321321
ABI = ISAInfo->computeDefaultABI().str();
322322

323+
if (ISAInfo->hasExtension("zfh"))
324+
HasLegalHalfType = true;
325+
323326
return true;
324327
}
325328

clang/test/CodeGen/RISCV/Float16-arith.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
_Float16 x, y, z;
1212

1313
// With no native half type support (no zfh), f16 will be promoted to f32.
14-
// With zfh, it shouldn't be (FIXME: set HasLegalHalfType = true in order to
15-
// get this behaviour for zfh).
14+
// With zfh, it shouldn't be.
1615

1716
// NOZFH-LABEL: define dso_local void @f16_add
1817
// NOZFH-SAME: () #[[ATTR0:[0-9]+]] {
@@ -30,12 +29,9 @@ _Float16 x, y, z;
3029
// ZFH-SAME: () #[[ATTR0:[0-9]+]] {
3130
// ZFH-NEXT: entry:
3231
// ZFH-NEXT: [[TMP0:%.*]] = load half, ptr @y, align 2
33-
// ZFH-NEXT: [[EXT:%.*]] = fpext half [[TMP0]] to float
3432
// ZFH-NEXT: [[TMP1:%.*]] = load half, ptr @z, align 2
35-
// ZFH-NEXT: [[EXT1:%.*]] = fpext half [[TMP1]] to float
36-
// ZFH-NEXT: [[ADD:%.*]] = fadd float [[EXT]], [[EXT1]]
37-
// ZFH-NEXT: [[UNPROMOTION:%.*]] = fptrunc float [[ADD]] to half
38-
// ZFH-NEXT: store half [[UNPROMOTION]], ptr @x, align 2
33+
// ZFH-NEXT: [[ADD:%.*]] = fadd half [[TMP0]], [[TMP1]]
34+
// ZFH-NEXT: store half [[ADD]], ptr @x, align 2
3935
// ZFH-NEXT: ret void
4036
//
4137
void f16_add() {

0 commit comments

Comments
 (0)