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