Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 3f2fe11

Browse files
committed
use local variables; NFC
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@277612 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 406cfb6 commit 3f2fe11

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,31 +2213,29 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
22132213

22142214
const APInt &RHSV = RHS->getValue();
22152215
bool isICMP_NE = ICI.getPredicate() == ICmpInst::ICMP_NE;
2216+
Value *BOp0 = BO->getOperand(0), *BOp1 = BO->getOperand(1);
22162217

22172218
switch (BO->getOpcode()) {
22182219
case Instruction::SRem:
22192220
// If we have a signed (X % (2^c)) == 0, turn it into an unsigned one.
2220-
if (RHSV == 0 && isa<ConstantInt>(BO->getOperand(1)) && BO->hasOneUse()) {
2221-
const APInt &V = cast<ConstantInt>(BO->getOperand(1))->getValue();
2221+
if (RHSV == 0 && isa<ConstantInt>(BOp1) && BO->hasOneUse()) {
2222+
const APInt &V = cast<ConstantInt>(BOp1)->getValue();
22222223
if (V.sgt(1) && V.isPowerOf2()) {
2223-
Value *NewRem = Builder->CreateURem(BO->getOperand(0),
2224-
BO->getOperand(1), BO->getName());
2224+
Value *NewRem = Builder->CreateURem(BOp0, BOp1, BO->getName());
22252225
return new ICmpInst(ICI.getPredicate(), NewRem,
22262226
Constant::getNullValue(BO->getType()));
22272227
}
22282228
}
22292229
break;
22302230
case Instruction::Add:
22312231
// Replace ((add A, B) != C) with (A != C-B) if B & C are constants.
2232-
if (ConstantInt *BOp1C = dyn_cast<ConstantInt>(BO->getOperand(1))) {
2232+
if (ConstantInt *BOp1C = dyn_cast<ConstantInt>(BOp1)) {
22332233
if (BO->hasOneUse())
2234-
return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
2234+
return new ICmpInst(ICI.getPredicate(), BOp0,
22352235
ConstantExpr::getSub(RHS, BOp1C));
22362236
} else if (RHSV == 0) {
22372237
// Replace ((add A, B) != 0) with (A != -B) if A or B is
22382238
// efficiently invertible, or if the add has just this one use.
2239-
Value *BOp0 = BO->getOperand(0), *BOp1 = BO->getOperand(1);
2240-
22412239
if (Value *NegVal = dyn_castNegVal(BOp1))
22422240
return new ICmpInst(ICI.getPredicate(), BOp0, NegVal);
22432241
if (Value *NegVal = dyn_castNegVal(BOp0))
@@ -2251,35 +2249,33 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
22512249
break;
22522250
case Instruction::Xor:
22532251
if (BO->hasOneUse()) {
2254-
if (Constant *BOC = dyn_cast<Constant>(BO->getOperand(1))) {
2252+
if (Constant *BOC = dyn_cast<Constant>(BOp1)) {
22552253
// For the xor case, we can xor two constants together, eliminating
22562254
// the explicit xor.
2257-
return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
2255+
return new ICmpInst(ICI.getPredicate(), BOp0,
22582256
ConstantExpr::getXor(RHS, BOC));
22592257
} else if (RHSV == 0) {
22602258
// Replace ((xor A, B) != 0) with (A != B)
2261-
return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
2262-
BO->getOperand(1));
2259+
return new ICmpInst(ICI.getPredicate(), BOp0, BOp1);
22632260
}
22642261
}
22652262
break;
22662263
case Instruction::Sub:
22672264
if (BO->hasOneUse()) {
2268-
if (ConstantInt *BOp0C = dyn_cast<ConstantInt>(BO->getOperand(0))) {
2265+
if (ConstantInt *BOp0C = dyn_cast<ConstantInt>(BOp0)) {
22692266
// Replace ((sub A, B) != C) with (B != A-C) if A & C are constants.
2270-
return new ICmpInst(ICI.getPredicate(), BO->getOperand(1),
2267+
return new ICmpInst(ICI.getPredicate(), BOp1,
22712268
ConstantExpr::getSub(BOp0C, RHS));
22722269
} else if (RHSV == 0) {
22732270
// Replace ((sub A, B) != 0) with (A != B)
2274-
return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
2275-
BO->getOperand(1));
2271+
return new ICmpInst(ICI.getPredicate(), BOp0, BOp1);
22762272
}
22772273
}
22782274
break;
22792275
case Instruction::Or:
22802276
// If bits are being or'd in that are not present in the constant we
22812277
// are comparing against, then the comparison could never succeed!
2282-
if (ConstantInt *BOC = dyn_cast<ConstantInt>(BO->getOperand(1))) {
2278+
if (ConstantInt *BOC = dyn_cast<ConstantInt>(BOp1)) {
22832279
Constant *NotCI = ConstantExpr::getNot(RHS);
22842280
if (!ConstantExpr::getAnd(BOC, NotCI)->isNullValue())
22852281
return replaceInstUsesWith(ICI, Builder->getInt1(isICMP_NE));
@@ -2289,14 +2285,14 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
22892285
// This removes the -1 constant.
22902286
if (BO->hasOneUse() && RHS->isAllOnesValue()) {
22912287
Constant *NotBOC = ConstantExpr::getNot(BOC);
2292-
Value *And = Builder->CreateAnd(BO->getOperand(0), NotBOC);
2288+
Value *And = Builder->CreateAnd(BOp0, NotBOC);
22932289
return new ICmpInst(ICI.getPredicate(), And, NotBOC);
22942290
}
22952291
}
22962292
break;
22972293

22982294
case Instruction::And:
2299-
if (ConstantInt *BOC = dyn_cast<ConstantInt>(BO->getOperand(1))) {
2295+
if (ConstantInt *BOC = dyn_cast<ConstantInt>(BOp1)) {
23002296
// If bits are being compared against that are and'd out, then the
23012297
// comparison can never succeed!
23022298
if ((RHSV & ~BOC->getValue()) != 0)
@@ -2313,31 +2309,29 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
23132309

23142310
// Replace (and X, (1 << size(X)-1) != 0) with x s< 0
23152311
if (BOC->getValue().isSignBit()) {
2316-
Value *X = BO->getOperand(0);
2317-
Constant *Zero = Constant::getNullValue(X->getType());
2318-
ICmpInst::Predicate pred =
2312+
Constant *Zero = Constant::getNullValue(BOp0->getType());
2313+
ICmpInst::Predicate Pred =
23192314
isICMP_NE ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_SGE;
2320-
return new ICmpInst(pred, X, Zero);
2315+
return new ICmpInst(Pred, BOp0, Zero);
23212316
}
23222317

23232318
// ((X & ~7) == 0) --> X < 8
23242319
if (RHSV == 0 && isHighOnes(BOC)) {
2325-
Value *X = BO->getOperand(0);
23262320
Constant *NegX = ConstantExpr::getNeg(BOC);
2327-
ICmpInst::Predicate pred =
2321+
ICmpInst::Predicate Pred =
23282322
isICMP_NE ? ICmpInst::ICMP_UGE : ICmpInst::ICMP_ULT;
2329-
return new ICmpInst(pred, X, NegX);
2323+
return new ICmpInst(Pred, BOp0, NegX);
23302324
}
23312325
}
23322326
break;
23332327
case Instruction::Mul:
23342328
if (RHSV == 0 && BO->hasNoSignedWrap()) {
2335-
if (ConstantInt *BOC = dyn_cast<ConstantInt>(BO->getOperand(1))) {
2329+
if (ConstantInt *BOC = dyn_cast<ConstantInt>(BOp1)) {
23362330
// The trivial case (mul X, 0) is handled by InstSimplify
23372331
// General case : (mul X, C) != 0 iff X != 0
23382332
// (mul X, C) == 0 iff X == 0
23392333
if (!BOC->isZero())
2340-
return new ICmpInst(ICI.getPredicate(), BO->getOperand(0),
2334+
return new ICmpInst(ICI.getPredicate(), BOp0,
23412335
Constant::getNullValue(RHS->getType()));
23422336
}
23432337
}
@@ -2347,7 +2341,7 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
23472341
// (icmp eq/ne (udiv A, B), 0) -> (icmp ugt/ule i32 B, A)
23482342
ICmpInst::Predicate Pred =
23492343
isICMP_NE ? ICmpInst::ICMP_ULE : ICmpInst::ICMP_UGT;
2350-
return new ICmpInst(Pred, BO->getOperand(1), BO->getOperand(0));
2344+
return new ICmpInst(Pred, BOp1, BOp0);
23512345
}
23522346
break;
23532347
default:

0 commit comments

Comments
 (0)