Skip to content

Commit

Permalink
[FPEnv] Remove unnecessary rounding mode argument for constrained int…
Browse files Browse the repository at this point in the history
…rinsics

The following intrinsics currently carry a rounding mode metadata argument:

    llvm.experimental.constrained.minnum
    llvm.experimental.constrained.maxnum
    llvm.experimental.constrained.ceil
    llvm.experimental.constrained.floor
    llvm.experimental.constrained.round
    llvm.experimental.constrained.trunc

This is not useful since the semantics of those intrinsics do not in any way
depend on the rounding mode. In similar cases, other constrained intrinsics
do not have the rounding mode argument. Remove it here as well.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D71218
  • Loading branch information
uweigand committed Dec 17, 2019
1 parent b6e7084 commit 1e89188
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 416 deletions.
36 changes: 18 additions & 18 deletions clang/test/CodeGen/constrained-math-builtins.c
Expand Up @@ -23,9 +23,9 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c) {

__builtin_ceil(f); __builtin_ceilf(f); __builtin_ceill(f);

// CHECK: declare double @llvm.experimental.constrained.ceil.f64(double, metadata, metadata)
// CHECK: declare float @llvm.experimental.constrained.ceil.f32(float, metadata, metadata)
// CHECK: declare x86_fp80 @llvm.experimental.constrained.ceil.f80(x86_fp80, metadata, metadata)
// CHECK: declare double @llvm.experimental.constrained.ceil.f64(double, metadata)
// CHECK: declare float @llvm.experimental.constrained.ceil.f32(float, metadata)
// CHECK: declare x86_fp80 @llvm.experimental.constrained.ceil.f80(x86_fp80, metadata)

__builtin_cos(f); __builtin_cosf(f); __builtin_cosl(f);

Expand All @@ -47,9 +47,9 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c) {

__builtin_floor(f); __builtin_floorf(f); __builtin_floorl(f);

// CHECK: declare double @llvm.experimental.constrained.floor.f64(double, metadata, metadata)
// CHECK: declare float @llvm.experimental.constrained.floor.f32(float, metadata, metadata)
// CHECK: declare x86_fp80 @llvm.experimental.constrained.floor.f80(x86_fp80, metadata, metadata)
// CHECK: declare double @llvm.experimental.constrained.floor.f64(double, metadata)
// CHECK: declare float @llvm.experimental.constrained.floor.f32(float, metadata)
// CHECK: declare x86_fp80 @llvm.experimental.constrained.floor.f80(x86_fp80, metadata)

__builtin_fma(f,f,f); __builtin_fmaf(f,f,f); __builtin_fmal(f,f,f);

Expand All @@ -59,15 +59,15 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c) {

__builtin_fmax(f,f); __builtin_fmaxf(f,f); __builtin_fmaxl(f,f);

// CHECK: declare double @llvm.experimental.constrained.maxnum.f64(double, double, metadata, metadata)
// CHECK: declare float @llvm.experimental.constrained.maxnum.f32(float, float, metadata, metadata)
// CHECK: declare x86_fp80 @llvm.experimental.constrained.maxnum.f80(x86_fp80, x86_fp80, metadata, metadata)
// CHECK: declare double @llvm.experimental.constrained.maxnum.f64(double, double, metadata)
// CHECK: declare float @llvm.experimental.constrained.maxnum.f32(float, float, metadata)
// CHECK: declare x86_fp80 @llvm.experimental.constrained.maxnum.f80(x86_fp80, x86_fp80, metadata)

__builtin_fmin(f,f); __builtin_fminf(f,f); __builtin_fminl(f,f);

// CHECK: declare double @llvm.experimental.constrained.minnum.f64(double, double, metadata, metadata)
// CHECK: declare float @llvm.experimental.constrained.minnum.f32(float, float, metadata, metadata)
// CHECK: declare x86_fp80 @llvm.experimental.constrained.minnum.f80(x86_fp80, x86_fp80, metadata, metadata)
// CHECK: declare double @llvm.experimental.constrained.minnum.f64(double, double, metadata)
// CHECK: declare float @llvm.experimental.constrained.minnum.f32(float, float, metadata)
// CHECK: declare x86_fp80 @llvm.experimental.constrained.minnum.f80(x86_fp80, x86_fp80, metadata)

__builtin_llrint(f); __builtin_llrintf(f); __builtin_llrintl(f);

Expand Down Expand Up @@ -125,9 +125,9 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c) {

__builtin_round(f); __builtin_roundf(f); __builtin_roundl(f);

// CHECK: declare double @llvm.experimental.constrained.round.f64(double, metadata, metadata)
// CHECK: declare float @llvm.experimental.constrained.round.f32(float, metadata, metadata)
// CHECK: declare x86_fp80 @llvm.experimental.constrained.round.f80(x86_fp80, metadata, metadata)
// CHECK: declare double @llvm.experimental.constrained.round.f64(double, metadata)
// CHECK: declare float @llvm.experimental.constrained.round.f32(float, metadata)
// CHECK: declare x86_fp80 @llvm.experimental.constrained.round.f80(x86_fp80, metadata)

__builtin_sin(f); __builtin_sinf(f); __builtin_sinl(f);

Expand All @@ -143,8 +143,8 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c) {

__builtin_trunc(f); __builtin_truncf(f); __builtin_truncl(f);

// CHECK: declare double @llvm.experimental.constrained.trunc.f64(double, metadata, metadata)
// CHECK: declare float @llvm.experimental.constrained.trunc.f32(float, metadata, metadata)
// CHECK: declare x86_fp80 @llvm.experimental.constrained.trunc.f80(x86_fp80, metadata, metadata)
// CHECK: declare double @llvm.experimental.constrained.trunc.f64(double, metadata)
// CHECK: declare float @llvm.experimental.constrained.trunc.f32(float, metadata)
// CHECK: declare x86_fp80 @llvm.experimental.constrained.trunc.f80(x86_fp80, metadata)
};

