@@ -3261,38 +3261,31 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
3261
3261
break ;
3262
3262
}
3263
3263
case ISD::INSERT_VECTOR_ELT: {
3264
+ // If we know the element index, split the demand between the
3265
+ // source vector and the inserted element, otherwise assume we need
3266
+ // the original demanded vector elements and the value.
3264
3267
SDValue InVec = Op.getOperand (0 );
3265
3268
SDValue InVal = Op.getOperand (1 );
3266
3269
SDValue EltNo = Op.getOperand (2 );
3267
-
3268
- ConstantSDNode *CEltNo = dyn_cast<ConstantSDNode>(EltNo);
3270
+ bool DemandedVal = true ;
3271
+ APInt DemandedVecElts = DemandedElts;
3272
+ auto *CEltNo = dyn_cast<ConstantSDNode>(EltNo);
3269
3273
if (CEltNo && CEltNo->getAPIntValue ().ult (NumElts)) {
3270
- // If we know the element index, split the demand between the
3271
- // source vector and the inserted element.
3272
- Known.Zero = Known.One = APInt::getAllOnesValue (BitWidth);
3273
3274
unsigned EltIdx = CEltNo->getZExtValue ();
3274
-
3275
- // If we demand the inserted element then add its common known bits.
3276
- if (DemandedElts[EltIdx]) {
3277
- Known2 = computeKnownBits (InVal, Depth + 1 );
3278
- Known.One &= Known2.One .zextOrTrunc (Known.One .getBitWidth ());
3279
- Known.Zero &= Known2.Zero .zextOrTrunc (Known.Zero .getBitWidth ());
3280
- }
3281
-
3282
- // If we demand the source vector then add its common known bits, ensuring
3283
- // that we don't demand the inserted element.
3284
- APInt VectorElts = DemandedElts & ~(APInt::getOneBitSet (NumElts, EltIdx));
3285
- if (!!VectorElts) {
3286
- Known2 = computeKnownBits (InVec, VectorElts, Depth + 1 );
3287
- Known.One &= Known2.One ;
3288
- Known.Zero &= Known2.Zero ;
3289
- }
3290
- } else {
3291
- // Unknown element index, so ignore DemandedElts and demand them all.
3292
- Known = computeKnownBits (InVec, Depth + 1 );
3275
+ DemandedVal = !!DemandedElts[EltIdx];
3276
+ DemandedVecElts.clearBit (EltIdx);
3277
+ }
3278
+ Known.One .setAllBits ();
3279
+ Known.Zero .setAllBits ();
3280
+ if (DemandedVal) {
3293
3281
Known2 = computeKnownBits (InVal, Depth + 1 );
3294
- Known.One &= Known2.One .zextOrTrunc (Known.One .getBitWidth ());
3295
- Known.Zero &= Known2.Zero .zextOrTrunc (Known.Zero .getBitWidth ());
3282
+ Known.One &= Known2.One .zextOrTrunc (BitWidth);
3283
+ Known.Zero &= Known2.Zero .zextOrTrunc (BitWidth);
3284
+ }
3285
+ if (!!DemandedVecElts) {
3286
+ Known2 = computeKnownBits (InVec, DemandedVecElts, Depth + 1 );
3287
+ Known.One &= Known2.One ;
3288
+ Known.Zero &= Known2.Zero ;
3296
3289
}
3297
3290
break ;
3298
3291
}
@@ -3850,39 +3843,32 @@ unsigned SelectionDAG::ComputeNumSignBits(SDValue Op, const APInt &DemandedElts,
3850
3843
return std::max (std::min (KnownSign - rIndex * BitWidth, BitWidth), 0 );
3851
3844
}
3852
3845
case ISD::INSERT_VECTOR_ELT: {
3846
+ // If we know the element index, split the demand between the
3847
+ // source vector and the inserted element, otherwise assume we need
3848
+ // the original demanded vector elements and the value.
3853
3849
SDValue InVec = Op.getOperand (0 );
3854
3850
SDValue InVal = Op.getOperand (1 );
3855
3851
SDValue EltNo = Op.getOperand (2 );
3856
-
3857
- ConstantSDNode *CEltNo = dyn_cast<ConstantSDNode>(EltNo);
3852
+ bool DemandedVal = true ;
3853
+ APInt DemandedVecElts = DemandedElts;
3854
+ auto *CEltNo = dyn_cast<ConstantSDNode>(EltNo);
3858
3855
if (CEltNo && CEltNo->getAPIntValue ().ult (NumElts)) {
3859
- // If we know the element index, split the demand between the
3860
- // source vector and the inserted element.
3861
3856
unsigned EltIdx = CEltNo->getZExtValue ();
3862
-
3863
- // If we demand the inserted element then get its sign bits.
3864
- Tmp = std::numeric_limits<unsigned >::max ();
3865
- if (DemandedElts[EltIdx]) {
3866
- // TODO - handle implicit truncation of inserted elements.
3867
- if (InVal.getScalarValueSizeInBits () != VTBits)
3868
- break ;
3869
- Tmp = ComputeNumSignBits (InVal, Depth + 1 );
3870
- }
3871
-
3872
- // If we demand the source vector then get its sign bits, and determine
3873
- // the minimum.
3874
- APInt VectorElts = DemandedElts;
3875
- VectorElts.clearBit (EltIdx);
3876
- if (!!VectorElts) {
3877
- Tmp2 = ComputeNumSignBits (InVec, VectorElts, Depth + 1 );
3878
- Tmp = std::min (Tmp, Tmp2);
3879
- }
3880
- } else {
3881
- // Unknown element index, so ignore DemandedElts and demand them all.
3882
- Tmp = ComputeNumSignBits (InVec, Depth + 1 );
3857
+ DemandedVal = !!DemandedElts[EltIdx];
3858
+ DemandedVecElts.clearBit (EltIdx);
3859
+ }
3860
+ Tmp = std::numeric_limits<unsigned >::max ();
3861
+ if (DemandedVal) {
3862
+ // TODO - handle implicit truncation of inserted elements.
3863
+ if (InVal.getScalarValueSizeInBits () != VTBits)
3864
+ break ;
3883
3865
Tmp2 = ComputeNumSignBits (InVal, Depth + 1 );
3884
3866
Tmp = std::min (Tmp, Tmp2);
3885
3867
}
3868
+ if (!!DemandedVecElts) {
3869
+ Tmp2 = ComputeNumSignBits (InVec, DemandedVecElts, Depth + 1 );
3870
+ Tmp = std::min (Tmp, Tmp2);
3871
+ }
3886
3872
assert (Tmp <= VTBits && " Failed to determine minimum sign bits" );
3887
3873
return Tmp;
3888
3874
}
0 commit comments