Skip to content
This repository was archived by the owner on Jan 1, 2023. It is now read-only.

Commit bdf2ed5

Browse files
committed
[LangRef] make it clear that FP instructions do not have side effects
Also, fix the undef vs. UB example to use 'sdiv' because that can trigger div-by-zero UB. The existing text for the constrained intrinsics says: "By default, LLVM optimization passes assume that the rounding mode is round-to-nearest and that floating point exceptions will not be monitored. Constrained FP intrinsics are used to support non-default rounding modes and accurately preserve exception behavior without compromising LLVM’s ability to optimize FP code when the default behavior is used." ...so the additional text with the normal FP opcodes should make the different modes clear. Differential Revision: https://reviews.llvm.org/D44216 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@327138 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 85e70cc commit bdf2ed5

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

docs/LangRef.rst

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,17 +3037,17 @@ uses with" concept would not hold.
30373037

30383038
.. code-block:: llvm
30393039

3040-
%A = fdiv undef, %X
3041-
%B = fdiv %X, undef
3040+
%A = sdiv undef, %X
3041+
%B = sdiv %X, undef
30423042
Safe:
3043-
%A = undef
3043+
%A = 0
30443044
b: unreachable
30453045

30463046
These examples show the crucial difference between an *undefined value*
30473047
and *undefined behavior*. An undefined value (like '``undef``') is
30483048
allowed to have an arbitrary bit-pattern. This means that the ``%A``
3049-
operation can be constant folded to '``undef``', because the '``undef``'
3050-
could be an SNaN, and ``fdiv`` is not (currently) defined on SNaN's.
3049+
operation can be constant folded to '``0``', because the '``undef``'
3050+
could be zero, and zero divided by any value is zero.
30513051
However, in the second example, we can make a more aggressive
30523052
assumption: because the ``undef`` is allowed to be an arbitrary value,
30533053
we are allowed to assume that it could be zero. Since a divide by zero
@@ -6404,6 +6404,9 @@ Semantics:
64046404
""""""""""
64056405

64066406
The value produced is the floating-point sum of the two operands.
6407+
This instruction is assumed to execute in the default floating-point
6408+
environment. It has no side effects. Users can not assume that any
6409+
floating-point exception state is updated by this instruction.
64076410
This instruction can also take any number of :ref:`fast-math
64086411
flags <fastmath>`, which are optimization hints to enable otherwise
64096412
unsafe floating-point optimizations:
@@ -6499,6 +6502,9 @@ Semantics:
64996502
""""""""""
65006503

65016504
The value produced is the floating-point difference of the two operands.
6505+
This instruction is assumed to execute in the default floating-point
6506+
environment. It has no side effects. Users can not assume that any
6507+
floating-point exception state is updated by this instruction.
65026508
This instruction can also take any number of :ref:`fast-math
65036509
flags <fastmath>`, which are optimization hints to enable otherwise
65046510
unsafe floating-point optimizations:
@@ -6592,6 +6598,9 @@ Semantics:
65926598
""""""""""
65936599

65946600
The value produced is the floating-point product of the two operands.
6601+
This instruction is assumed to execute in the default floating-point
6602+
environment. It has no side effects. Users can not assume that any
6603+
floating-point exception state is updated by this instruction.
65956604
This instruction can also take any number of :ref:`fast-math
65966605
flags <fastmath>`, which are optimization hints to enable otherwise
65976606
unsafe floating-point optimizations:
@@ -6724,6 +6733,9 @@ Semantics:
67246733
""""""""""
67256734

67266735
The value produced is the floating-point quotient of the two operands.
6736+
This instruction is assumed to execute in the default floating-point
6737+
environment. It has no side effects. Users can not assume that any
6738+
floating-point exception state is updated by this instruction.
67276739
This instruction can also take any number of :ref:`fast-math
67286740
flags <fastmath>`, which are optimization hints to enable otherwise
67296741
unsafe floating-point optimizations:
@@ -6868,6 +6880,9 @@ The value produced is the floating-point remainder of the two operands.
68686880
This is the same output as a libm '``fmod``' function, but without any
68696881
possibility of setting ``errno``. The remainder has the same sign as the
68706882
dividend.
6883+
This instruction is assumed to execute in the default floating-point
6884+
environment. It has no side effects. Users can not assume that any
6885+
floating-point exception state is updated by this instruction.
68716886
This instruction can also take any number of :ref:`fast-math
68726887
flags <fastmath>`, which are optimization hints to enable otherwise
68736888
unsafe floating-point optimizations:

0 commit comments

Comments
 (0)