38 changes: 8 additions & 30 deletions llvm/docs/LangRef.rst
Expand Up @@ -16478,7 +16478,6 @@ Syntax:

declare <type>
@llvm.experimental.constrained.maxnum(<type> <op1>, <type> <op2>
metadata <rounding mode>,
metadata <exception behavior>)

Overview:
Expand All @@ -16493,16 +16492,12 @@ Arguments:
The first two arguments and the return value are floating-point numbers
of the same type.

The third and forth arguments specify the rounding mode and exception
behavior as described above.
The third argument specifies the exception behavior as described above.

Semantics:
""""""""""

This function follows the IEEE-754 semantics for maxNum. The rounding mode is
described, not determined, by the rounding mode argument. The actual rounding
mode is determined by the runtime floating-point environment. The rounding
mode argument is only intended as information to the compiler.
This function follows the IEEE-754 semantics for maxNum.


'``llvm.experimental.constrained.minnum``' Intrinsic
Expand All @@ -16515,7 +16510,6 @@ Syntax:

declare <type>
@llvm.experimental.constrained.minnum(<type> <op1>, <type> <op2>
metadata <rounding mode>,
metadata <exception behavior>)

Overview:
Expand All @@ -16530,16 +16524,12 @@ Arguments:
The first two arguments and the return value are floating-point numbers
of the same type.

The third and forth arguments specify the rounding mode and exception
behavior as described above.
The third argument specifies the exception behavior as described above.

Semantics:
""""""""""

This function follows the IEEE-754 semantics for minNum. The rounding mode is
described, not determined, by the rounding mode argument. The actual rounding
mode is determined by the runtime floating-point environment. The rounding
mode argument is only intended as information to the compiler.
This function follows the IEEE-754 semantics for minNum.


'``llvm.experimental.constrained.ceil``' Intrinsic
Expand All @@ -16552,7 +16542,6 @@ Syntax:

declare <type>
@llvm.experimental.constrained.ceil(<type> <op1>,
metadata <rounding mode>,
metadata <exception behavior>)

Overview:
Expand All @@ -16567,9 +16556,7 @@ Arguments:
The first argument and the return value are floating-point numbers of the same
type.

