@@ -5458,6 +5458,9 @@ bool SelectionDAG::isGuaranteedNotToBeUndefOrPoison(SDValue Op,
54585458 case ISD::CopyFromReg:
54595459 return true;
54605460
5461+ case ISD::POISON:
5462+ return false;
5463+
54615464 case ISD::UNDEF:
54625465 return PoisonOnly;
54635466
@@ -6310,6 +6313,10 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
63106313 if (OpOpcode == ISD::UNDEF)
63116314 // sext(undef) = 0, because the top bits will all be the same.
63126315 return getConstant(0, DL, VT);
6316+
6317+ if (OpOpcode == ISD::POISON)
6318+ return getPoison(VT);
6319+
63136320 break;
63146321 case ISD::ZERO_EXTEND:
63156322 assert(VT.isInteger() && N1.getValueType().isInteger() &&
@@ -6331,6 +6338,9 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
63316338 // zext(undef) = 0, because the top bits will be zero.
63326339 return getConstant(0, DL, VT);
63336340
6341+ if (OpOpcode == ISD::POISON)
6342+ return getPoison(VT);
6343+
63346344 // Skip unnecessary zext_inreg pattern:
63356345 // (zext (trunc x)) -> x iff the upper bits are known zero.
63366346 // TODO: Remove (zext (trunc (and x, c))) exception which some targets
@@ -6371,6 +6381,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
63716381 }
63726382 if (OpOpcode == ISD::UNDEF)
63736383 return getUNDEF(VT);
6384+ if (OpOpcode == ISD::POISON)
6385+ return getPoison(VT);
63746386
63756387 // (ext (trunc x)) -> x
63766388 if (OpOpcode == ISD::TRUNCATE) {
@@ -6406,6 +6418,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
64066418 }
64076419 if (OpOpcode == ISD::UNDEF)
64086420 return getUNDEF(VT);
6421+ if (OpOpcode == ISD::POISON)
6422+ return getPoison(VT);
64096423 if (OpOpcode == ISD::VSCALE && !NewNodesMustHaveLegalTypes)
64106424 return getVScale(DL, VT,
64116425 N1.getConstantOperandAPInt(0).trunc(VT.getSizeInBits()));
@@ -6424,13 +6438,17 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
64246438 assert(VT.isInteger() && VT == N1.getValueType() && "Invalid ABS!");
64256439 if (OpOpcode == ISD::UNDEF)
64266440 return getConstant(0, DL, VT);
6441+ if (OpOpcode == ISD::POISON)
6442+ return getPoison(VT);
64276443 break;
64286444 case ISD::BSWAP:
64296445 assert(VT.isInteger() && VT == N1.getValueType() && "Invalid BSWAP!");
64306446 assert((VT.getScalarSizeInBits() % 16 == 0) &&
64316447 "BSWAP types must be a multiple of 16 bits!");
64326448 if (OpOpcode == ISD::UNDEF)
64336449 return getUNDEF(VT);
6450+ if (OpOpcode == ISD::POISON)
6451+ return getPoison(VT);
64346452 // bswap(bswap(X)) -> X.
64356453 if (OpOpcode == ISD::BSWAP)
64366454 return N1.getOperand(0);
@@ -6439,6 +6457,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
64396457 assert(VT.isInteger() && VT == N1.getValueType() && "Invalid BITREVERSE!");
64406458 if (OpOpcode == ISD::UNDEF)
64416459 return getUNDEF(VT);
6460+ if (OpOpcode == ISD::POISON)
6461+ return getPoison(VT);
64426462 break;
64436463 case ISD::BITCAST:
64446464 assert(VT.getSizeInBits() == N1.getValueSizeInBits() &&
@@ -6448,6 +6468,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
64486468 return getNode(ISD::BITCAST, DL, VT, N1.getOperand(0));
64496469 if (OpOpcode == ISD::UNDEF)
64506470 return getUNDEF(VT);
6471+ if (OpOpcode == ISD::POISON)
6472+ return getPoison(VT);
64516473 break;
64526474 case ISD::SCALAR_TO_VECTOR:
64536475 assert(VT.isVector() && !N1.getValueType().isVector() &&
@@ -6458,6 +6480,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
64586480 "Illegal SCALAR_TO_VECTOR node!");
64596481 if (OpOpcode == ISD::UNDEF)
64606482 return getUNDEF(VT);
6483+ if (OpOpcode == ISD::POISON)
6484+ return getPoison(VT);
64616485 // scalar_to_vector(extract_vector_elt V, 0) -> V, top bits are undefined.
64626486 if (OpOpcode == ISD::EXTRACT_VECTOR_ELT &&
64636487 isa<ConstantSDNode>(N1.getOperand(1)) &&
@@ -6469,6 +6493,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
64696493 // Negation of an unknown bag of bits is still completely undefined.
64706494 if (OpOpcode == ISD::UNDEF)
64716495 return getUNDEF(VT);
6496+ if (OpOpcode == ISD::POISON)
6497+ return getPoison(VT);
64726498
64736499 if (OpOpcode == ISD::FNEG) // --X -> X
64746500 return N1.getOperand(0);
@@ -9237,6 +9263,11 @@ SDValue SelectionDAG::getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
92379263
92389264 SDVTList VTs = Indexed ?
92399265 getVTList(VT, Ptr.getValueType(), MVT::Other) : getVTList(VT, MVT::Other);
9266+
9267+ // FixedMe: lower poison to undef.
9268+ if (Ptr.getNode()->isPoison())
9269+ Ptr = getUNDEF(Ptr.getValueType());
9270+
92409271 SDValue Ops[] = { Chain, Ptr, Offset };
92419272 FoldingSetNodeID ID;
92429273 AddNodeIDNode(ID, ISD::LOAD, VTs, Ops);
@@ -13374,7 +13405,7 @@ void BuildVectorSDNode::recastRawBits(bool IsLittleEndian,
1337413405bool BuildVectorSDNode::isConstant() const {
1337513406 for (const SDValue &Op : op_values()) {
1337613407 unsigned Opc = Op.getOpcode();
13377- if (Opc != ISD::UNDEF && Opc != ISD::Constant && Opc != ISD::ConstantFP)
13408+ if (!Op.isUndef() && Opc != ISD::Constant && Opc != ISD::ConstantFP)
1337813409 return false;
1337913410 }
1338013411 return true;
0 commit comments