@@ -152,14 +152,10 @@ bool ConstantFPSDNode::isValueValidForType(EVT VT,
152
152
153
153
bool ISD::isConstantSplatVector(const SDNode *N, APInt &SplatVal) {
154
154
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);
163
159
return true;
164
160
}
165
161
}
@@ -215,12 +211,9 @@ bool ISD::isConstantSplatVectorAllOnes(const SDNode *N, bool BuildVectorOnly) {
215
211
// we care if the resultant vector is all ones, not whether the individual
216
212
// constants are.
217
213
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)
224
217
return false;
225
218
} else
226
219
return false;
@@ -259,12 +252,9 @@ bool ISD::isConstantSplatVectorAllZeros(const SDNode *N, bool BuildVectorOnly) {
259
252
// We only want to check enough bits to cover the vector elements, because
260
253
// we care if the resultant vector is all zeros, not whether the individual
261
254
// 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)
268
258
return false;
269
259
} else
270
260
return false;
@@ -3405,13 +3395,9 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
3405
3395
3406
3396
KnownBits Known(BitWidth); // Don't know anything.
3407
3397
3408
- if (auto *C = dyn_cast<ConstantSDNode>(Op )) {
3398
+ if (auto OptAPInt = Op->bitcastToAPInt( )) {
3409
3399
// 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));
3415
3401
}
3416
3402
3417
3403
if (Depth >= MaxRecursionDepth)
0 commit comments