Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 00e900a

Browse files
committedNov 6, 2017
[IR] redefine 'UnsafeAlgebra' / 'reassoc' fast-math-flags and add 'trans' fast-math-flag
As discussed on llvm-dev: http://lists.llvm.org/pipermail/llvm-dev/2016-November/107104.html and again more recently: http://lists.llvm.org/pipermail/llvm-dev/2017-October/118118.html ...this is a step in cleaning up our fast-math-flags implementation in IR to better match the capabilities of both clang's user-visible flags and the backend's flags for SDNode. As proposed in the above threads, we're replacing the 'UnsafeAlgebra' bit (which had the 'umbrella' meaning that all flags are set) with a new bit that only applies to algebraic reassociation - 'AllowReassoc'. We're also adding a bit to allow approximations for library functions called 'ApproxFunc' (this was initially proposed as 'libm' or similar). ...and we're out of bits. 7 bits ought to be enough for anyone, right? :) FWIW, I did look at getting this out of SubclassOptionalData via SubclassData (spacious 16-bits), but that's apparently already used for other purposes. Also, I don't think we can just add a field to FPMathOperator because Operator is not intended to be instantiated. We'll defer movement of FMF to another day. We keep the 'fast' keyword. I thought about removing that, but seeing IR like this: %f.fast = fadd reassoc nnan ninf nsz arcp contract afn float %op1, %op2 ...made me think we want to keep the shortcut synonym. Finally, this change is binary incompatible with existing IR as seen in the compatibility tests. This statement: "Newer releases can ignore features from older releases, but they cannot miscompile them. For example, if nsw is ever replaced with something else, dropping it would be a valid way to upgrade the IR." ( http://llvm.org/docs/DeveloperPolicy.html#ir-backwards-compatibility ) ...provides the flexibility we want to make this change without requiring a new IR version. Ie, we're not loosening the FP strictness of existing IR. At worst, we will fail to optimize some previously 'fast' code because it's no longer recognized as 'fast'. This should get fixed as we audit/squash all of the uses of 'isFast()'. Note: an inter-dependent clang commit to use the new API name should closely follow commit. Differential Revision: https://reviews.llvm.org/D39304 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317488 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ae8a000 commit 00e900a

32 files changed

+387
-191
lines changed
 

‎docs/LangRef.rst

+86-56
Original file line numberDiff line numberDiff line change
@@ -2272,11 +2272,11 @@ seq\_cst total orderings of other operations that are not marked
22722272
Fast-Math Flags
22732273
---------------
22742274

