@@ -4506,13 +4506,23 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
4506
4506
return New;
4507
4507
}
4508
4508
4509
- // Sign-bit checks are preserved through signed floating-point casts:
4510
- // icmp slt (bitcast (sitofp X)), 0 --> icmp slt X, 0
4511
- // icmp sgt (bitcast (sitofp X)), -1 --> icmp sgt X, -1
4509
+ // Zero-equality and sign-bit checks are preserved through sitofp + bitcast.
4512
4510
Value *X;
4513
4511
if (match (Op0, m_BitCast (m_SIToFP (m_Value (X))))) {
4514
- if (Pred == ICmpInst::ICMP_SLT && match (Op1, m_Zero ()))
4512
+ // icmp eq (bitcast (sitofp X)), 0 --> icmp eq X, 0
4513
+ // icmp ne (bitcast (sitofp X)), 0 --> icmp ne X, 0
4514
+ // icmp slt (bitcast (sitofp X)), 0 --> icmp slt X, 0
4515
+ // icmp sgt (bitcast (sitofp X)), 0 --> icmp sgt X, 0
4516
+ if ((Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_SLT ||
4517
+ Pred == ICmpInst::ICMP_NE || Pred == ICmpInst::ICMP_SGT) &&
4518
+ match (Op1, m_Zero ()))
4515
4519
return new ICmpInst (Pred, X, ConstantInt::getNullValue (X->getType ()));
4520
+
4521
+ // icmp slt (bitcast (sitofp X)), 1 --> icmp slt X, 1
4522
+ if (Pred == ICmpInst::ICMP_SLT && match (Op1, m_One ()))
4523
+ return new ICmpInst (Pred, X, ConstantInt::get (X->getType (), 1 ));
4524
+
4525
+ // icmp sgt (bitcast (sitofp X)), -1 --> icmp sgt X, -1
4516
4526
if (Pred == ICmpInst::ICMP_SGT && match (Op1, m_AllOnes ()))
4517
4527
return new ICmpInst (Pred, X, ConstantInt::getAllOnesValue (X->getType ()));
4518
4528
}
0 commit comments