@@ -2355,13 +2355,16 @@ bool SelectionDAG::MaskedValueIsAllOnes(SDValue V, const APInt &Mask,
2355
2355
// / sense to specify which elements are demanded or undefined, therefore
2356
2356
// / they are simply ignored.
2357
2357
bool SelectionDAG::isSplatValue (SDValue V, const APInt &DemandedElts,
2358
- APInt &UndefElts) {
2358
+ APInt &UndefElts, unsigned Depth ) {
2359
2359
EVT VT = V.getValueType ();
2360
2360
assert (VT.isVector () && " Vector type expected" );
2361
2361
2362
2362
if (!VT.isScalableVector () && !DemandedElts)
2363
2363
return false ; // No demanded elts, better to assume we don't know anything.
2364
2364
2365
+ if (Depth >= MaxRecursionDepth)
2366
+ return false ; // Limit search depth.
2367
+
2365
2368
// Deal with some common cases here that work for both fixed and scalable
2366
2369
// vector types.
2367
2370
switch (V.getOpcode ()) {
@@ -2376,8 +2379,8 @@ bool SelectionDAG::isSplatValue(SDValue V, const APInt &DemandedElts,
2376
2379
APInt UndefLHS, UndefRHS;
2377
2380
SDValue LHS = V.getOperand (0 );
2378
2381
SDValue RHS = V.getOperand (1 );
2379
- if (isSplatValue (LHS, DemandedElts, UndefLHS) &&
2380
- isSplatValue (RHS, DemandedElts, UndefRHS)) {
2382
+ if (isSplatValue (LHS, DemandedElts, UndefLHS, Depth + 1 ) &&
2383
+ isSplatValue (RHS, DemandedElts, UndefRHS, Depth + 1 )) {
2381
2384
UndefElts = UndefLHS | UndefRHS;
2382
2385
return true ;
2383
2386
}
@@ -2386,7 +2389,7 @@ bool SelectionDAG::isSplatValue(SDValue V, const APInt &DemandedElts,
2386
2389
case ISD::TRUNCATE:
2387
2390
case ISD::SIGN_EXTEND:
2388
2391
case ISD::ZERO_EXTEND:
2389
- return isSplatValue (V.getOperand (0 ), DemandedElts, UndefElts);
2392
+ return isSplatValue (V.getOperand (0 ), DemandedElts, UndefElts, Depth + 1 );
2390
2393
}
2391
2394
2392
2395
// We don't support other cases than those above for scalable vectors at
@@ -2441,7 +2444,7 @@ bool SelectionDAG::isSplatValue(SDValue V, const APInt &DemandedElts,
2441
2444
unsigned NumSrcElts = Src.getValueType ().getVectorNumElements ();
2442
2445
APInt UndefSrcElts;
2443
2446
APInt DemandedSrcElts = DemandedElts.zextOrSelf (NumSrcElts).shl (Idx);
2444
- if (isSplatValue (Src, DemandedSrcElts, UndefSrcElts)) {
2447
+ if (isSplatValue (Src, DemandedSrcElts, UndefSrcElts, Depth + 1 )) {
2445
2448
UndefElts = UndefSrcElts.extractBits (NumElts, Idx);
2446
2449
return true ;
2447
2450
}
0 commit comments