@@ -1768,11 +1768,8 @@ Instruction *InstCombinerImpl::foldICmpAndConstConst(ICmpInst &Cmp,
1768
1768
const APInt &C1) {
1769
1769
bool isICMP_NE = Cmp.getPredicate () == ICmpInst::ICMP_NE;
1770
1770
1771
- // For vectors: icmp ne (and X, 1), 0 --> trunc X to N x i1
1772
- // TODO: We canonicalize to the longer form for scalars because we have
1773
- // better analysis/folds for icmp, and codegen may be better with icmp.
1774
- if (isICMP_NE && Cmp.getType ()->isVectorTy () && C1.isZero () &&
1775
- match (And->getOperand (1 ), m_One ()))
1771
+ // icmp ne (and X, 1), 0 --> trunc X to N x i1
1772
+ if (isICMP_NE && C1.isZero () && match (And->getOperand (1 ), m_One ()))
1776
1773
return new TruncInst (And->getOperand (0 ), Cmp.getType ());
1777
1774
1778
1775
const APInt *C2;
@@ -6778,6 +6775,13 @@ Instruction *InstCombinerImpl::foldICmpUsingKnownBits(ICmpInst &I) {
6778
6775
break ;
6779
6776
case ICmpInst::ICMP_EQ:
6780
6777
case ICmpInst::ICMP_NE: {
6778
+ if (Ty->isIntOrIntVectorTy () && Op0Known.countMaxActiveBits () <= 1 )
6779
+ if ((Pred == CmpInst::ICMP_NE && Op1Known.isZero ()) ||
6780
+ (Pred == CmpInst::ICMP_EQ && Op1Known.isConstant () &&
6781
+ Op1Known.getConstant ().isOne ()))
6782
+ return replaceInstUsesWith (
6783
+ I, Builder.CreateTrunc (Op0, I.getType (), " " , /* IsNUW=*/ true ));
6784
+
6781
6785
// If all bits are known zero except for one, then we know at most one bit
6782
6786
// is set. If the comparison is against zero, then this is a check to see if
6783
6787
// *that* bit is set.
0 commit comments