}
break;
case Instruction::Add: {
- // Replace ((add A, B) != C) with (A != C-B) if B & C are constants.
- if (Constant *BOC = dyn_cast<Constant>(BOp1)) {
+ // (A + C2) == C --> A == (C - C2)
+ // (A + C2) != C --> A != (C - C2)
+ // TODO: Remove the one-use limitation? See discussion in D58633.
+ if (Constant *C2 = dyn_cast<Constant>(BOp1)) {
if (BO->hasOneUse())
- return new ICmpInst(Pred, BOp0, ConstantExpr::getSub(RHS, BOC));
+ return new ICmpInst(Pred, BOp0, ConstantExpr::getSub(RHS, C2));
} else if (C.isZero()) {
// Replace ((add A, B) != 0) with (A != -B) if A or B is
// efficiently invertible, or if the add has just this one use.