Skip to content

Commit

Permalink
[EarlyCSE] Simplify max/min pattern matching. NFC.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkbuck committed Sep 16, 2020
1 parent 0c6a56e commit 4e4c89b
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions llvm/lib/Transforms/Scalar/EarlyCSE.cpp
Expand Up @@ -191,25 +191,16 @@ static bool matchSelectWithOptionalNotCond(Value *V, Value *&Cond, Value *&A,
Pred = ICmpInst::getSwappedPredicate(Pred);
}

// Check for inverted variants of min/max by swapping operands.
bool Inversed = false;
switch (Pred) {
case CmpInst::ICMP_ULE:
case CmpInst::ICMP_UGE:
case CmpInst::ICMP_SLE:
case CmpInst::ICMP_SGE:
Pred = CmpInst::getInversePredicate(Pred);
Inversed = true;
break;
default:
break;
}

switch (Pred) {
case CmpInst::ICMP_UGT: Flavor = Inversed ? SPF_UMIN : SPF_UMAX; break;
case CmpInst::ICMP_ULT: Flavor = Inversed ? SPF_UMAX : SPF_UMIN; break;
case CmpInst::ICMP_SGT: Flavor = Inversed ? SPF_SMIN : SPF_SMAX; break;
case CmpInst::ICMP_SLT: Flavor = Inversed ? SPF_SMAX : SPF_SMIN; break;
case CmpInst::ICMP_UGT: Flavor = SPF_UMAX; break;
case CmpInst::ICMP_ULT: Flavor = SPF_UMIN; break;
case CmpInst::ICMP_SGT: Flavor = SPF_SMAX; break;
case CmpInst::ICMP_SLT: Flavor = SPF_SMIN; break;
// Non-strict inequalities.
case CmpInst::ICMP_ULE: Flavor = SPF_UMIN; break;
case CmpInst::ICMP_UGE: Flavor = SPF_UMAX; break;
case CmpInst::ICMP_SLE: Flavor = SPF_SMIN; break;
case CmpInst::ICMP_SGE: Flavor = SPF_SMAX; break;
default: break;
}

Expand Down

0 comments on commit 4e4c89b

Please sign in to comment.