@@ -4284,6 +4284,10 @@ static Value *simplifyWithOpsReplaced(Value *V,
4284
4284
assert ((AllowRefinement || !Q.CanUseUndef ) &&
4285
4285
" If AllowRefinement=false then CanUseUndef=false" );
4286
4286
for (const auto &OpAndRepOp : Ops) {
4287
+ // We cannot replace a constant, and shouldn't even try.
4288
+ if (isa<Constant>(OpAndRepOp.first ))
4289
+ return nullptr ;
4290
+
4287
4291
// Trivial replacement.
4288
4292
if (V == OpAndRepOp.first )
4289
4293
return OpAndRepOp.second ;
@@ -4309,30 +4313,20 @@ static Value *simplifyWithOpsReplaced(Value *V,
4309
4313
if (isa<FreezeInst>(I))
4310
4314
return nullptr ;
4311
4315
4312
- SmallVector<std::pair<Value *, Value *>> ValidReplacements{};
4313
4316
for (const auto &OpAndRepOp : Ops) {
4314
- // We cannot replace a constant, and shouldn't even try.
4315
- if (isa<Constant>(OpAndRepOp.first ))
4316
- return nullptr ;
4317
-
4318
4317
// For vector types, the simplification must hold per-lane, so forbid
4319
4318
// potentially cross-lane operations like shufflevector.
4320
4319
if (OpAndRepOp.first ->getType ()->isVectorTy () &&
4321
4320
!isNotCrossLaneOperation (I))
4322
- continue ;
4323
- ValidReplacements.emplace_back (OpAndRepOp);
4321
+ return nullptr ;
4324
4322
}
4325
4323
4326
- if (ValidReplacements.empty ())
4327
- return nullptr ;
4328
-
4329
4324
// Replace Op with RepOp in instruction operands.
4330
4325
SmallVector<Value *, 8 > NewOps;
4331
4326
bool AnyReplaced = false ;
4332
4327
for (Value *InstOp : I->operands ()) {
4333
- if (Value *NewInstOp =
4334
- simplifyWithOpsReplaced (InstOp, ValidReplacements, Q,
4335
- AllowRefinement, DropFlags, MaxRecurse)) {
4328
+ if (Value *NewInstOp = simplifyWithOpsReplaced (
4329
+ InstOp, Ops, Q, AllowRefinement, DropFlags, MaxRecurse)) {
4336
4330
NewOps.push_back (NewInstOp);
4337
4331
AnyReplaced = InstOp != NewInstOp;
4338
4332
} else {
@@ -4383,9 +4377,8 @@ static Value *simplifyWithOpsReplaced(Value *V,
4383
4377
// by assumption and this case never wraps, so nowrap flags can be
4384
4378
// ignored.
4385
4379
if ((Opcode == Instruction::Sub || Opcode == Instruction::Xor) &&
4386
- any_of (ValidReplacements, [=](const auto &Rep) {
4387
- return NewOps[0 ] == NewOps[1 ] && NewOps[0 ] == Rep.second ;
4388
- }))
4380
+ NewOps[0 ] == NewOps[1 ] &&
4381
+ any_of (Ops, [=](const auto &Rep) { return NewOps[0 ] == Rep.second ; }))
4389
4382
return Constant::getNullValue (I->getType ());
4390
4383
4391
4384
// If we are substituting an absorber constant into a binop and extra
@@ -4397,7 +4390,7 @@ static Value *simplifyWithOpsReplaced(Value *V,
4397
4390
// (Op == -1) ? -1 : (Op | (binop C, Op) --> Op | (binop C, Op)
4398
4391
Constant *Absorber = ConstantExpr::getBinOpAbsorber (Opcode, I->getType ());
4399
4392
if ((NewOps[0 ] == Absorber || NewOps[1 ] == Absorber) &&
4400
- any_of (ValidReplacements ,
4393
+ any_of (Ops ,
4401
4394
[=](const auto &Rep) { return impliesPoison (BO, Rep.first ); }))
4402
4395
return Absorber;
4403
4396
}
0 commit comments