[llvm] r326828 - [InstCombine] simplify min/max canonicalization; NFCI
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 6 11:01:18 PST 2018
Author: spatel
Date: Tue Mar 6 11:01:18 2018
New Revision: 326828
URL: http://llvm.org/viewvc/llvm-project?rev=326828&view=rev
Log:
[InstCombine] simplify min/max canonicalization; NFCI
Modified:
llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp?rev=326828&r1=326827&r2=326828&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSelect.cpp Tue Mar 6 11:01:18 2018
@@ -713,23 +713,18 @@ canonicalizeMinMaxWithConstant(SelectIns
// Canonicalize the compare predicate based on whether we have min or max.
Value *LHS, *RHS;
- ICmpInst::Predicate NewPred;
SelectPatternResult SPR = matchSelectPattern(&Sel, LHS, RHS);
- switch (SPR.Flavor) {
- case SPF_SMIN: NewPred = ICmpInst::ICMP_SLT; break;
- case SPF_UMIN: NewPred = ICmpInst::ICMP_ULT; break;
- case SPF_SMAX: NewPred = ICmpInst::ICMP_SGT; break;
- case SPF_UMAX: NewPred = ICmpInst::ICMP_UGT; break;
- default: return nullptr;
- }
+ if (!SelectPatternResult::isMinOrMax(SPR.Flavor))
+ return nullptr;
// Is this already canonical?
+ ICmpInst::Predicate CanonicalPred = getMinMaxPred(SPR.Flavor);
if (Cmp.getOperand(0) == LHS && Cmp.getOperand(1) == RHS &&
- Cmp.getPredicate() == NewPred)
+ Cmp.getPredicate() == CanonicalPred)
return nullptr;
// Create the canonical compare and plug it into the select.
- Sel.setCondition(Builder.CreateICmp(NewPred, LHS, RHS));
+ Sel.setCondition(Builder.CreateICmp(CanonicalPred, LHS, RHS));
// If the select operands did not change, we're done.
if (Sel.getTrueValue() == LHS && Sel.getFalseValue() == RHS)
More information about the llvm-commits
mailing list