The second and third arguments specify the rounding mode and exception
behavior as described above. The rounding mode is currently unused for this
intrinsic.
The second argument specifies the exception behavior as described above.

Semantics:
""""""""""
Expand All @@ -16588,7 +16575,6 @@ Syntax:

declare <type>
@llvm.experimental.constrained.floor(<type> <op1>,
metadata <rounding mode>,
metadata <exception behavior>)

Overview:
Expand All @@ -16603,9 +16589,7 @@ Arguments:
The first argument and the return value are floating-point numbers of the same
type.

The second and third arguments specify the rounding mode and exception
behavior as described above. The rounding mode is currently unused for this
intrinsic.
The second argument specifies the exception behavior as described above.

Semantics:
""""""""""
Expand All @@ -16624,7 +16608,6 @@ Syntax:

declare <type>
@llvm.experimental.constrained.round(<type> <op1>,
metadata <rounding mode>,
metadata <exception behavior>)

Overview:
Expand All @@ -16639,9 +16622,7 @@ Arguments:
The first argument and the return value are floating-point numbers of the same
type.

The second and third arguments specify the rounding mode and exception
behavior as described above. The rounding mode is currently unused for this
intrinsic.
The second argument specifies the exception behavior as described above.

Semantics:
""""""""""
Expand Down Expand Up @@ -16736,7 +16717,6 @@ Syntax:

declare <type>
@llvm.experimental.constrained.trunc(<type> <op1>,
metadata <truncing mode>,
metadata <exception behavior>)

Overview:
Expand All @@ -16752,9 +16732,7 @@ Arguments:
The first argument and the return value are floating-point numbers of the same
type.

The second and third arguments specify the truncing mode and exception
behavior as described above. The truncing mode is currently unused for this
intrinsic.
The second argument specifies the exception behavior as described above.

Semantics:
""""""""""
Expand Down
12 changes: 6 additions & 6 deletions llvm/include/llvm/IR/ConstrainedOps.def
Expand Up @@ -55,11 +55,11 @@ CMP_INSTRUCTION(FCmp, 2, 0, experimental_constrained_fcmps, FSETCCS)
// Theses are definitions for intrinsic functions, that are converted into
// constrained intrinsics.
//
FUNCTION(ceil, 1, 1, experimental_constrained_ceil, FCEIL)
FUNCTION(ceil, 1, 0, experimental_constrained_ceil, FCEIL)
FUNCTION(cos, 1, 1, experimental_constrained_cos, FCOS)
FUNCTION(exp, 1, 1, experimental_constrained_exp, FEXP)
FUNCTION(exp2, 1, 1, experimental_constrained_exp2, FEXP2)
FUNCTION(floor, 1, 1, experimental_constrained_floor, FFLOOR)
FUNCTION(floor, 1, 0, experimental_constrained_floor, FFLOOR)
FUNCTION(fma, 3, 1, experimental_constrained_fma, FMA)
FUNCTION(log, 1, 1, experimental_constrained_log, FLOG)
FUNCTION(log10, 1, 1, experimental_constrained_log10, FLOG10)
Expand All @@ -68,16 +68,16 @@ FUNCTION(lrint, 1, 1, experimental_constrained_lrint, LRINT)
FUNCTION(llrint, 1, 1, experimental_constrained_llrint, LLRINT)
FUNCTION(lround, 1, 0, experimental_constrained_lround, LROUND)
FUNCTION(llround, 1, 0, experimental_constrained_llround, LLROUND)
FUNCTION(maxnum, 2, 1, experimental_constrained_maxnum, FMAXNUM)
FUNCTION(minnum, 2, 1, experimental_constrained_minnum, FMINNUM)
FUNCTION(maxnum, 2, 0, experimental_constrained_maxnum, FMAXNUM)
FUNCTION(minnum, 2, 0, experimental_constrained_minnum, FMINNUM)
FUNCTION(nearbyint, 1, 1, experimental_constrained_nearbyint, FNEARBYINT)
FUNCTION(pow, 2, 1, experimental_constrained_pow, FPOW)
FUNCTION(powi, 2, 1, experimental_constrained_powi, FPOWI)
FUNCTION(rint, 1, 1, experimental_constrained_rint, FRINT)
FUNCTION(round, 1, 1, experimental_constrained_round, FROUND)
FUNCTION(round, 1, 0, experimental_constrained_round, FROUND)
FUNCTION(sin, 1, 1, experimental_constrained_sin, FSIN)
FUNCTION(sqrt, 1, 1, experimental_constrained_sqrt, FSQRT)
FUNCTION(trunc, 1, 1, experimental_constrained_trunc, FTRUNC)
FUNCTION(trunc, 1, 0, experimental_constrained_trunc, FTRUNC)

