[llvm] [GISel] Add KnownFPClass Analysis to GISelValueTrackingPass (PR #134611)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 7 07:23:57 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,
----------------
arsenm wrote:

This is more duplication from the IR version than I would hope. Can we cut out the Value / Register part of the first field and share the rest? Or should this be templatized? 

https://github.com/llvm/llvm-project/pull/134611


More information about the llvm-commits mailing list