This is an archive of the discontinued LLVM Phabricator instance.

Remove implicit conversion that promotes half to other larger precision types for fp classification builtins
ClosedPublic

Authored by Jim on Dec 4 2019, 11:07 PM.

Details

Summary

It shouldn't promote half to double or any larger precision types for fp classification builtins.
Because fp classification builtins would get incorrect result with promoted argument.
For example, __builtin_isnormal with a subnormal half value should return false, but it is not.
That the subnormal half value is promoted to a normal double value.

Diff Detail

Event Timeline

Jim created this revision.Dec 4 2019, 11:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 4 2019, 11:07 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Thank you for the patch -- can you add some test cases?

clang/lib/Sema/SemaChecking.cpp
5849–5850

I think this should be combined with the code above. Something like:

bool IgnoreCast = false;
if (CastArg-> is Float) {
  assert(stuff);
  IgnoreCast = true;
} else if (CastArg-> is Half) {
  assert(stuff);
  IgnoreCast = true;
}

if (IgnoreCast) {
  Cast->setSubExpr(nullptr);
  TheCall->setArg(NumArgs - 1, CastArg);
}
Jim updated this revision to Diff 232765.Dec 9 2019, 12:29 AM

Thank you for review.
Update patch and add tests that test half value will not be promoted to double.

aaron.ballman accepted this revision.Dec 9 2019, 10:26 AM

LGTM, insofar as I understand __fp16 semantics.

This revision is now accepted and ready to land.Dec 9 2019, 10:26 AM
This revision was automatically updated to reflect the committed changes.

This causes build bot failures on SystemZ due to a failed assertion in ConstantFP::getInfinity:
http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/28723/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Abuiltins.c