Page MenuHomePhabricator

[DAGCombine] Adding a hook to improve the precision of fsqrt if the input is denormal
Needs ReviewPublic

Authored by steven.zhang on Jun 1 2020, 9:06 PM.

Details

Reviewers
spatel
RKSimon
jsji
hfinkel
Group Reviewers
Restricted Project
Summary

For now, we will hardcode the result as 0.0 if the input is denormal or 0. That will have the impact the precision. As the fsqrt added belong to the cold path of the cmp+branch, it won't impact the performance for normal inputs for PowerPC. Besides, it removes the xxlxor of the hot path.

clang without this patch

sqrt(2.2250738585072014e-308) = 1.4916681462400413e-154
sqrt(2.2250738585072009e-308) = 0
sqrt(4.9406564584124654e-324) = 0

With this patch:

sqrt(2.2250738585072014e-308) = 1.4916681462400413e-154
sqrt(2.2250738585072009e-308) = 1.4916681462400412e-154
sqrt(4.9406564584124654e-324) = 2.2227587494850775e-162

Diff Detail

Event Timeline

steven.zhang created this revision.Jun 1 2020, 9:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 1 2020, 9:06 PM
spatel added a comment.Jun 3 2020, 6:09 AM

Not sure about other targets, but x86 is mostly expected to flush denorms (FTZ/DAZ) when using fast-math, so this should not matter even if we decide to override the default setting.

llvm/include/llvm/CodeGen/TargetLowering.h
4213

Can we have this default to:

return DAG.getConstantFP(0.0, SDLoc(Operand), Operand.getValueType());

and save some code in the calling function?

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
21403

"value that provided" -> "value provided"