@@ -152,14 +152,10 @@ bool ConstantFPSDNode::isValueValidForType(EVT VT,
152152
153153bool ISD::isConstantSplatVector(const SDNode *N, APInt &SplatVal) {
154154 if (N->getOpcode() == ISD::SPLAT_VECTOR) {
155- unsigned EltSize =
156- N->getValueType(0).getVectorElementType().getSizeInBits();
157- if (auto *Op0 = dyn_cast<ConstantSDNode>(N->getOperand(0))) {
158- SplatVal = Op0->getAPIntValue().trunc(EltSize);
159- return true;
160- }
161- if (auto *Op0 = dyn_cast<ConstantFPSDNode>(N->getOperand(0))) {
162- SplatVal = Op0->getValueAPF().bitcastToAPInt().trunc(EltSize);
155+ if (auto OptAPInt = N->getOperand(0)->bitcastToAPInt()) {
156+ unsigned EltSize =
157+ N->getValueType(0).getVectorElementType().getSizeInBits();
158+ SplatVal = OptAPInt->trunc(EltSize);
163159 return true;
164160 }
165161 }
@@ -215,12 +211,9 @@ bool ISD::isConstantSplatVectorAllOnes(const SDNode *N, bool BuildVectorOnly) {
215211 // we care if the resultant vector is all ones, not whether the individual
216212 // constants are.
217213 SDValue NotZero = N->getOperand(i);
218- unsigned EltSize = N->getValueType(0).getScalarSizeInBits();
219- if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(NotZero)) {
220- if (CN->getAPIntValue().countr_one() < EltSize)
221- return false;
222- } else if (ConstantFPSDNode *CFPN = dyn_cast<ConstantFPSDNode>(NotZero)) {
223- if (CFPN->getValueAPF().bitcastToAPInt().countr_one() < EltSize)
214+ if (auto OptAPInt = NotZero->bitcastToAPInt()) {
215+ unsigned EltSize = N->getValueType(0).getScalarSizeInBits();
216+ if (OptAPInt->countr_one() < EltSize)
224217 return false;
225218 } else
226219 return false;
@@ -259,12 +252,9 @@ bool ISD::isConstantSplatVectorAllZeros(const SDNode *N, bool BuildVectorOnly) {
259252 // We only want to check enough bits to cover the vector elements, because
260253 // we care if the resultant vector is all zeros, not whether the individual
261254 // constants are.
262- unsigned EltSize = N->getValueType(0).getScalarSizeInBits();
263- if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(Op)) {
264- if (CN->getAPIntValue().countr_zero() < EltSize)
265- return false;
266- } else if (ConstantFPSDNode *CFPN = dyn_cast<ConstantFPSDNode>(Op)) {
267- if (CFPN->getValueAPF().bitcastToAPInt().countr_zero() < EltSize)
255+ if (auto OptAPInt = Op->bitcastToAPInt()) {
256+ unsigned EltSize = N->getValueType(0).getScalarSizeInBits();
257+ if (OptAPInt->countr_zero() < EltSize)
268258 return false;
269259 } else
270260 return false;
@@ -3405,13 +3395,9 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
34053395
34063396 KnownBits Known(BitWidth); // Don't know anything.
34073397
3408- if (auto *C = dyn_cast<ConstantSDNode>(Op )) {
3398+ if (auto OptAPInt = Op->bitcastToAPInt( )) {
34093399 // We know all of the bits for a constant!
3410- return KnownBits::makeConstant(C->getAPIntValue());
3411- }
3412- if (auto *C = dyn_cast<ConstantFPSDNode>(Op)) {
3413- // We know all of the bits for a constant fp!
3414- return KnownBits::makeConstant(C->getValueAPF().bitcastToAPInt());
3400+ return KnownBits::makeConstant(*std::move(OptAPInt));
34153401 }
34163402
34173403 if (Depth >= MaxRecursionDepth)
0 commit comments