@@ -2019,7 +2019,8 @@ static Value *simplifyAndOrOfCmps(const SimplifyQuery &Q, Value *Op0,
2019
2019
// If we looked through casts, we can only handle a constant simplification
2020
2020
// because we are not allowed to create a cast instruction here.
2021
2021
if (auto *C = dyn_cast<Constant>(V))
2022
- return ConstantExpr::getCast (Cast0->getOpcode (), C, Cast0->getType ());
2022
+ return ConstantFoldCastOperand (Cast0->getOpcode (), C, Cast0->getType (),
2023
+ Q.DL );
2023
2024
2024
2025
return nullptr ;
2025
2026
}
@@ -3876,9 +3877,15 @@ static Value *simplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
3876
3877
3877
3878
// Compute the constant that would happen if we truncated to SrcTy then
3878
3879
// reextended to DstTy.
3879
- Constant *Trunc = ConstantExpr::getTrunc (C, SrcTy);
3880
- Constant *RExt = ConstantExpr::getCast (CastInst::ZExt, Trunc, DstTy);
3881
- Constant *AnyEq = ConstantExpr::getICmp (ICmpInst::ICMP_EQ, RExt, C);
3880
+ Constant *Trunc =
3881
+ ConstantFoldCastOperand (Instruction::Trunc, C, SrcTy, Q.DL );
3882
+ assert (Trunc && " Constant-fold of ImmConstant should not fail" );
3883
+ Constant *RExt =
3884
+ ConstantFoldCastOperand (CastInst::ZExt, Trunc, DstTy, Q.DL );
3885
+ assert (RExt && " Constant-fold of ImmConstant should not fail" );
3886
+ Constant *AnyEq =
3887
+ ConstantFoldCompareInstOperands (ICmpInst::ICMP_EQ, RExt, C, Q.DL );
3888
+ assert (AnyEq && " Constant-fold of ImmConstant should not fail" );
3882
3889
3883
3890
// If the re-extended constant didn't change any of the elements then
3884
3891
// this is effectively also a case of comparing two zero-extended
@@ -3947,9 +3954,15 @@ static Value *simplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS,
3947
3954
3948
3955
// Compute the constant that would happen if we truncated to SrcTy then
3949
3956
// reextended to DstTy.
3950
- Constant *Trunc = ConstantExpr::getTrunc (C, SrcTy);
3951
- Constant *RExt = ConstantExpr::getCast (CastInst::SExt, Trunc, DstTy);
3952
- Constant *AnyEq = ConstantExpr::getICmp (ICmpInst::ICMP_EQ, RExt, C);
3957
+ Constant *Trunc =
3958
+ ConstantFoldCastOperand (Instruction::Trunc, C, SrcTy, Q.DL );
3959
+ assert (Trunc && " Constant-fold of ImmConstant should not fail" );
3960
+ Constant *RExt =
3961
+ ConstantFoldCastOperand (CastInst::SExt, Trunc, DstTy, Q.DL );
3962
+ assert (RExt && " Constant-fold of ImmConstant should not fail" );
3963
+ Constant *AnyEq =
3964
+ ConstantFoldCompareInstOperands (ICmpInst::ICMP_EQ, RExt, C, Q.DL );
3965
+ assert (AnyEq && " Constant-fold of ImmConstant should not fail" );
3953
3966
3954
3967
// If the re-extended constant didn't change then this is effectively
3955
3968
// also a case of comparing two sign-extended values.
0 commit comments