2275-
LLVM IR floating-point binary ops (:ref:`fadd <i_fadd>`,
2275+
LLVM IR floating-point operations (:ref:`fadd <i_fadd>`,
22762276
:ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
22772277
:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`) and :ref:`call <i_call>`
2278-
instructions have the following flags that can be set to enable
2279-
otherwise unsafe floating point transformations.
2278+
may use the following flags to enable otherwise unsafe
2279+
floating-point transformations.
22802280

22812281
``nnan``
22822282
No NaNs - Allow optimizations to assume the arguments and result are not
@@ -2300,10 +2300,17 @@ otherwise unsafe floating point transformations.
23002300
Allow floating-point contraction (e.g. fusing a multiply followed by an
23012301
addition into a fused multiply-and-add).
23022302

2303+
``afn``
2304+
Approximate functions - Allow substitution of approximate calculations for
2305+
functions (sin, log, sqrt, etc). See floating-point intrinsic definitions
2306+
for places where this can apply to LLVM's intrinsic math functions.
2307+
2308+
``reassoc``
2309+
Allow reassociation transformations for floating-point instructions.
2310+
This may dramatically change results in floating point.
2311+
23032312
``fast``
2304-
Fast - Allow algebraically equivalent transformations that may
2305-
dramatically change results in floating point (e.g. reassociate). This
2306-
flag implies all the others.
2313+
This flag implies all of the others.
23072314

23082315
.. _uselistorder:
23092316

@@ -10483,7 +10490,7 @@ Syntax:
1048310490
"""""""
1048410491

1048510492
This is an overloaded intrinsic. You can use ``llvm.sqrt`` on any
10486-
floating point or vector of floating point type. Not all targets support
10493+
floating-point or vector of floating-point type. Not all targets support
1048710494
all types however.
1048810495

1048910496
::
@@ -10497,20 +10504,22 @@ all types however.
1049710504
Overview:
1049810505
"""""""""
1049910506

10500-
The '``llvm.sqrt``' intrinsics return the square root of the specified value,
10501-
returning the same value as the libm '``sqrt``' functions would, but without
10502-
trapping or setting ``errno``.
10507+
The '``llvm.sqrt``' intrinsics return the square root of the specified value.
1050310508

1050410509
Arguments:
1050510510
""""""""""
1050610511

10507-
The argument and return value are floating point numbers of the same type.
10512+
The argument and return value are floating-point numbers of the same type.
1050810513

1050910514
Semantics:
1051010515
""""""""""
1051110516

10512-
This function returns the square root of the operand if it is a nonnegative
10513-
floating point number.
10517+
Return the same value as a corresponding libm '``sqrt``' function but without
10518+
trapping or setting ``errno``. For types specified by IEEE-754, the result
10519+
matches a conforming libm implementation.
10520+
10521+
When specified with the fast-math-flag 'afn', the result may be approximated
10522+
using a less accurate calculation.
1051410523

1051510524
'``llvm.powi.*``' Intrinsic
1051610525
^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -10557,7 +10566,7 @@ Syntax:
1055710566
"""""""
1055810567

1055910568
This is an overloaded intrinsic. You can use ``llvm.sin`` on any
10560-
floating point or vector of floating point type. Not all targets support
10569+
floating-point or vector of floating-point type. Not all targets support
1056110570
all types however.
1056210571

1056310572
::
@@ -10576,14 +10585,16 @@ The '``llvm.sin.*``' intrinsics return the sine of the operand.
1057610585
Arguments:
1057710586
""""""""""
1057810587

10579-
The argument and return value are floating point numbers of the same type.
10588+
The argument and return value are floating-point numbers of the same type.
1058010589

1058110590
Semantics:
1058210591
""""""""""
1058310592

10584-
This function returns the sine of the specified operand, returning the
10585-
same values as the libm ``sin`` functions would, and handles error
10586-
conditions in the same way.
10593+
Return the same value as a corresponding libm '``sin``' function but without
10594+
trapping or setting ``errno``.
10595+
10596+
When specified with the fast-math-flag 'afn', the result may be approximated
10597+
using a less accurate calculation.
1058710598

1058810599
'``llvm.cos.*``' Intrinsic
1058910600
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -10592,7 +10603,7 @@ Syntax:
1059210603
"""""""
1059310604

1059410605
This is an overloaded intrinsic. You can use ``llvm.cos`` on any
10595-
floating point or vector of floating point type. Not all targets support
10606+
floating-point or vector of floating-point type. Not all targets support
1059610607
all types however.
1059710608

1059810609
::
@@ -10611,14 +10622,16 @@ The '``llvm.cos.*``' intrinsics return the cosine of the operand.
1061110622
Arguments:
1061210623
""""""""""
1061310624

10614-
The argument and return value are floating point numbers of the same type.
10625+
The argument and return value are floating-point numbers of the same type.
1061510626

1061610627
Semantics:
1061710628
""""""""""
1061810629

10619-
This function returns the cosine of the specified operand, returning the
10620-
same values as the libm ``cos`` functions would, and handles error
10621-
conditions in the same way.
10630+
Return the same value as a corresponding libm '``cos``' function but without
10631+
trapping or setting ``errno``.
10632+
10633+
When specified with the fast-math-flag 'afn', the result may be approximated
10634+
using a less accurate calculation.
1062210635

1062310636
'``llvm.pow.*``' Intrinsic
1062410637
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -10627,7 +10640,7 @@ Syntax:
1062710640
"""""""
1062810641

1062910642
This is an overloaded intrinsic. You can use ``llvm.pow`` on any
10630-
floating point or vector of floating point type. Not all targets support
10643+
floating-point or vector of floating-point type. Not all targets support
1063110644
all types however.
1063210645

1063310646
::
@@ -10647,15 +10660,16 @@ specified (positive or negative) power.
1064710660
Arguments:
1064810661
""""""""""
1064910662

10650-
The second argument is a floating point power, and the first is a value
10651-
to raise to that power.
10663+
The arguments and return value are floating-point numbers of the same type.
1065210664

1065310665
Semantics:
1065410666
""""""""""
1065510667

10656-
This function returns the first value raised to the second power,
10657-
returning the same values as the libm ``pow`` functions would, and
10658-
handles error conditions in the same way.
10668+
Return the same value as a corresponding libm '``pow``' function but without
10669+
trapping or setting ``errno``.
10670+
10671+
When specified with the fast-math-flag 'afn', the result may be approximated
10672+
using a less accurate calculation.
1065910673

1066010674
'``llvm.exp.*``' Intrinsic
1066110675
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -10664,7 +10678,7 @@ Syntax:
1066410678
"""""""
1066510679

1066610680
This is an overloaded intrinsic. You can use ``llvm.exp`` on any
10667-
floating point or vector of floating point type. Not all targets support
10681+
floating-point or vector of floating-point type. Not all targets support
1066810682
all types however.
1066910683

1067010684
::
@@ -10684,13 +10698,16 @@ value.
1068410698
Arguments:
1068510699
""""""""""
1068610700

10687-
The argument and return value are floating point numbers of the same type.
10701+
The argument and return value are floating-point numbers of the same type.
1068810702

1068910703
Semantics:
1069010704
""""""""""
1069110705

10692-
This function returns the same values as the libm ``exp`` functions
10693-
would, and handles error conditions in the same way.
10706+
Return the same value as a corresponding libm '``exp``' function but without
10707+
trapping or setting ``errno``.
10708+
10709+
When specified with the fast-math-flag 'afn', the result may be approximated
10710+
using a less accurate calculation.
1069410711

1069510712
'``llvm.exp2.*``' Intrinsic
1069610713
^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -10699,7 +10716,7 @@ Syntax:
1069910716
"""""""
1070010717

1070110718
This is an overloaded intrinsic. You can use ``llvm.exp2`` on any
10702-
floating point or vector of floating point type. Not all targets support
10719+
floating-point or vector of floating-point type. Not all targets support
1070310720
all types however.
1070410721

1070510722
::
@@ -10719,13 +10736,16 @@ specified value.
1071910736
Arguments:
1072010737
""""""""""
1072110738

10722-
The argument and return value are floating point numbers of the same type.
10739+
The argument and return value are floating-point numbers of the same type.
1072310740

1072410741
Semantics:
1072510742
""""""""""
1072610743

10727-
This function returns the same values as the libm ``exp2`` functions
10728-
would, and handles error conditions in the same way.
10744+
Return the same value as a corresponding libm '``exp2``' function but without
10745+
trapping or setting ``errno``.
10746+
10747+
When specified with the fast-math-flag 'afn', the result may be approximated
10748+
using a less accurate calculation.
1072910749

1073010750
'``llvm.log.*``' Intrinsic
1073110751
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -10734,7 +10754,7 @@ Syntax:
1073410754
"""""""
1073510755

1073610756
This is an overloaded intrinsic. You can use ``llvm.log`` on any
10737-
floating point or vector of floating point type. Not all targets support
10757+
floating-point or vector of floating-point type. Not all targets support
1073810758
all types however.
1073910759

1074010760
::
@@ -10754,13 +10774,16 @@ value.
1075410774
Arguments:
1075510775
""""""""""
1075610776

10757-
The argument and return value are floating point numbers of the same type.
10777+
The argument and return value are floating-point numbers of the same type.
1075810778

1075910779
Semantics:
1076010780
""""""""""
1076110781

10762-
This function returns the same values as the libm ``log`` functions
10763-
would, and handles error conditions in the same way.
10782+
Return the same value as a corresponding libm '``log``' function but without
10783+
trapping or setting ``errno``.
10784+
10785+
When specified with the fast-math-flag 'afn', the result may be approximated
10786+
using a less accurate calculation.
1076410787

1076510788
'``llvm.log10.*``' Intrinsic
1076610789
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -10769,7 +10792,7 @@ Syntax:
1076910792
"""""""
1077010793

1077110794
This is an overloaded intrinsic. You can use ``llvm.log10`` on any
10772-
floating point or vector of floating point type. Not all targets support
10795+
floating-point or vector of floating-point type. Not all targets support
1077310796
all types however.
1077410797

1077510798
::
@@ -10789,13 +10812,16 @@ specified value.
1078910812
Arguments:
1079010813
""""""""""
1079110814

10792-
The argument and return value are floating point numbers of the same type.
10815+
The argument and return value are floating-point numbers of the same type.
1079310816

1079410817
Semantics:
1079510818
""""""""""
1079610819

10797-
This function returns the same values as the libm ``log10`` functions
10798-
would, and handles error conditions in the same way.
10820+
Return the same value as a corresponding libm '``log10``' function but without
10821+
trapping or setting ``errno``.
10822+
10823+
When specified with the fast-math-flag 'afn', the result may be approximated
10824+
using a less accurate calculation.
1079910825

1080010826
'``llvm.log2.*``' Intrinsic
1080110827
^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -10804,7 +10830,7 @@ Syntax:
1080410830
"""""""
1080510831

1080610832
This is an overloaded intrinsic. You can use ``llvm.log2`` on any
10807-
floating point or vector of floating point type. Not all targets support
10833+
floating-point or vector of floating-point type. Not all targets support
1080810834
all types however.
1080910835

1081010836
::
@@ -10824,13 +10850,16 @@ value.
1082410850
Arguments:
1082510851
""""""""""
1082610852

10827-
The argument and return value are floating point numbers of the same type.
10853+
The argument and return value are floating-point numbers of the same type.
1082810854

1082910855
Semantics:
1083010856
""""""""""
1083110857

10832-
This function returns the same values as the libm ``log2`` functions
10833-
would, and handles error conditions in the same way.
10858+
Return the same value as a corresponding libm '``log2``' function but without
10859+
trapping or setting ``errno``.
10860+
10861+
When specified with the fast-math-flag 'afn', the result may be approximated
10862+
using a less accurate calculation.
1083410863

1083510864
'``llvm.fma.*``' Intrinsic
1083610865
^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -10839,7 +10868,7 @@ Syntax:
1083910868
"""""""
1084010869

1084110870
This is an overloaded intrinsic. You can use ``llvm.fma`` on any
10842-
floating point or vector of floating point type. Not all targets support
10871+
floating-point or vector of floating-point type. Not all targets support
1084310872
all types however.
1084410873

1084510874
::
@@ -10853,20 +10882,21 @@ all types however.
1085310882
Overview:
1085410883
"""""""""
1085510884

10856-
The '``llvm.fma.*``' intrinsics perform the fused multiply-add
10857-
operation.
10885+
The '``llvm.fma.*``' intrinsics perform the fused multiply-add operation.
1085810886

1085910887
Arguments:
1086010888
""""""""""
1086110889

10862-
The argument and return value are floating point numbers of the same
10863-
type.
10890+
The arguments and return value are floating-point numbers of the same type.
1086410891

1086510892
Semantics:
1086610893
""""""""""
1086710894

10868-
This function returns the same values as the libm ``fma`` functions
10869-
would, and does not set errno.
10895+
Return the same value as a corresponding libm '``fma``' function but without
10896+
trapping or setting ``errno``.
10897+
10898+
When specified with the fast-math-flag 'afn', the result may be approximated
10899+
using a less accurate calculation.
1087010900

1087110901
'``llvm.fabs.*``' Intrinsic
1087210902
^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)