Skip to content

Commit 15b8f8e

Browse files
committed
[GlobalISel] Add computeFPClass to GlobaISelValueTracking
1 parent 2c10723 commit 15b8f8e

File tree

8 files changed

+1856
-4
lines changed

8 files changed

+1856
-4
lines changed

llvm/include/llvm/CodeGen/GlobalISel/GISelValueTracking.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
#ifndef LLVM_CODEGEN_GLOBALISEL_GISELVALUETRACKING_H
1515
#define LLVM_CODEGEN_GLOBALISEL_GISELVALUETRACKING_H
1616

17+
#include "llvm/ADT/APFloat.h"
1718
#include "llvm/ADT/DenseMap.h"
1819
#include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
1920
#include "llvm/CodeGen/MachineFunctionPass.h"
2021
#include "llvm/CodeGen/Register.h"
22+
#include "llvm/IR/InstrTypes.h"
2123
#include "llvm/InitializePasses.h"
2224
#include "llvm/Support/KnownBits.h"
25+
#include "llvm/Support/KnownFPClass.h"
2326

2427
namespace llvm {
2528

@@ -41,6 +44,64 @@ class GISelValueTracking : public GISelChangeObserver {
4144
unsigned computeNumSignBitsMin(Register Src0, Register Src1,
4245
const APInt &DemandedElts, unsigned Depth = 0);
4346

47+
/// Returns a pair of values, which if passed to llvm.is.fpclass, returns the
48+
/// same result as an fcmp with the given operands.
49+
///
50+
/// If \p LookThroughSrc is true, consider the input value when computing the
51+
/// mask.
52+
///
53+
/// If \p LookThroughSrc is false, ignore the source value (i.e. the first
54+
/// pair element will always be LHS.
55+
std::pair<Register, FPClassTest> fcmpToClassTest(CmpInst::Predicate Pred,
56+
const MachineFunction &MF,
57+
Register LHS, Value *RHS,
58+
bool LookThroughSrc = true);
59+
std::pair<Register, FPClassTest> fcmpToClassTest(CmpInst::Predicate Pred,
60+
const MachineFunction &MF,
61+
Register LHS,
62+
const APFloat *ConstRHS,
63+
bool LookThroughSrc = true);
64+
65+
/// Compute the possible floating-point classes that \p LHS could be based on
66+
/// fcmp \Pred \p LHS, \p RHS.
67+
///
68+
/// \returns { TestedValue, ClassesIfTrue, ClassesIfFalse }
69+
///
70+
/// If the compare returns an exact class test, ClassesIfTrue ==
71+
/// ~ClassesIfFalse
72+
///
73+
/// This is a less exact version of fcmpToClassTest (e.g. fcmpToClassTest will
74+
/// only succeed for a test of x > 0 implies positive, but not x > 1).
75+
///
76+
/// If \p LookThroughSrc is true, consider the input value when computing the
77+
/// mask. This may look through sign bit operations.
78+
///
79+
/// If \p LookThroughSrc is false, ignore the source value (i.e. the first
80+
/// pair element will always be LHS.
81+
///
82+
std::tuple<Register, FPClassTest, FPClassTest>
83+
fcmpImpliesClass(CmpInst::Predicate Pred, const MachineFunction &MF,
84+
Register LHS, Register RHS, bool LookThroughSrc = true);
85+
std::tuple<Register, FPClassTest, FPClassTest>
86+
fcmpImpliesClass(CmpInst::Predicate Pred, const MachineFunction &MF,
87+
Register LHS, FPClassTest RHS, bool LookThroughSrc = true);
88+
std::tuple<Register, FPClassTest, FPClassTest>
89+
fcmpImpliesClass(CmpInst::Predicate Pred, const MachineFunction &MF,
90+
Register LHS, const APFloat &RHS,
91+
bool LookThroughSrc = true);
92+
93+
void computeKnownFPClass(Register R, KnownFPClass &Known,
94+
FPClassTest InterestedClasses, unsigned Depth);
95+
96+
void computeKnownFPClassForFPTrunc(const MachineInstr &MI,
97+
const APInt &DemandedElts,
98+
FPClassTest InterestedClasses,
99+
KnownFPClass &Known, unsigned Depth);
100+
101+
void computeKnownFPClass(Register R, const APInt &DemandedElts,
102+
FPClassTest InterestedClasses, KnownFPClass &Known,
103+
unsigned Depth);
104+
44105
public:
45106
GISelValueTracking(MachineFunction &MF, unsigned MaxDepth = 6);
46107
virtual ~GISelValueTracking() = default;
@@ -86,6 +147,34 @@ class GISelValueTracking : public GISelChangeObserver {
86147
/// \return The known alignment for the pointer-like value \p R.
87148
Align computeKnownAlignment(Register R, unsigned Depth = 0);
88149

150+
/// Determine which floating-point classes are valid for \p V, and return them
151+
/// in KnownFPClass bit sets.
152+
///
153+
/// This function is defined on values with floating-point type, values
154+
/// vectors of floating-point type, and arrays of floating-point type.
155+
156+
/// \p InterestedClasses is a compile time optimization hint for which
157+
/// floating point classes should be queried. Queries not specified in \p
158+
/// InterestedClasses should be reliable if they are determined during the
159+
/// query.
160+
KnownFPClass computeKnownFPClass(Register R, const APInt &DemandedElts,
161+
FPClassTest InterestedClasses,
162+
unsigned Depth);
163+
164+
KnownFPClass computeKnownFPClass(Register R,
165+
FPClassTest InterestedClasses = fcAllFlags,
166+
unsigned Depth = 0);
167+
168+
/// Wrapper to account for known fast math flags at the use instruction.
169+
KnownFPClass computeKnownFPClass(Register R, const APInt &DemandedElts,
170+
uint32_t Flags,
171+
FPClassTest InterestedClasses,
172+
unsigned Depth);
173+
174+
KnownFPClass computeKnownFPClass(Register R, uint32_t Flags,
175+
FPClassTest InterestedClasses,
176+
unsigned Depth);
177+
89178
// Observer API. No-op for non-caching implementation.
90179
void erasingInstr(MachineInstr &MI) override {}
91180
void createdInstr(MachineInstr &MI) override {}

0 commit comments

Comments
 (0)