[llvm] [Support] Move UndefPoisonKind enum to a shared header (PR #195523)

via llvm-commits llvm-commits at lists.llvm.org
Wed May 6 05:26:15 PDT 2026


https://github.com/levi42x updated https://github.com/llvm/llvm-project/pull/195523

>From 88ba93012ec9d1819d24a5ca8f2ab158a94efca1 Mon Sep 17 00:00:00 2001
From: shekhar suman <shekharsuman0397 at gmail.com>
Date: Sun, 3 May 2026 17:54:01 +0530
Subject: [PATCH] [Support] Move UndefPoisonKind enum to a shared header

---
 llvm/include/llvm/Support/UndefPoison.h | 40 +++++++++++++++++++++++++
 llvm/lib/Analysis/ValueTracking.cpp     | 15 +---------
 llvm/lib/CodeGen/GlobalISel/Utils.cpp   | 17 +----------
 3 files changed, 42 insertions(+), 30 deletions(-)
 create mode 100644 llvm/include/llvm/Support/UndefPoison.h

diff --git a/llvm/include/llvm/Support/UndefPoison.h b/llvm/include/llvm/Support/UndefPoison.h
new file mode 100644
index 0000000000000..ba554a64bfbfa
--- /dev/null
+++ b/llvm/include/llvm/Support/UndefPoison.h
@@ -0,0 +1,40 @@
+//===-- llvm/Support/UndefPoison.h - Undef/Poison tracking ------*- 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
+/// This file contains the UndefPoisonKind enum and helper functions.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_SUPPORT_UNDEFPOISON_H
+#define LLVM_SUPPORT_UNDEFPOISON_H
+
+namespace llvm {
+
+/// Enumeration to track whether we are interested in Undef, Poison, or both.
+enum class UndefPoisonKind {
+  PoisonOnly = (1 << 0),
+  UndefOnly = (1 << 1),
+  UndefOrPoison = PoisonOnly | UndefOnly,
+};
+
+/// Returns true if \p Kind includes the Poison bit.
+inline bool includesPoison(UndefPoisonKind Kind) {
+  return (static_cast<unsigned>(Kind) &
+          static_cast<unsigned>(UndefPoisonKind::PoisonOnly)) != 0;
+}
+
+/// Returns true if \p Kind includes the Undef bit.
+inline bool includesUndef(UndefPoisonKind Kind) {
+  return (static_cast<unsigned>(Kind) &
+          static_cast<unsigned>(UndefPoisonKind::UndefOnly)) != 0;
+}
+
+} // namespace llvm
+
+#endif // LLVM_SUPPORT_UNDEFPOISON_H
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 40f1025fed4fb..8f10bbae3d462 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -75,6 +75,7 @@
 #include "llvm/Support/KnownBits.h"
 #include "llvm/Support/KnownFPClass.h"
 #include "llvm/Support/MathExtras.h"
+#include "llvm/Support/UndefPoison.h"
 #include "llvm/TargetParser/RISCVTargetParser.h"
 #include <algorithm>
 #include <cassert>
@@ -7632,20 +7633,6 @@ static bool shiftAmountKnownInRange(const Value *ShiftAmount) {
   return Safe;
 }
 
-enum class UndefPoisonKind {
-  PoisonOnly = (1 << 0),
-  UndefOnly = (1 << 1),
-  UndefOrPoison = PoisonOnly | UndefOnly,
-};
-
-static bool includesPoison(UndefPoisonKind Kind) {
-  return (unsigned(Kind) & unsigned(UndefPoisonKind::PoisonOnly)) != 0;
-}
-
-static bool includesUndef(UndefPoisonKind Kind) {
-  return (unsigned(Kind) & unsigned(UndefPoisonKind::UndefOnly)) != 0;
-}
-
 static bool canCreateUndefOrPoison(const Operator *Op, UndefPoisonKind Kind,
                                    bool ConsiderFlagsAndMetadata) {
 
diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index 37af0716df9ec..f552fb7de45dd 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -33,6 +33,7 @@
 #include "llvm/CodeGen/TargetPassConfig.h"
 #include "llvm/CodeGen/TargetRegisterInfo.h"
 #include "llvm/IR/Constants.h"
+#include "llvm/Support/UndefPoison.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Transforms/Utils/SizeOpts.h"
 #include <numeric>
@@ -1787,22 +1788,6 @@ static bool shiftAmountKnownInRange(Register ShiftAmount,
   return true;
 }
 
-namespace {
-enum class UndefPoisonKind {
-  PoisonOnly = (1 << 0),
-  UndefOnly = (1 << 1),
-  UndefOrPoison = PoisonOnly | UndefOnly,
-};
-}
-
-static bool includesPoison(UndefPoisonKind Kind) {
-  return (unsigned(Kind) & unsigned(UndefPoisonKind::PoisonOnly)) != 0;
-}
-
-static bool includesUndef(UndefPoisonKind Kind) {
-  return (unsigned(Kind) & unsigned(UndefPoisonKind::UndefOnly)) != 0;
-}
-
 static bool canCreateUndefOrPoison(Register Reg, const MachineRegisterInfo &MRI,
                                    bool ConsiderFlagsAndMetadata,
                                    UndefPoisonKind Kind) {



More information about the llvm-commits mailing list