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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu May 8 03:05:23 PDT 2025


================
@@ -0,0 +1,434 @@
+//===- llvm/Support/FloatingPointModeUtils.h -----*- C++ -*----------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Utilities for dealing with flags related to floating point properties and
+/// mode controls.
+///
+//===----------------------------------------------------------------------===/
+
+#ifndef LLVM_ADT_FLOATINGPOINTMODEUTILS_H
+#define LLVM_ADT_FLOATINGPOINTMODEUTILS_H
+
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/FloatingPointMode.h"
+#include "llvm/IR/Instructions.h"
+#include <type_traits>
+
+namespace llvm {
+
+/// Return the return value for fcmpImpliesClass for a compare that produces an
+/// exact class test.
+template <typename ValueTy>
+static std::tuple<ValueTy, FPClassTest, FPClassTest> exactClass(ValueTy V,
+                                                                FPClassTest M) {
+  return {V, M, ~M};
+}
+
+/// Compute the possible floating-point classes that \p LHS could be based on
+/// fcmp \Pred \p LHS, \p RHS.
+///
+/// \returns { TestedValue, ClassesIfTrue, ClassesIfFalse }
+///
+/// If the compare returns an exact class test, ClassesIfTrue == ~ClassesIfFalse
+///
+/// This is a less exact version of fcmpToClassTest (e.g. fcmpToClassTest will
+/// only succeed for a test of x > 0 implies positive, but not x > 1).
+///
+/// If \p LookThroughSrc is true, consider the input value when computing the
+/// mask. This may look through sign bit operations.
+///
+/// If \p LookThroughSrc is false, ignore the source value (i.e. the first pair
+/// element will always be LHS.
+///
+template <typename ValueTy, typename LookThroughFnTy>
+std::tuple<ValueTy, FPClassTest, FPClassTest>
+fcmpImpliesClass(CmpInst::Predicate Pred, DenormalMode Mode, ValueTy LHS,
+                 FPClassTest RHSClass, LookThroughFnTy LookThroughFn) {
+  assert(RHSClass != fcNone);
+
+  ValueTy Invalid;
+  if constexpr (std::is_pointer_v<ValueTy>) {
+    Invalid = nullptr;
+  } else {
+    Invalid = ValueTy();
+  }
----------------
arsenm wrote:

```suggestion
  const ValueTy Invalid = {};
```

Then you can probably drop the type_traits include? 

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


More information about the llvm-commits mailing list