@@ -4284,6 +4284,10 @@ static Value *simplifyWithOpsReplaced(Value *V,
42844284 assert ((AllowRefinement || !Q.CanUseUndef ) &&
42854285 " If AllowRefinement=false then CanUseUndef=false" );
42864286 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+
42874291 // Trivial replacement.
42884292 if (V == OpAndRepOp.first )
42894293 return OpAndRepOp.second ;
@@ -4309,30 +4313,20 @@ static Value *simplifyWithOpsReplaced(Value *V,
43094313 if (isa<FreezeInst>(I))
43104314 return nullptr ;
43114315
4312- SmallVector<std::pair<Value *, Value *>> ValidReplacements{};
43134316 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-
43184317 // For vector types, the simplification must hold per-lane, so forbid
43194318 // potentially cross-lane operations like shufflevector.
43204319 if (OpAndRepOp.first ->getType ()->isVectorTy () &&
43214320 !isNotCrossLaneOperation (I))
4322- continue ;
4323- ValidReplacements.emplace_back (OpAndRepOp);
4321+ return nullptr ;
43244322 }
43254323
4326- if (ValidReplacements.empty ())
4327- return nullptr ;
4328-
43294324 // Replace Op with RepOp in instruction operands.
43304325 SmallVector<Value *, 8 > NewOps;
43314326 bool AnyReplaced = false ;
43324327 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)) {
43364330 NewOps.push_back (NewInstOp);
43374331 AnyReplaced = InstOp != NewInstOp;
43384332 } else {
@@ -4383,9 +4377,8 @@ static Value *simplifyWithOpsReplaced(Value *V,
43834377 // by assumption and this case never wraps, so nowrap flags can be
43844378 // ignored.
43854379 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 ; }))
43894382 return Constant::getNullValue (I->getType ());
43904383
43914384 // If we are substituting an absorber constant into a binop and extra
@@ -4397,7 +4390,7 @@ static Value *simplifyWithOpsReplaced(Value *V,
43974390 // (Op == -1) ? -1 : (Op | (binop C, Op) --> Op | (binop C, Op)
43984391 Constant *Absorber = ConstantExpr::getBinOpAbsorber (Opcode, I->getType ());
43994392 if ((NewOps[0 ] == Absorber || NewOps[1 ] == Absorber) &&
4400- any_of (ValidReplacements ,
4393+ any_of (Ops ,
44014394 [=](const auto &Rep) { return impliesPoison (BO, Rep.first ); }))
44024395 return Absorber;
44034396 }
0 commit comments