This is an archive of the discontinued LLVM Phabricator instance.

Add flag to enable native half type
ClosedPublic

Authored by pirama on May 14 2015, 1:37 PM.

Details

Summary

r235215 enables support in LLVM for legalizing f16 type in the IR. AArch64
already had support for this. r235215 and some backend patches brought support
for ARM, X86, X86-64, Mips and Mips64.

This change exposes the LangOption 'NativeHalfType' in the command line, so the
backend legalization can be used if desired. NativeHalfType is enabled for
OpenCL (current behavior) or if '-fnative-half-type' is set.

Diff Detail

Repository
rL LLVM

Event Timeline

pirama updated this revision to Diff 25806.May 14 2015, 1:37 PM
pirama retitled this revision from to Add flag to enable native half type.
pirama updated this object.
pirama edited the test plan for this revision. (Show Details)
pirama added reviewers: olista01, steven_wu, ab.
pirama added subscribers: srhines, Unknown Object (MLST).
ab accepted this revision.May 14 2015, 2:03 PM
ab edited edge metadata.

LGTM, see inline nits. I'll trust you know what you're doing in making this a cc1 option.

-Ahmed

include/clang/Driver/CC1Options.td
550–553 ↗(On Diff #25806)

I don't like "half": it should really be about "__fp16". But that's also a problem for -fallow-half-*, so I'm fine with it.

We can have a more explicit description though. How about "Use the native half type for __fp16 instead of promoting to float" ?

lib/Frontend/CompilerInvocation.cpp
1588–1589 ↗(On Diff #25806)

How about:

Ops.NativeHalfType |= Arg.hasArg(Opt_fnative_half_type);
1593 ↗(On Diff #25806)

Spurious whitespace?

test/CodeGen/fp16-ops.c
2 ↗(On Diff #25806)

You can split these lines in a separate commit, helps readability.

176 ↗(On Diff #25806)

Now that it makes a difference, can you add "float" in the ones where it's missing?
You can do that separately as well.

228–229 ↗(On Diff #25806)

One thing you could do is separate all the clang-promoted comparisons like this and group them together. You can then share CHECK- and F16TOF32 for these with HALF, if you add a NATIVE-HALF: [[F16TOF32:...]] and yet another, *really* shared CHECK prefix. Not sure it helps though.

This revision is now accepted and ready to land.May 14 2015, 2:03 PM
pirama updated this revision to Diff 25816.May 14 2015, 3:05 PM
pirama edited edge metadata.

Changes based on review comments

A CC1 option is enough for our purposes, and matches the other fallow-half-* argument.

test/CodeGen/fp16-ops.c
228–229 ↗(On Diff #25806)

I'll leave this check as-is. Having three different prefixes that are all interdependent is too complicated :)

This revision was automatically updated to reflect the committed changes.