@@ -4128,27 +4128,21 @@ Instruction *InstCombiner::foldICmpWithCastOp(ICmpInst &ICmp) {
4128
4128
// The re-extended constant changed, partly changed (in the case of a vector),
4129
4129
// or could not be determined to be equal (in the case of a constant
4130
4130
// expression), so the constant cannot be represented in the shorter type.
4131
- // Consequently, we cannot emit a simple comparison.
4132
4131
// All the cases that fold to true or false will have already been handled
4133
4132
// by SimplifyICmpInst, so only deal with the tricky case.
4134
-
4135
4133
if (isSignedCmp || !isSignedExt || !isa<ConstantInt>(C))
4136
4134
return nullptr ;
4137
4135
4138
- // Evaluate the comparison for LT (we invert for GT below). LE and GE cases
4139
- // should have been folded away previously and not enter in here.
4140
-
4141
- // We're performing an unsigned comp with a sign extended value.
4142
- // This is true if the input is >= 0. [aka >s -1]
4143
- Constant *NegOne = Constant::getAllOnesValue (SrcTy);
4144
- Value *Result = Builder.CreateICmpSGT (Op0Src, NegOne, ICmp.getName ());
4145
-
4146
- // Finally, return the value computed.
4136
+ // Is source op positive?
4137
+ // icmp ult (sext X), C --> icmp sgt X, -1
4147
4138
if (ICmp.getPredicate () == ICmpInst::ICMP_ULT)
4148
- return replaceInstUsesWith (ICmp, Result);
4139
+ return new ICmpInst (CmpInst::ICMP_SGT, Op0Src,
4140
+ Constant::getAllOnesValue (SrcTy));
4149
4141
4142
+ // Is source op negative?
4143
+ // icmp ugt (sext X), C --> icmp slt X, 0
4150
4144
assert (ICmp.getPredicate () == ICmpInst::ICMP_UGT && " ICmp should be folded!" );
4151
- return BinaryOperator::CreateNot (Result );
4145
+ return new ICmpInst (CmpInst::ICMP_SLT, Op0Src, Constant::getNullValue (SrcTy) );
4152
4146
}
4153
4147
4154
4148
static bool isNeutralValue (Instruction::BinaryOps BinaryOp, Value *RHS) {
0 commit comments