mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2026-04-24 13:18:17 +00:00
Bug 21610: Canonicalize min/max fcmp selects to use ordered comparisons
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222705 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -928,8 +928,22 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||
!CFPf->getValueAPF().isZero()))
|
||||
return ReplaceInstUsesWith(SI, TrueVal);
|
||||
}
|
||||
// NOTE: if we wanted to, this is where to detect MIN/MAX
|
||||
|
||||
// Canonicalize to use ordered comparisons by swapping the select
|
||||
// operands.
|
||||
//
|
||||
// e.g.
|
||||
// (X ugt Y) ? X : Y -> (X ole Y) ? Y : X
|
||||
if (FCI->hasOneUse() && FCmpInst::isUnordered(FCI->getPredicate())) {
|
||||
FCmpInst::Predicate InvPred = FCI->getInversePredicate();
|
||||
Value *NewCond = Builder->CreateFCmp(InvPred, TrueVal, FalseVal,
|
||||
FCI->getName() + ".inv");
|
||||
|
||||
return SelectInst::Create(NewCond, FalseVal, TrueVal,
|
||||
SI.getName() + ".p");
|
||||
}
|
||||
|
||||
// NOTE: if we wanted to, this is where to detect MIN/MAX
|
||||
} else if (FCI->getOperand(0) == FalseVal && FCI->getOperand(1) == TrueVal){
|
||||
// Transform (X == Y) ? Y : X -> X
|
||||
if (FCI->getPredicate() == FCmpInst::FCMP_OEQ) {
|
||||
@@ -955,6 +969,21 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
|
||||
!CFPf->getValueAPF().isZero()))
|
||||
return ReplaceInstUsesWith(SI, TrueVal);
|
||||
}
|
||||
|
||||
// Canonicalize to use ordered comparisons by swapping the select
|
||||
// operands.
|
||||
//
|
||||
// e.g.
|
||||
// (X ugt Y) ? X : Y -> (X ole Y) ? X : Y
|
||||
if (FCI->hasOneUse() && FCmpInst::isUnordered(FCI->getPredicate())) {
|
||||
FCmpInst::Predicate InvPred = FCI->getInversePredicate();
|
||||
Value *NewCond = Builder->CreateFCmp(InvPred, FalseVal, TrueVal,
|
||||
FCI->getName() + ".inv");
|
||||
|
||||
return SelectInst::Create(NewCond, FalseVal, TrueVal,
|
||||
SI.getName() + ".p");
|
||||
}
|
||||
|
||||
// NOTE: if we wanted to, this is where to detect MIN/MAX
|
||||
}
|
||||
// NOTE: if we wanted to, this is where to detect ABS
|
||||
|
||||
Reference in New Issue
Block a user