Skip to content

Commit

Permalink
[InstCombine] Remove SPF moveNotAfterMinMax() (NFC)
Browse files Browse the repository at this point in the history
This happens after SPF -> intrinsic canonicalization, and as such
should be entirely NFC.
  • Loading branch information
nikic committed Feb 28, 2022
1 parent 0bc3e23 commit ee62dcd
Showing 1 changed file with 0 additions and 34 deletions.
34 changes: 0 additions & 34 deletions llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2988,8 +2988,6 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
if (Instruction *R = foldSPFofSPF(cast<Instruction>(RHS), SPF2, LHS2,
RHS2, SI, SPF, LHS))
return R;
// TODO.
// ABS(-X) -> ABS(X)
}

if (SelectPatternResult::isMinOrMax(SPF)) {
Expand Down Expand Up @@ -3025,38 +3023,6 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
return replaceInstUsesWith(SI, NewCast);
}

// MAX(~a, ~b) -> ~MIN(a, b)
// MAX(~a, C) -> ~MIN(a, ~C)
// MIN(~a, ~b) -> ~MAX(a, b)
// MIN(~a, C) -> ~MAX(a, ~C)
auto moveNotAfterMinMax = [&](Value *X, Value *Y) -> Instruction * {
Value *A;
if (match(X, m_Not(m_Value(A))) && !X->hasNUsesOrMore(3) &&
!isFreeToInvert(A, A->hasOneUse()) &&
// Passing false to only consider m_Not and constants.
isFreeToInvert(Y, false)) {
Value *B = Builder.CreateNot(Y);
Value *NewMinMax = createMinMax(Builder, getInverseMinMaxFlavor(SPF),
A, B);
// Copy the profile metadata.
if (MDNode *MD = SI.getMetadata(LLVMContext::MD_prof)) {
cast<SelectInst>(NewMinMax)->setMetadata(LLVMContext::MD_prof, MD);
// Swap the metadata if the operands are swapped.
if (X == SI.getFalseValue() && Y == SI.getTrueValue())
cast<SelectInst>(NewMinMax)->swapProfMetadata();
}

return BinaryOperator::CreateNot(NewMinMax);
}

return nullptr;
};

if (Instruction *I = moveNotAfterMinMax(LHS, RHS))
return I;
if (Instruction *I = moveNotAfterMinMax(RHS, LHS))
return I;

if (Instruction *I = moveAddAfterMinMax(SPF, LHS, RHS, Builder))
return I;

Expand Down

0 comments on commit ee62dcd

Please sign in to comment.