[llvm] Introducing a new ISD::POISON SDNode to represent the poison value in the IR. (PR #125883)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 4 12:14:41 PDT 2025


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- llvm/include/llvm/CodeGen/ISDOpcodes.h llvm/include/llvm/CodeGen/SelectionDAG.h llvm/include/llvm/CodeGen/SelectionDAGNodes.h llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
index c4b649b03..60d9465cc 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -699,9 +699,7 @@ public:
   }
 
   /// Returns true if the node type is POISON.
-  bool isPoison() const {
-    return NodeType == ISD::POISON;
-  }
+  bool isPoison() const { return NodeType == ISD::POISON; }
 
   /// Test if this node is a memory intrinsic (with valid pointer information).
   bool isMemIntrinsic() const { return SDNodeBits.IsMemIntrinsic; }
@@ -1276,9 +1274,7 @@ inline bool SDValue::isUndef() const {
   return Node->isUndef();
 }
 
-inline bool SDValue::isPoison() const {
-  return Node->isPoison();
-}
+inline bool SDValue::isPoison() const { return Node->isPoison(); }
 
 inline bool SDValue::use_empty() const {
   return !Node->hasAnyUseOfValue(ResNo);
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 83e200d5f..24ba5207d 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -7586,13 +7586,14 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
     }
   }
 
-  // TODO: According to https://llvm.org/docs/UndefinedBehavior.html#poison-values,
-  // most instructions return poison if any of their inputs are poison.
-  // A notable exception is the select instruction, which is poison if and only if
-  // the condition is poison or the selected value is poison.
-
-  // Currently, we only handle the case where the opcode is ISD::ADD and the second input is poison.
-  // Other cases will be handled in a future patch.
+  // TODO: According to
+  // https://llvm.org/docs/UndefinedBehavior.html#poison-values, most
+  // instructions return poison if any of their inputs are poison. A notable
+  // exception is the select instruction, which is poison if and only if the
+  // condition is poison or the selected value is poison.
+
+  // Currently, we only handle the case where the opcode is ISD::ADD and the
+  // second input is poison. Other cases will be handled in a future patch.
   if (N2.isPoison()) {
     switch (Opcode) {
     case ISD::ADD:

``````````

</details>


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


More information about the llvm-commits mailing list