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

via llvm-commits llvm-commits at lists.llvm.org
Tue May 5 10:34:51 PDT 2026


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

>From 489ce550b1556229bf79744bb0835d26f3a4ff68 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/Analysis/ValueTracking.h |  1 +
 llvm/include/llvm/Support/UndefPoison.h    | 40 ++++++++++++++++++++++
 llvm/lib/Analysis/ValueTracking.cpp        | 14 --------
 llvm/lib/CodeGen/GlobalISel/Utils.cpp      | 17 +--------
 4 files changed, 42 insertions(+), 30 deletions(-)
 create mode 100644 llvm/include/llvm/Support/UndefPoison.h

diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h
index ff2712efe1ef5..f2e129db1632e 100644
--- a/llvm/include/llvm/Analysis/ValueTracking.h
+++ b/llvm/include/llvm/Analysis/ValueTracking.h
@@ -23,6 +23,7 @@
 #include "llvm/IR/Instructions.h"
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/Support/Compiler.h"
+#include "llvm/Support/UndefPoison.h"
 #include <cassert>
 #include <cstdint>
 
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..19c0b93f82df7 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -7632,20 +7632,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