Skip to content

Commit

Permalink
[clang][RISCV] Set HasLegalHalfType to true if zfh is enabled
Browse files Browse the repository at this point in the history
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
  • Loading branch information
asb committed May 5, 2023
1 parent c7cd7a0 commit 560065b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
3 changes: 3 additions & 0 deletions clang/lib/Basic/Targets/RISCV.cpp
Expand Up @@ -320,6 +320,9 @@ bool RISCVTargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
if (ABI.empty())
ABI = ISAInfo->computeDefaultABI().str();

if (ISAInfo->hasExtension("zfh"))
HasLegalHalfType = true;

return true;
}

Expand Down
10 changes: 3 additions & 7 deletions clang/test/CodeGen/RISCV/Float16-arith.c
Expand Up @@ -11,8 +11,7 @@
_Float16 x, y, z;

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

// NOZFH-LABEL: define dso_local void @f16_add
// NOZFH-SAME: () #[[ATTR0:[0-9]+]] {
Expand All @@ -30,12 +29,9 @@ _Float16 x, y, z;
// ZFH-SAME: () #[[ATTR0:[0-9]+]] {
// ZFH-NEXT: entry:
// ZFH-NEXT: [[TMP0:%.*]] = load half, ptr @y, align 2
// ZFH-NEXT: [[EXT:%.*]] = fpext half [[TMP0]] to float
// ZFH-NEXT: [[TMP1:%.*]] = load half, ptr @z, align 2
// ZFH-NEXT: [[EXT1:%.*]] = fpext half [[TMP1]] to float
// ZFH-NEXT: [[ADD:%.*]] = fadd float [[EXT]], [[EXT1]]
// ZFH-NEXT: [[UNPROMOTION:%.*]] = fptrunc float [[ADD]] to half
// ZFH-NEXT: store half [[UNPROMOTION]], ptr @x, align 2
// ZFH-NEXT: [[ADD:%.*]] = fadd half [[TMP0]], [[TMP1]]
// ZFH-NEXT: store half [[ADD]], ptr @x, align 2
// ZFH-NEXT: ret void
//
void f16_add() {
Expand Down

0 comments on commit 560065b

Please sign in to comment.