[llvm] [SelectionDAG] Add function for `peekThroughFreeze` (PR #195324)
Henry Jiang via llvm-commits
llvm-commits at lists.llvm.org
Fri May 1 11:51:14 PDT 2026
https://github.com/mustartt updated https://github.com/llvm/llvm-project/pull/195324
>From 1177f18344bcff86e01c4d1315a5b12c9335780a Mon Sep 17 00:00:00 2001
From: Henry Jiang <henry_jiang2 at apple.com>
Date: Fri, 1 May 2026 11:42:09 -0700
Subject: [PATCH] Introduce peekThroughFreeze
---
llvm/include/llvm/CodeGen/SelectionDAGNodes.h | 8 ++++++++
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 12 ++++++++++++
2 files changed, 20 insertions(+)
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
index 2d5e92381ef64..4f17dcc63f9d0 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -1977,6 +1977,14 @@ LLVM_ABI SDValue peekThroughInsertVectorElt(SDValue V,
/// If \p V is not a truncation, it is returned as-is.
LLVM_ABI SDValue peekThroughTruncates(SDValue V);
+/// Return the non-frozen source operand of \p V if it exists.
+/// If \p V is not a freeze, it is returned as-is.
+LLVM_ABI SDValue peekThroughFreeze(SDValue V);
+
+/// Return the non-frozen source operand of \p V if it exists and \p V has
+/// a single use. If \p V is not a single-use freeze, it is returned as-is.
+LLVM_ABI SDValue peekThroughOneUseFreeze(SDValue V);
+
/// Returns true if \p V is a bitwise not operation. Assumes that an all ones
/// constant is canonicalized to be operand 1.
LLVM_ABI bool isBitwiseNot(SDValue V, bool AllowUndefs = false);
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index f91f0bb63cebc..d26c792269307 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -13604,6 +13604,18 @@ SDValue llvm::peekThroughTruncates(SDValue V) {
return V;
}
+SDValue llvm::peekThroughFreeze(SDValue V) {
+ if (V.getOpcode() == ISD::FREEZE)
+ return V.getOperand(0);
+ return V;
+}
+
+SDValue llvm::peekThroughOneUseFreeze(SDValue V) {
+ if (V.getOpcode() == ISD::FREEZE && V.hasOneUse())
+ return V.getOperand(0);
+ return V;
+}
+
bool llvm::isBitwiseNot(SDValue V, bool AllowUndefs) {
if (V.getOpcode() != ISD::XOR)
return false;
More information about the llvm-commits
mailing list