@@ -3561,7 +3561,6 @@ static Instruction *foldBitCeil(SelectInst &SI, IRBuilderBase &Builder) {
3561
3561
// This function tries to fold the following operations:
3562
3562
// (x < y) ? -1 : zext(x != y)
3563
3563
// (x > y) ? 1 : sext(x != y)
3564
- // (x >= y) ? zext(x != y) : -1
3565
3564
// Into ucmp/scmp(x, y), where signedness is determined by the signedness
3566
3565
// of the comparison in the original sequence
3567
3566
Instruction *InstCombinerImpl::foldSelectToCmp (SelectInst &SI) {
@@ -3589,19 +3588,22 @@ Instruction *InstCombinerImpl::foldSelectToCmp(SelectInst &SI) {
3589
3588
Intrinsic::ID IID =
3590
3589
ICmpInst::isSigned (Pred) ? Intrinsic::scmp : Intrinsic::ucmp;
3591
3590
3592
- CallInst *Intrinsic = nullptr ;
3591
+ bool Replace = false ;
3593
3592
// (x < y) ? -1 : zext(x != y)
3594
3593
if (ICmpInst::isLT (Pred) && match (TV, m_AllOnes ()) &&
3595
- match (FV, m_ZExt (m_c_SpecificICmp (ICmpInst::ICMP_NE, m_Specific (LHS), m_Specific (RHS)))))
3596
- Intrinsic = Builder.CreateIntrinsic (SI.getType (), IID, {LHS, RHS});
3594
+ match (FV, m_ZExt (m_c_SpecificICmp (ICmpInst::ICMP_NE, m_Specific (LHS),
3595
+ m_Specific (RHS)))))
3596
+ Replace = true ;
3597
3597
3598
3598
// (x > y) ? 1 : sext(x != y)
3599
3599
if (ICmpInst::isGT (Pred) && match (TV, m_One ()) &&
3600
- match (FV, m_SExt (m_c_SpecificICmp (ICmpInst::ICMP_NE, m_Specific (LHS), m_Specific (RHS)))))
3601
- Intrinsic = Builder.CreateIntrinsic (SI.getType (), IID, {LHS, RHS});
3600
+ match (FV, m_SExt (m_c_SpecificICmp (ICmpInst::ICMP_NE, m_Specific (LHS),
3601
+ m_Specific (RHS)))))
3602
+ Replace = true ;
3602
3603
3603
- if (Intrinsic)
3604
- return replaceInstUsesWith (SI, Intrinsic);
3604
+ if (Replace)
3605
+ return replaceInstUsesWith (
3606
+ SI, Builder.CreateIntrinsic (SI.getType (), IID, {LHS, RHS}));
3605
3607
return nullptr ;
3606
3608
}
3607
3609
0 commit comments