#undef INSTRUCTION
#undef FUNCTION
Expand Down
35 changes: 19 additions & 16 deletions llvm/include/llvm/IR/IRBuilder.h
Expand Up @@ -2171,21 +2171,24 @@ class IRBuilder : public IRBuilderBase, public Inserter {
UseFMF = FMFSource->getFastMathFlags();

CallInst *C;
bool HasRoundingMD = false;
switch (ID) {
default: {
default:
break;
#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
case Intrinsic::INTRINSIC: \
HasRoundingMD = ROUND_MODE; \
break;
#include "llvm/IR/ConstrainedOps.def"
}
if (HasRoundingMD) {
Value *RoundingV = getConstrainedFPRounding(Rounding);
C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, RoundingV, ExceptV},
nullptr, Name);
} break;
case Intrinsic::experimental_constrained_fpext:
case Intrinsic::experimental_constrained_fptoui:
case Intrinsic::experimental_constrained_fptosi:
case Intrinsic::experimental_constrained_lround:
case Intrinsic::experimental_constrained_llround:
} else
C = CreateIntrinsic(ID, {DestTy, V->getType()}, {V, ExceptV}, nullptr,
Name);
break;
}

setConstrainedFPCallAttr(C);

if (isa<FPMathOperator>(C))
Expand Down Expand Up @@ -2402,18 +2405,18 @@ class IRBuilder : public IRBuilderBase, public Inserter {
for (auto *OneArg : Args)
UseArgs.push_back(OneArg);
Function *F = cast<Function>(Callee);
bool HasRoundingMD = false;
switch (F->getIntrinsicID()) {
default:
UseArgs.push_back(getConstrainedFPRounding(Rounding));
break;
case Intrinsic::experimental_constrained_fpext:
case Intrinsic::experimental_constrained_fptoui:
case Intrinsic::experimental_constrained_fptosi:
case Intrinsic::experimental_constrained_lround:
case Intrinsic::experimental_constrained_llround:
// No rounding metadata for these intrinsics.
#define INSTRUCTION(NAME, NARG, ROUND_MODE, INTRINSIC, DAGN) \
case Intrinsic::INTRINSIC: \
HasRoundingMD = ROUND_MODE; \
break;
#include "llvm/IR/ConstrainedOps.def"
}
if (HasRoundingMD)
UseArgs.push_back(getConstrainedFPRounding(Rounding));
UseArgs.push_back(getConstrainedFPExcept(Except));

CallInst *C = CreateCall(
Expand Down
6 changes: 0 additions & 6 deletions llvm/include/llvm/IR/Intrinsics.td
Expand Up @@ -724,20 +724,16 @@ let IntrProperties = [IntrInaccessibleMemOnly, IntrWillReturn] in {
def int_experimental_constrained_maxnum : Intrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_minnum : Intrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_ceil : Intrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_floor : Intrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_lround : Intrinsic<[ llvm_anyint_ty ],
[ llvm_anyfloat_ty,
Expand All @@ -747,11 +743,9 @@ let IntrProperties = [IntrInaccessibleMemOnly, IntrWillReturn] in {
llvm_metadata_ty ]>;
def int_experimental_constrained_round : Intrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;
def int_experimental_constrained_trunc : Intrinsic<[ llvm_anyfloat_ty ],
[ LLVMMatchType<0>,
llvm_metadata_ty,
llvm_metadata_ty ]>;

// Constrained floating-point comparison (quiet and signaling variants).
Expand Down

0 comments on commit 1e89188

Please sign in to comment.