Skip to content

Commit 8d3353c

Browse files
committed
Fixups
1 parent 5cc741f commit 8d3353c

File tree

3 files changed

+53
-25
lines changed

3 files changed

+53
-25
lines changed

llvm/docs/LangRef.rst

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,9 +3685,9 @@ Fast-Math Flags
36853685

36863686
LLVM IR floating-point operations (:ref:`fneg <i_fneg>`, :ref:`fadd <i_fadd>`,
36873687
:ref:`fsub <i_fsub>`, :ref:`fmul <i_fmul>`, :ref:`fdiv <i_fdiv>`,
3688-
:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`), :ref:`phi <i_phi>`,
3689-
:ref:`select <i_select>` and :ref:`call <i_call>`
3690-
may use the following flags to enable otherwise unsafe
3688+
:ref:`frem <i_frem>`, :ref:`fcmp <i_fcmp>`), and :ref:`phi <i_phi>`,
3689+
:ref:`select <i_select>`, or :ref:`call <i_call>` instructions that return
3690+
floating-point types may use the following flags to enable otherwise unsafe
36913691
floating-point transformations.
36923692

36933693
``fast``
@@ -3709,6 +3709,16 @@ floating-point transformations.
37093709
argument or zero result as insignificant. This does not imply that -0.0
37103710
is poison and/or guaranteed to not exist in the operation.
37113711

3712+
.. _fastmath_return_types:
3713+
3714+
Note: For :ref:`phi <i_phi>`, :ref:`select <i_select>`, and :ref:`call <i_call>`
3715+
instructions, the following return types are considered to be floating-point
3716+
types:
3717+
3718+
- Floating-point scalar or vector types
3719+
- Array types (nested to any depth) of floating-point scalar or vector types
3720+
- Homogeneous literal struct types of floating-point scalar or vector types
3721+
37123722
Rewrite-based flags
37133723
^^^^^^^^^^^^^^^^^^^
37143724

@@ -4343,7 +4353,7 @@ recursive, can be opaqued, and are never uniqued.
43434353
:Examples:
43444354

43454355
+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4346-
| ``{ i32, i32, i32 }`` | A triple of three ``i32`` values |
4356+
| ``{ i32, i32, i32 }`` | A triple of three ``i32`` values (this is a "homogeneous" struct as all element types are the same) |
43474357
+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
43484358
| ``{ float, ptr }`` | A pair, where the first element is a ``float`` and the second element is a :ref:`pointer <t_pointer>`. |
43494359
+------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
@@ -12472,8 +12482,8 @@ instruction's return value on the same edge).
1247212482
The optional ``fast-math-flags`` marker indicates that the phi has one
1247312483
or more :ref:`fast-math-flags <fastmath>`. These are optimization hints
1247412484
to enable otherwise unsafe floating-point optimizations. Fast-math-flags
12475-
are only valid for phis that return a floating-point scalar or vector type,
12476-
possibly within an array (nested to any depth), or a homogeneous struct literal.
12485+
are only valid for phis that return :ref:`supported floating-point types
12486+
<fastmath_return_types>`.
1247712487

1247812488
Semantics:
1247912489
""""""""""
@@ -12522,8 +12532,8 @@ class <t_firstclass>` type.
1252212532
#. The optional ``fast-math flags`` marker indicates that the select has one or more
1252312533
:ref:`fast-math flags <fastmath>`. These are optimization hints to enable
1252412534
otherwise unsafe floating-point optimizations. Fast-math flags are only valid
12525-
for selects that return a floating-point scalar or vector type, possibly
12526-
within an array (nested to any depth), or a homogeneous struct literal.
12535+
for selects that return :ref:`supported floating-point types
12536+
<fastmath_return_types>`..
1252712537

1252812538
Semantics:
1252912539
""""""""""
@@ -12761,8 +12771,7 @@ This instruction requires several arguments:
1276112771
#. The optional ``fast-math flags`` marker indicates that the call has one or more
1276212772
:ref:`fast-math flags <fastmath>`, which are optimization hints to enable
1276312773
otherwise unsafe floating-point optimizations. Fast-math flags are only valid
12764-
for calls that return a floating-point scalar or vector type, possibly within
12765-
an array (nested to any depth), or a homogeneous struct literal.
12774+
for calls that return :ref:`supported floating-point types <fastmath_return_types>`.
1276612775

1276712776
#. The optional "cconv" marker indicates which :ref:`calling
1276812777
convention <callingconv>` the call should use. If none is
@@ -20526,9 +20535,8 @@ the explicit vector length.
2052620535
#. The optional ``fast-math flags`` marker indicates that the select has one or
2052720536
more :ref:`fast-math flags <fastmath>`. These are optimization hints to
2052820537
enable otherwise unsafe floating-point optimizations. Fast-math flags are
20529-
only valid for selects that return a floating-point scalar or vector type,
20530-
possibly within an array (nested to any depth), or a homogeneous struct
20531-
literal.
20538+
only valid for selects that return :ref:`supported floating-point types
20539+
<fastmath_return_types>`.
2053220540

2053320541
Semantics:
2053420542
""""""""""
@@ -20585,9 +20593,8 @@ is the pivot.
2058520593
#. The optional ``fast-math flags`` marker indicates that the merge has one or
2058620594
more :ref:`fast-math flags <fastmath>`. These are optimization hints to
2058720595
enable otherwise unsafe floating-point optimizations. Fast-math flags are
20588-
only valid for merges that return a floating-point scalar or vector type,
20589-
possibly within an array (nested to any depth), or a homogeneous struct
20590-
literal.
20596+
only valid for merges that return :ref:`supported floating-point types
20597+
<fastmath_return_types>`.
2059120598

2059220599
Semantics:
2059320600
""""""""""

llvm/test/Bitcode/compatibility.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,21 +1123,21 @@ define void @fastMathFlagsForArrayCalls([2 x float] %f, [2 x double] %d1, [2 x <
11231123
}
11241124

11251125
declare { float, float } @fmf_struct_f32()
1126-
declare { double, double } @fmf_struct_f64()
1127-
declare { <4 x double>, <4 x double> } @fmf_struct_v4f64()
1126+
declare { double, double, double } @fmf_struct_f64()
1127+
declare { <4 x double> } @fmf_struct_v4f64()
11281128

11291129
; CHECK-LABEL: fastMathFlagsForStructCalls(
1130-
define void @fastMathFlagsForStructCalls({ float, float } %f, { double, double } %d1, { <4 x double>, <4 x double> } %d2) {
1130+
define void @fastMathFlagsForStructCalls() {
11311131
%call.fast = call fast { float, float } @fmf_struct_f32()
11321132
; CHECK: %call.fast = call fast { float, float } @fmf_struct_f32()
11331133

11341134
; Throw in some other attributes to make sure those stay in the right places.
11351135

1136-
%call.nsz.arcp = notail call nsz arcp { double, double } @fmf_struct_f64()
1137-
; CHECK: %call.nsz.arcp = notail call nsz arcp { double, double } @fmf_struct_f64()
1136+
%call.nsz.arcp = notail call nsz arcp { double, double, double } @fmf_struct_f64()
1137+
; CHECK: %call.nsz.arcp = notail call nsz arcp { double, double, double } @fmf_struct_f64()
11381138

1139-
%call.nnan.ninf = tail call nnan ninf fastcc { <4 x double>, <4 x double> } @fmf_struct_v4f64()
1140-
; CHECK: %call.nnan.ninf = tail call nnan ninf fastcc { <4 x double>, <4 x double> } @fmf_struct_v4f64()
1139+
%call.nnan.ninf = tail call nnan ninf fastcc { <4 x double> } @fmf_struct_v4f64()
1140+
; CHECK: %call.nnan.ninf = tail call nnan ninf fastcc { <4 x double> } @fmf_struct_v4f64()
11411141

11421142
ret void
11431143
}

llvm/unittests/IR/InstructionsTest.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,6 +1566,13 @@ TEST(InstructionsTest, FPCallIsFPMathOperator) {
15661566
CallInst::Create(StructIFnTy, StructICallee, {}, ""));
15671567
EXPECT_FALSE(isa<FPMathOperator>(StructICall));
15681568

1569+
Type *EmptyStructTy = StructType::get(C);
1570+
FunctionType *EmptyStructFnTy = FunctionType::get(EmptyStructTy, {});
1571+
Value *EmptyStructCallee = Constant::getNullValue(PtrTy);
1572+
std::unique_ptr<CallInst> EmptyStructCall(
1573+
CallInst::Create(EmptyStructFnTy, EmptyStructCallee, {}, ""));
1574+
EXPECT_FALSE(isa<FPMathOperator>(EmptyStructCall));
1575+
15691576
Type *NamedStructFTy = StructType::create({FTy, FTy}, "AStruct");
15701577
FunctionType *NamedStructFFnTy = FunctionType::get(NamedStructFTy, {});
15711578
Value *NamedStructFCallee = Constant::getNullValue(PtrTy);
@@ -1580,19 +1587,33 @@ TEST(InstructionsTest, FPCallIsFPMathOperator) {
15801587
CallInst::Create(MixedStructFnTy, MixedStructCallee, {}, ""));
15811588
EXPECT_FALSE(isa<FPMathOperator>(MixedStructCall));
15821589

1583-
Type *StructFTy = StructType::get(FTy, FTy);
1590+
Type *StructFTy = StructType::get(FTy, FTy, FTy);
15841591
FunctionType *StructFFnTy = FunctionType::get(StructFTy, {});
15851592
Value *StructFCallee = Constant::getNullValue(PtrTy);
15861593
std::unique_ptr<CallInst> StructFCall(
15871594
CallInst::Create(StructFFnTy, StructFCallee, {}, ""));
15881595
EXPECT_TRUE(isa<FPMathOperator>(StructFCall));
15891596

1590-
Type *StructVFTy = StructType::get(VFTy, VFTy);
1597+
Type *StructVFTy = StructType::get(VFTy, VFTy, VFTy, VFTy);
15911598
FunctionType *StructVFFnTy = FunctionType::get(StructVFTy, {});
15921599
Value *StructVFCallee = Constant::getNullValue(PtrTy);
15931600
std::unique_ptr<CallInst> StructVFCall(
15941601
CallInst::Create(StructVFFnTy, StructVFCallee, {}, ""));
15951602
EXPECT_TRUE(isa<FPMathOperator>(StructVFCall));
1603+
1604+
Type *NestedStructFTy = StructType::get(StructFTy, StructFTy, StructFTy);
1605+
FunctionType *NestedStructFFnTy = FunctionType::get(NestedStructFTy, {});
1606+
Value *NestedStructFCallee = Constant::getNullValue(PtrTy);
1607+
std::unique_ptr<CallInst> NestedStructFCall(
1608+
CallInst::Create(NestedStructFFnTy, NestedStructFCallee, {}, ""));
1609+
EXPECT_FALSE(isa<FPMathOperator>(NestedStructFCall));
1610+
1611+
Type *AStructFTy = ArrayType::get(StructFTy, 5);
1612+
FunctionType *AStructFFnTy = FunctionType::get(AStructFTy, {});
1613+
Value *AStructFCallee = Constant::getNullValue(PtrTy);
1614+
std::unique_ptr<CallInst> AStructFCall(
1615+
CallInst::Create(AStructFFnTy, AStructFCallee, {}, ""));
1616+
EXPECT_FALSE(isa<FPMathOperator>(AStructFCall));
15961617
}
15971618

15981619
TEST(InstructionsTest, FNegInstruction) {

0 commit comments

Comments
 (0)