@@ -3801,7 +3801,8 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
3801
3801
default : break ;
3802
3802
case Instruction::SExt:
3803
3803
Tmp = TyBits - U->getOperand (0 )->getType ()->getScalarSizeInBits ();
3804
- return ComputeNumSignBits (U->getOperand (0 ), Depth + 1 , Q) + Tmp;
3804
+ return ComputeNumSignBits (U->getOperand (0 ), DemandedElts, Depth + 1 , Q) +
3805
+ Tmp;
3805
3806
3806
3807
case Instruction::SDiv: {
3807
3808
const APInt *Denominator;
@@ -3813,7 +3814,8 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
3813
3814
break ;
3814
3815
3815
3816
// Calculate the incoming numerator bits.
3816
- unsigned NumBits = ComputeNumSignBits (U->getOperand (0 ), Depth + 1 , Q);
3817
+ unsigned NumBits =
3818
+ ComputeNumSignBits (U->getOperand (0 ), DemandedElts, Depth + 1 , Q);
3817
3819
3818
3820
// Add floor(log(C)) bits to the numerator bits.
3819
3821
return std::min (TyBits, NumBits + Denominator->logBase2 ());
@@ -3822,7 +3824,7 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
3822
3824
}
3823
3825
3824
3826
case Instruction::SRem: {
3825
- Tmp = ComputeNumSignBits (U->getOperand (0 ), Depth + 1 , Q);
3827
+ Tmp = ComputeNumSignBits (U->getOperand (0 ), DemandedElts, Depth + 1 , Q);
3826
3828
3827
3829
const APInt *Denominator;
3828
3830
// srem X, C -> we know that the result is within [-C+1,C) when C is a
@@ -3853,7 +3855,7 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
3853
3855
}
3854
3856
3855
3857
case Instruction::AShr: {
3856
- Tmp = ComputeNumSignBits (U->getOperand (0 ), Depth + 1 , Q);
3858
+ Tmp = ComputeNumSignBits (U->getOperand (0 ), DemandedElts, Depth + 1 , Q);
3857
3859
// ashr X, C -> adds C sign bits. Vectors too.
3858
3860
const APInt *ShAmt;
3859
3861
if (match (U->getOperand (1 ), m_APInt (ShAmt))) {
@@ -3869,7 +3871,7 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
3869
3871
const APInt *ShAmt;
3870
3872
if (match (U->getOperand (1 ), m_APInt (ShAmt))) {
3871
3873
// shl destroys sign bits.
3872
- Tmp = ComputeNumSignBits (U->getOperand (0 ), Depth + 1 , Q);
3874
+ Tmp = ComputeNumSignBits (U->getOperand (0 ), DemandedElts, Depth + 1 , Q);
3873
3875
if (ShAmt->uge (TyBits) || // Bad shift.
3874
3876
ShAmt->uge (Tmp)) break ; // Shifted all sign bits out.
3875
3877
Tmp2 = ShAmt->getZExtValue ();
@@ -3881,9 +3883,9 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
3881
3883
case Instruction::Or:
3882
3884
case Instruction::Xor: // NOT is handled here.
3883
3885
// Logical binary ops preserve the number of sign bits at the worst.
3884
- Tmp = ComputeNumSignBits (U->getOperand (0 ), Depth + 1 , Q);
3886
+ Tmp = ComputeNumSignBits (U->getOperand (0 ), DemandedElts, Depth + 1 , Q);
3885
3887
if (Tmp != 1 ) {
3886
- Tmp2 = ComputeNumSignBits (U->getOperand (1 ), Depth + 1 , Q);
3888
+ Tmp2 = ComputeNumSignBits (U->getOperand (1 ), DemandedElts, Depth + 1 , Q);
3887
3889
FirstAnswer = std::min (Tmp, Tmp2);
3888
3890
// We computed what we know about the sign bits as our first
3889
3891
// answer. Now proceed to the generic code that uses
@@ -3899,9 +3901,10 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
3899
3901
if (isSignedMinMaxClamp (U, X, CLow, CHigh))
3900
3902
return std::min (CLow->getNumSignBits (), CHigh->getNumSignBits ());
3901
3903
3902
- Tmp = ComputeNumSignBits (U->getOperand (1 ), Depth + 1 , Q);
3903
- if (Tmp == 1 ) break ;
3904
- Tmp2 = ComputeNumSignBits (U->getOperand (2 ), Depth + 1 , Q);
3904
+ Tmp = ComputeNumSignBits (U->getOperand (1 ), DemandedElts, Depth + 1 , Q);
3905
+ if (Tmp == 1 )
3906
+ break ;
3907
+ Tmp2 = ComputeNumSignBits (U->getOperand (2 ), DemandedElts, Depth + 1 , Q);
3905
3908
return std::min (Tmp, Tmp2);
3906
3909
}
3907
3910
@@ -3915,7 +3918,7 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
3915
3918
if (const auto *CRHS = dyn_cast<Constant>(U->getOperand (1 )))
3916
3919
if (CRHS->isAllOnesValue ()) {
3917
3920
KnownBits Known (TyBits);
3918
- computeKnownBits (U->getOperand (0 ), Known, Depth + 1 , Q);
3921
+ computeKnownBits (U->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
3919
3922
3920
3923
// If the input is known to be 0 or 1, the output is 0/-1, which is
3921
3924
// all sign bits set.
@@ -3928,19 +3931,21 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
3928
3931
return Tmp;
3929
3932
}
3930
3933
3931
- Tmp2 = ComputeNumSignBits (U->getOperand (1 ), Depth + 1 , Q);
3932
- if (Tmp2 == 1 ) break ;
3934
+ Tmp2 = ComputeNumSignBits (U->getOperand (1 ), DemandedElts, Depth + 1 , Q);
3935
+ if (Tmp2 == 1 )
3936
+ break ;
3933
3937
return std::min (Tmp, Tmp2) - 1 ;
3934
3938
3935
3939
case Instruction::Sub:
3936
- Tmp2 = ComputeNumSignBits (U->getOperand (1 ), Depth + 1 , Q);
3937
- if (Tmp2 == 1 ) break ;
3940
+ Tmp2 = ComputeNumSignBits (U->getOperand (1 ), DemandedElts, Depth + 1 , Q);
3941
+ if (Tmp2 == 1 )
3942
+ break ;
3938
3943
3939
3944
// Handle NEG.
3940
3945
if (const auto *CLHS = dyn_cast<Constant>(U->getOperand (0 )))
3941
3946
if (CLHS->isNullValue ()) {
3942
3947
KnownBits Known (TyBits);
3943
- computeKnownBits (U->getOperand (1 ), Known, Depth + 1 , Q);
3948
+ computeKnownBits (U->getOperand (1 ), DemandedElts, Known, Depth + 1 , Q);
3944
3949
// If the input is known to be 0 or 1, the output is 0/-1, which is
3945
3950
// all sign bits set.
3946
3951
if ((Known.Zero | 1 ).isAllOnes ())
@@ -3957,17 +3962,22 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
3957
3962
3958
3963
// Sub can have at most one carry bit. Thus we know that the output
3959
3964
// is, at worst, one more bit than the inputs.
3960
- Tmp = ComputeNumSignBits (U->getOperand (0 ), Depth + 1 , Q);
3961
- if (Tmp == 1 ) break ;
3965
+ Tmp = ComputeNumSignBits (U->getOperand (0 ), DemandedElts, Depth + 1 , Q);
3966
+ if (Tmp == 1 )
3967
+ break ;
3962
3968
return std::min (Tmp, Tmp2) - 1 ;
3963
3969
3964
3970
case Instruction::Mul: {
3965
3971
// The output of the Mul can be at most twice the valid bits in the
3966
3972
// inputs.
3967
- unsigned SignBitsOp0 = ComputeNumSignBits (U->getOperand (0 ), Depth + 1 , Q);
3968
- if (SignBitsOp0 == 1 ) break ;
3969
- unsigned SignBitsOp1 = ComputeNumSignBits (U->getOperand (1 ), Depth + 1 , Q);
3970
- if (SignBitsOp1 == 1 ) break ;
3973
+ unsigned SignBitsOp0 =
3974
+ ComputeNumSignBits (U->getOperand (0 ), DemandedElts, Depth + 1 , Q);
3975
+ if (SignBitsOp0 == 1 )
3976
+ break ;
3977
+ unsigned SignBitsOp1 =
3978
+ ComputeNumSignBits (U->getOperand (1 ), DemandedElts, Depth + 1 , Q);
3979
+ if (SignBitsOp1 == 1 )
3980
+ break ;
3971
3981
unsigned OutValidBits =
3972
3982
(TyBits - SignBitsOp0 + 1 ) + (TyBits - SignBitsOp1 + 1 );
3973
3983
return OutValidBits > TyBits ? 1 : TyBits - OutValidBits + 1 ;
@@ -3988,8 +3998,8 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
3988
3998
for (unsigned i = 0 , e = NumIncomingValues; i != e; ++i) {
3989
3999
if (Tmp == 1 ) return Tmp;
3990
4000
RecQ.CxtI = PN->getIncomingBlock (i)->getTerminator ();
3991
- Tmp = std::min (
3992
- Tmp, ComputeNumSignBits (PN-> getIncomingValue (i) , Depth + 1 , RecQ));
4001
+ Tmp = std::min (Tmp, ComputeNumSignBits (PN-> getIncomingValue (i),
4002
+ DemandedElts , Depth + 1 , RecQ));
3993
4003
}
3994
4004
return Tmp;
3995
4005
}
@@ -4050,10 +4060,13 @@ static unsigned ComputeNumSignBitsImpl(const Value *V,
4050
4060
case Instruction::Call: {
4051
4061
if (const auto *II = dyn_cast<IntrinsicInst>(U)) {
4052
4062
switch (II->getIntrinsicID ()) {
4053
- default : break ;
4063
+ default :
4064
+ break ;
4054
4065
case Intrinsic::abs:
4055
- Tmp = ComputeNumSignBits (U->getOperand (0 ), Depth + 1 , Q);
4056
- if (Tmp == 1 ) break ;
4066
+ Tmp =
4067
+ ComputeNumSignBits (U->getOperand (0 ), DemandedElts, Depth + 1 , Q);
4068
+ if (Tmp == 1 )
4069
+ break ;
4057
4070
4058
4071
// Absolute value reduces number of sign bits by at most 1.
4059
4072
return Tmp - 1 ;
0 commit comments