@@ -2333,7 +2333,9 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
2333
2333
2334
2334
// See if we are selecting two values based on a comparison of the two values.
2335
2335
if (FCmpInst *FCI = dyn_cast<FCmpInst>(CondVal)) {
2336
- if (FCI->getOperand (0 ) == TrueVal && FCI->getOperand (1 ) == FalseVal) {
2336
+ Value *Cmp0 = FCI->getOperand (0 ), *Cmp1 = FCI->getOperand (1 );
2337
+ if ((Cmp0 == TrueVal && Cmp1 == FalseVal) ||
2338
+ (Cmp0 == FalseVal && Cmp1 == TrueVal)) {
2337
2339
// Canonicalize to use ordered comparisons by swapping the select
2338
2340
// operands.
2339
2341
//
@@ -2343,25 +2345,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
2343
2345
FCmpInst::Predicate InvPred = FCI->getInversePredicate ();
2344
2346
IRBuilder<>::FastMathFlagGuard FMFG (Builder);
2345
2347
Builder.setFastMathFlags (FCI->getFastMathFlags ());
2346
- Value *NewCond = Builder.CreateFCmp (InvPred, TrueVal, FalseVal,
2347
- FCI->getName () + " .inv" );
2348
-
2349
- return SelectInst::Create (NewCond, FalseVal, TrueVal,
2350
- SI.getName () + " .p" );
2351
- }
2352
-
2353
- // NOTE: if we wanted to, this is where to detect MIN/MAX
2354
- } else if (FCI->getOperand (0 ) == FalseVal && FCI->getOperand (1 ) == TrueVal){
2355
- // Canonicalize to use ordered comparisons by swapping the select
2356
- // operands.
2357
- //
2358
- // e.g.
2359
- // (X ugt Y) ? X : Y -> (X ole Y) ? X : Y
2360
- if (FCI->hasOneUse () && FCmpInst::isUnordered (FCI->getPredicate ())) {
2361
- FCmpInst::Predicate InvPred = FCI->getInversePredicate ();
2362
- IRBuilder<>::FastMathFlagGuard FMFG (Builder);
2363
- Builder.setFastMathFlags (FCI->getFastMathFlags ());
2364
- Value *NewCond = Builder.CreateFCmp (InvPred, FalseVal, TrueVal,
2348
+ Value *NewCond = Builder.CreateFCmp (InvPred, Cmp0, Cmp1,
2365
2349
FCI->getName () + " .inv" );
2366
2350
2367
2351
return SelectInst::Create (NewCond, FalseVal, TrueVal,
0 commit comments