1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-18 18:42:46 +02:00

[NFC][InstCombine] Extract freelyInvertAllUsersOf() out of canonicalizeICmpPredicate()

I'd like to use it in an upcoming fold.
This commit is contained in:
Roman Lebedev 2021-01-22 12:51:40 +03:00
parent 80ea20bdfe
commit 1cff9b2a83
4 changed files with 29 additions and 22 deletions

View File

@ -263,8 +263,7 @@ public:
}
/// Given i1 V, can every user of V be freely adapted if V is changed to !V ?
/// InstCombine's canonicalizeICmpPredicate() must be kept in sync with this
/// fn.
/// InstCombine's freelyInvertAllUsersOf() must be kept in sync with this fn.
///
/// See also: isFreeToInvert()
static bool canFreelyInvertAllUsersOf(Value *V, Value *IgnoredUser) {

View File

@ -5328,26 +5328,8 @@ CmpInst *InstCombinerImpl::canonicalizeICmpPredicate(CmpInst &I) {
I.setPredicate(CmpInst::getInversePredicate(Pred));
I.setName(I.getName() + ".not");
// And now let's adjust every user.
for (User *U : I.users()) {
switch (cast<Instruction>(U)->getOpcode()) {
case Instruction::Select: {
auto *SI = cast<SelectInst>(U);
SI->swapValues();
SI->swapProfMetadata();
break;
}
case Instruction::Br:
cast<BranchInst>(U)->swapSuccessors(); // swaps prof metadata too
break;
case Instruction::Xor:
replaceInstUsesWith(cast<Instruction>(*U), &I);
break;
default:
llvm_unreachable("Got unexpected user - out of sync with "
"canFreelyInvertAllUsersOf() ?");
}
}
// And, adapt users.
freelyInvertAllUsersOf(&I);
return &I;
}

View File

@ -323,6 +323,8 @@ private:
Instruction *optimizeBitCastFromPhi(CastInst &CI, PHINode *PN);
Instruction *matchSAddSubSat(SelectInst &MinMax1);
void freelyInvertAllUsersOf(Value *V);
/// Determine if a pair of casts can be replaced by a single cast.
///
/// \param CI1 The first of a pair of casts.

View File

@ -870,6 +870,30 @@ Value *InstCombinerImpl::SimplifySelectsFeedingBinaryOp(BinaryOperator &I,
return SI;
}
/// Freely adapt every user of V as-if V was changed to !V.
/// WARNING: only if canFreelyInvertAllUsersOf() said this can be done.
void InstCombinerImpl::freelyInvertAllUsersOf(Value *I) {
for (User *U : I->users()) {
switch (cast<Instruction>(U)->getOpcode()) {
case Instruction::Select: {
auto *SI = cast<SelectInst>(U);
SI->swapValues();
SI->swapProfMetadata();
break;
}
case Instruction::Br:
cast<BranchInst>(U)->swapSuccessors(); // swaps prof metadata too
break;
case Instruction::Xor:
replaceInstUsesWith(cast<Instruction>(*U), I);
break;
default:
llvm_unreachable("Got unexpected user - out of sync with "
"canFreelyInvertAllUsersOf() ?");
}
}
}
/// Given a 'sub' instruction, return the RHS of the instruction if the LHS is a
/// constant zero (which is the 'negate' form).
Value *InstCombinerImpl::dyn_castNegVal(Value *V) const {