[llvm] [GISel] Add KnownFPClass Analysis to GISelValueTrackingPass (PR #134611)
Tim Gymnich via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 7 08:36:21 PDT 2025
================
@@ -631,12 +655,1448 @@ void GISelValueTracking::computeKnownBitsImpl(Register R, KnownBits &Known,
}
}
- LLVM_DEBUG(dumpResult(MI, Known, Depth));
+ LLVM_DEBUG(dumpKnownBitsResult(MI, Known, Depth));
// Update the cache.
ComputeKnownBitsCache[R] = Known;
}
+/// Return true if it's possible to assume IEEE treatment of input denormals in
+/// \p MF for \p Ty.
+static bool inputDenormalIsIEEE(const MachineFunction &MF, LLT Ty) {
+ Ty = Ty.getScalarType();
+ return MF.getDenormalMode(getFltSemanticForLLT(Ty)).Input ==
+ DenormalMode::IEEE;
+}
+
+static bool outputDenormalIsIEEEOrPosZero(const MachineFunction &MF, LLT Ty) {
+ Ty = Ty.getScalarType();
+ DenormalMode Mode = MF.getDenormalMode(getFltSemanticForLLT(Ty));
+ return Mode.Output == DenormalMode::IEEE ||
+ Mode.Output == DenormalMode::PositiveZero;
+}
+
+std::pair<Register, FPClassTest> GISelValueTracking::fcmpToClassTest(
+ FCmpInst::Predicate Pred, const MachineFunction &MF, Register LHS,
+ const APFloat *ConstRHS, bool LookThroughSrc) {
+
+ auto [Src, ClassIfTrue, ClassIfFalse] =
+ fcmpImpliesClass(Pred, MF, LHS, *ConstRHS, LookThroughSrc);
+ if (Src && ClassIfTrue == ~ClassIfFalse)
+ return {Src, ClassIfTrue};
+
+ return {Register(), fcAllFlags};
+}
+
+/// Return the return value for fcmpImpliesClass for a compare that produces an
+/// exact class test.
+static std::tuple<Register, FPClassTest, FPClassTest>
+exactClass(Register V, FPClassTest M) {
+ return {V, M, ~M};
+}
+
+std::tuple<Register, FPClassTest, FPClassTest>
+GISelValueTracking::fcmpImpliesClass(CmpInst::Predicate Pred,
----------------
tgymnich wrote:
Here is my attempt of templating this: https://github.com/tgymnich/llvm-project/blob/tim/gisel-value-tracking/llvm/include/llvm/ADT/FloatingPointModeUtils.h
In the end I wasn't quite happy with how I handled the LookThrough.
- Just passing a lambda is not extensible enoguh imo. => e.g. what happens if we want to look through to more than just fabs.
- `if constexpr` is also not to nice since we'd need to inlcude all the MIR and IR headers.
https://github.com/llvm/llvm-project/pull/134611
More information about the llvm-commits
mailing list