LLVM 22.0.0git
KnownFPClass.cpp
Go to the documentation of this file.
1//===- llvm/Support/KnownFPClass.h - Stores known fplcass -------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file contains a class for representing known fpclasses used by
10// computeKnownFPClass.
11//
12//===----------------------------------------------------------------------===//
13
16
17using namespace llvm;
18
19/// Return true if it's possible to assume IEEE treatment of input denormals in
20/// \p F for \p Val.
22 return Mode.Input == DenormalMode::IEEE;
23}
24
26 return Mode.Input == DenormalMode::IEEE ||
27 Mode.Input == DenormalMode::PositiveZero;
28}
29
31 return isKnownNeverZero() &&
33}
34
36 return isKnownNeverNegZero() &&
38}
39
42 return false;
43
44 // If we know there are no denormals, nothing can be flushed to zero.
46 return true;
47
48 switch (Mode.Input) {
50 return true;
52 // Negative subnormal won't flush to +0
55 default:
56 // Both positive and negative subnormal could flush to +0
57 return false;
58 }
59
60 llvm_unreachable("covered switch over denormal mode");
61}
62
64 DenormalMode Mode) {
65 KnownFPClasses = Src.KnownFPClasses;
66 // If we aren't assuming the source can't be a zero, we don't have to check if
67 // a denormal input could be flushed.
68 if (!Src.isKnownNeverPosZero() && !Src.isKnownNeverNegZero())
69 return;
70
71 // If we know the input can't be a denormal, it can't be flushed to 0.
72 if (Src.isKnownNeverSubnormal())
73 return;
74
75 if (!Src.isKnownNeverPosSubnormal() && Mode != DenormalMode::getIEEE())
77
78 if (!Src.isKnownNeverNegSubnormal() && Mode != DenormalMode::getIEEE()) {
81
82 if (Mode.Input == DenormalMode::PositiveZero ||
83 Mode.Output == DenormalMode::PositiveZero ||
84 Mode.Input == DenormalMode::Dynamic ||
85 Mode.Output == DenormalMode::Dynamic)
87 }
88}
89
91 DenormalMode Mode) {
92 propagateDenormal(Src, Mode);
93 propagateNaN(Src, /*PreserveSign=*/true);
94}
static bool inputDenormalIsIEEE(DenormalMode Mode)
Return true if it's possible to assume IEEE treatment of input denormals in F for Val.
static bool inputDenormalIsIEEEOrPosZero(DenormalMode Mode)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
Represent subnormal handling kind for floating point instruction inputs and outputs.
@ PreserveSign
The sign of a flushed-to-zero number is preserved in the sign of 0.
@ PositiveZero
Denormals are flushed to positive zero.
@ Dynamic
Denormals have unknown treatment.
@ IEEE
IEEE-754 denormal numbers preserved.
static constexpr DenormalMode getPositiveZero()
static constexpr DenormalMode getIEEE()
FPClassTest KnownFPClasses
Floating-point classes the value could be one of.
Definition: KnownFPClass.h:25
bool isKnownNeverZero() const
Return true if it's known this can never be a zero.
Definition: KnownFPClass.h:70
bool isKnownNeverSubnormal() const
Return true if it's known this can never be a subnormal.
Definition: KnownFPClass.h:60
LLVM_ABI bool isKnownNeverLogicalZero(DenormalMode Mode) const
Return true if it's know this can never be interpreted as a zero.
LLVM_ABI void propagateDenormal(const KnownFPClass &Src, DenormalMode Mode)
Propagate knowledge from a source value that could be a denormal or zero.
bool isKnownNeverNegSubnormal() const
Return true if it's known this can never be a negative subnormal.
Definition: KnownFPClass.h:66
bool isKnownNeverPosZero() const
Return true if it's known this can never be a literal positive zero.
Definition: KnownFPClass.h:73
bool isKnownNeverNegZero() const
Return true if it's known this can never be a negative zero.
Definition: KnownFPClass.h:77
void propagateNaN(const KnownFPClass &Src, bool PreserveSign=false)
Definition: KnownFPClass.h:198
LLVM_ABI void propagateCanonicalizingSrc(const KnownFPClass &Src, DenormalMode Mode)
Report known classes if Src is evaluated through a potentially canonicalizing operation.
LLVM_ABI bool isKnownNeverLogicalPosZero(DenormalMode Mode) const
Return true if it's know this can never be interpreted as a positive zero.
LLVM_ABI bool isKnownNeverLogicalNegZero(DenormalMode Mode) const
Return true if it's know this can never be interpreted as a negative zero.
bool isKnownNeverPosSubnormal() const
Return true if it's known this can never be a positive subnormal.
Definition: KnownFPClass.h:63