@@ -2213,31 +2213,29 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
2213
2213
2214
2214
const APInt &RHSV = RHS->getValue ();
2215
2215
bool isICMP_NE = ICI.getPredicate () == ICmpInst::ICMP_NE;
2216
+ Value *BOp0 = BO->getOperand (0 ), *BOp1 = BO->getOperand (1 );
2216
2217
2217
2218
switch (BO->getOpcode ()) {
2218
2219
case Instruction::SRem:
2219
2220
// 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 ();
2222
2223
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 ());
2225
2225
return new ICmpInst (ICI.getPredicate (), NewRem,
2226
2226
Constant::getNullValue (BO->getType ()));
2227
2227
}
2228
2228
}
2229
2229
break ;
2230
2230
case Instruction::Add:
2231
2231
// 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 )) {
2233
2233
if (BO->hasOneUse ())
2234
- return new ICmpInst (ICI.getPredicate (), BO-> getOperand ( 0 ) ,
2234
+ return new ICmpInst (ICI.getPredicate (), BOp0 ,
2235
2235
ConstantExpr::getSub (RHS, BOp1C));
2236
2236
} else if (RHSV == 0 ) {
2237
2237
// Replace ((add A, B) != 0) with (A != -B) if A or B is
2238
2238
// efficiently invertible, or if the add has just this one use.
2239
- Value *BOp0 = BO->getOperand (0 ), *BOp1 = BO->getOperand (1 );
2240
-
2241
2239
if (Value *NegVal = dyn_castNegVal (BOp1))
2242
2240
return new ICmpInst (ICI.getPredicate (), BOp0, NegVal);
2243
2241
if (Value *NegVal = dyn_castNegVal (BOp0))
@@ -2251,35 +2249,33 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
2251
2249
break ;
2252
2250
case Instruction::Xor:
2253
2251
if (BO->hasOneUse ()) {
2254
- if (Constant *BOC = dyn_cast<Constant>(BO-> getOperand ( 1 ) )) {
2252
+ if (Constant *BOC = dyn_cast<Constant>(BOp1 )) {
2255
2253
// For the xor case, we can xor two constants together, eliminating
2256
2254
// the explicit xor.
2257
- return new ICmpInst (ICI.getPredicate (), BO-> getOperand ( 0 ) ,
2255
+ return new ICmpInst (ICI.getPredicate (), BOp0 ,
2258
2256
ConstantExpr::getXor (RHS, BOC));
2259
2257
} else if (RHSV == 0 ) {
2260
2258
// 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);
2263
2260
}
2264
2261
}
2265
2262
break ;
2266
2263
case Instruction::Sub:
2267
2264
if (BO->hasOneUse ()) {
2268
- if (ConstantInt *BOp0C = dyn_cast<ConstantInt>(BO-> getOperand ( 0 ) )) {
2265
+ if (ConstantInt *BOp0C = dyn_cast<ConstantInt>(BOp0 )) {
2269
2266
// 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 ,
2271
2268
ConstantExpr::getSub (BOp0C, RHS));
2272
2269
} else if (RHSV == 0 ) {
2273
2270
// 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);
2276
2272
}
2277
2273
}
2278
2274
break ;
2279
2275
case Instruction::Or:
2280
2276
// If bits are being or'd in that are not present in the constant we
2281
2277
// 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 )) {
2283
2279
Constant *NotCI = ConstantExpr::getNot (RHS);
2284
2280
if (!ConstantExpr::getAnd (BOC, NotCI)->isNullValue ())
2285
2281
return replaceInstUsesWith (ICI, Builder->getInt1 (isICMP_NE));
@@ -2289,14 +2285,14 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
2289
2285
// This removes the -1 constant.
2290
2286
if (BO->hasOneUse () && RHS->isAllOnesValue ()) {
2291
2287
Constant *NotBOC = ConstantExpr::getNot (BOC);
2292
- Value *And = Builder->CreateAnd (BO-> getOperand ( 0 ) , NotBOC);
2288
+ Value *And = Builder->CreateAnd (BOp0 , NotBOC);
2293
2289
return new ICmpInst (ICI.getPredicate (), And, NotBOC);
2294
2290
}
2295
2291
}
2296
2292
break ;
2297
2293
2298
2294
case Instruction::And:
2299
- if (ConstantInt *BOC = dyn_cast<ConstantInt>(BO-> getOperand ( 1 ) )) {
2295
+ if (ConstantInt *BOC = dyn_cast<ConstantInt>(BOp1 )) {
2300
2296
// If bits are being compared against that are and'd out, then the
2301
2297
// comparison can never succeed!
2302
2298
if ((RHSV & ~BOC->getValue ()) != 0 )
@@ -2313,31 +2309,29 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
2313
2309
2314
2310
// Replace (and X, (1 << size(X)-1) != 0) with x s< 0
2315
2311
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 =
2319
2314
isICMP_NE ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_SGE;
2320
- return new ICmpInst (pred, X , Zero);
2315
+ return new ICmpInst (Pred, BOp0 , Zero);
2321
2316
}
2322
2317
2323
2318
// ((X & ~7) == 0) --> X < 8
2324
2319
if (RHSV == 0 && isHighOnes (BOC)) {
2325
- Value *X = BO->getOperand (0 );
2326
2320
Constant *NegX = ConstantExpr::getNeg (BOC);
2327
- ICmpInst::Predicate pred =
2321
+ ICmpInst::Predicate Pred =
2328
2322
isICMP_NE ? ICmpInst::ICMP_UGE : ICmpInst::ICMP_ULT;
2329
- return new ICmpInst (pred, X , NegX);
2323
+ return new ICmpInst (Pred, BOp0 , NegX);
2330
2324
}
2331
2325
}
2332
2326
break ;
2333
2327
case Instruction::Mul:
2334
2328
if (RHSV == 0 && BO->hasNoSignedWrap ()) {
2335
- if (ConstantInt *BOC = dyn_cast<ConstantInt>(BO-> getOperand ( 1 ) )) {
2329
+ if (ConstantInt *BOC = dyn_cast<ConstantInt>(BOp1 )) {
2336
2330
// The trivial case (mul X, 0) is handled by InstSimplify
2337
2331
// General case : (mul X, C) != 0 iff X != 0
2338
2332
// (mul X, C) == 0 iff X == 0
2339
2333
if (!BOC->isZero ())
2340
- return new ICmpInst (ICI.getPredicate (), BO-> getOperand ( 0 ) ,
2334
+ return new ICmpInst (ICI.getPredicate (), BOp0 ,
2341
2335
Constant::getNullValue (RHS->getType ()));
2342
2336
}
2343
2337
}
@@ -2347,7 +2341,7 @@ Instruction *InstCombiner::foldICmpEqualityWithConstant(ICmpInst &ICI) {
2347
2341
// (icmp eq/ne (udiv A, B), 0) -> (icmp ugt/ule i32 B, A)
2348
2342
ICmpInst::Predicate Pred =
2349
2343
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 );
2351
2345
}
2352
2346
break ;
2353
2347
default :
0 commit comments