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

zhijian lin via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 27 08:19:35 PST 2025


================
@@ -977,6 +977,11 @@ void SelectionDAGLegalize::LegalizeOp(SDNode *Node) {
   TargetLowering::LegalizeAction Action = TargetLowering::Legal;
   bool SimpleFinishLegalizing = true;
   switch (Node->getOpcode()) {
+  case ISD::POISON: {
+    SDValue UndefNode = DAG.getUNDEF(Node->getValueType(0));
+    ReplaceNode(Node, UndefNode.getNode());
+    break;
+  }
----------------
diggerlin wrote:

yes, I think so,

for example ,in the function `void DAGTypeLegalizer::WidenVectorResult(SDNode *N, unsigned ResNo) ` 
if  we do not replace POISON with UNDEF in the legal type. we need to implement a new function ``DAGTypeLegalizer::WidenVecRes_POISON(SDNode *N)` like `DAGTypeLegalizer::WidenVecRes_UNDEF(SDNode *N)`

and we have to have the code 

```
SDValue DAGTypeLegalizer::WidenVecRes_POISON(SDNode *N) {
 EVT WidenVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
 return DAG.getPOISON(WidenVT);
}


void DAGTypeLegalizer::WidenVectorResult(SDNode *N, unsigned ResNo)  {
 ....
   case ISD::UNDEF:             Res = WidenVecRes_UNDEF(N); break;
   case ISD::POISON:             Res = WidenVecRes_POISON(N); break;
....
}

```

since we can replace the POISON value with UNDEF at any time.

So I think  the following code is more reasonable.
```
void DAGTypeLegalizer::WidenVectorResult(SDNode *N, unsigned ResNo)  {
...
case ISD::POISON:
case ISD::UNDEF:             Res = WidenVecRes_UNDEF(N); break;
...
}
```


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


More information about the llvm-commits mailing list