diff options
author | Tim Gymnich <tim@gymni.ch> | 2025-05-21 23:45:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-21 23:45:31 +0200 |
commit | d00d74bb2564103ae3cb5ac6b6ffecf7e1cc2238 (patch) | |
tree | d21fb1c557c8ad633a3ee436572f0933c349dced /llvm/lib/CodeGen/MachineFloatingPointPredicateUtils.cpp | |
parent | b499f7f2b246c284f8deb428f68d0b488b80c630 (diff) | |
download | llvm-d00d74bb2564103ae3cb5ac6b6ffecf7e1cc2238.zip llvm-d00d74bb2564103ae3cb5ac6b6ffecf7e1cc2238.tar.gz llvm-d00d74bb2564103ae3cb5ac6b6ffecf7e1cc2238.tar.bz2 |
[llvm] add GenericFloatingPointPredicateUtils (#140254)
add `GenericFloatingPointPredicateUtils` in order to generalize
effects of floating point comparisons on `KnownFPClass` for both IR and
MIR.
---------
Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
Diffstat (limited to 'llvm/lib/CodeGen/MachineFloatingPointPredicateUtils.cpp')
-rw-r--r-- | llvm/lib/CodeGen/MachineFloatingPointPredicateUtils.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/MachineFloatingPointPredicateUtils.cpp b/llvm/lib/CodeGen/MachineFloatingPointPredicateUtils.cpp new file mode 100644 index 0000000..3f640de --- /dev/null +++ b/llvm/lib/CodeGen/MachineFloatingPointPredicateUtils.cpp @@ -0,0 +1,48 @@ +//===- MachineFloatingPointPredicateUtils.cpp -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "llvm/CodeGen/MachineFloatingPointPredicateUtils.h" +#include "llvm/CodeGen/GlobalISel/MIPatternMatch.h" +#include "llvm/CodeGen/LowLevelTypeUtils.h" +#include "llvm/CodeGen/MachineRegisterInfo.h" +#include "llvm/CodeGen/MachineSSAContext.h" +#include "llvm/IR/Constants.h" +#include <optional> + +namespace llvm { + +using namespace MIPatternMatch; + +template <> +DenormalMode +MachineFloatingPointPredicateUtils::queryDenormalMode(const MachineFunction &MF, + Register Val) { + const MachineRegisterInfo &MRI = MF.getRegInfo(); + LLT Ty = MRI.getType(Val).getScalarType(); + return MF.getDenormalMode(getFltSemanticForLLT(Ty)); +} + +template <> +bool MachineFloatingPointPredicateUtils::lookThroughFAbs( + const MachineFunction &MF, Register LHS, Register &Src) { + const MachineRegisterInfo &MRI = MF.getRegInfo(); + return mi_match(LHS, MRI, m_GFabs(m_Reg(Src))); +} + +template <> +std::optional<APFloat> MachineFloatingPointPredicateUtils::matchConstantFloat( + const MachineFunction &MF, Register Val) { + const MachineRegisterInfo &MRI = MF.getRegInfo(); + const ConstantFP *ConstVal; + if (mi_match(Val, MRI, m_GFCst(ConstVal))) + return ConstVal->getValueAPF(); + + return std::nullopt; +} + +} // namespace llvm |