diff options
| author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2019-04-05 14:56:21 +0000 | 
|---|---|---|
| committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2019-04-05 14:56:21 +0000 | 
| commit | 17586cda4adda536af2631ff83dcb49d2dceaa2f (patch) | |
| tree | 691202d0aef81a6dd78eaaefa5faf1cb6afc57cb /llvm/lib/CodeGen/SelectionDAG | |
| parent | 84f2271acd818e50c598fef7ce9586e7ee0ac553 (diff) | |
| download | bcm5719-llvm-17586cda4adda536af2631ff83dcb49d2dceaa2f.tar.gz bcm5719-llvm-17586cda4adda536af2631ff83dcb49d2dceaa2f.zip | |
[SelectionDAG] Add fcmp UNDEF handling to SelectionDAG::FoldSetCC
Second half of PR40800, this patch adds DAG undef handling to fcmp instructions to match the behavior in llvm::ConstantFoldCompareInstruction, this permits constant folding of vector comparisons where some elements had been reduced to UNDEF (by SimplifyDemandedVectorElts etc.).
This involves a lot of tweaking to reduced tests as bugpoint loves to reduce fcmp arguments to undef........
Differential Revision: https://reviews.llvm.org/D60006
llvm-svn: 357765
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 11 | 
1 files changed, 8 insertions, 3 deletions
| diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 148a3805b3b..caa3f14b8a1 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -2085,14 +2085,19 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,      case ISD::SETUGE: return getBoolConstant(R!=APFloat::cmpLessThan, dl, VT,                                               OpVT);      } -  } else if (N1CFP && OpVT.isSimple()) { +  } else if (N1CFP && OpVT.isSimple() && !N2.isUndef()) {      // Ensure that the constant occurs on the RHS.      ISD::CondCode SwappedCond = ISD::getSetCCSwappedOperands(Cond);      if (!TLI->isCondCodeLegal(SwappedCond, OpVT.getSimpleVT()))        return SDValue();      return getSetCC(dl, VT, N2, N1, SwappedCond); -  } else if (N2CFP && N2CFP->getValueAPF().isNaN()) { -    // If an operand is known to be a nan, we can fold it. +  } else if ((N2CFP && N2CFP->getValueAPF().isNaN()) || +             (OpVT.isFloatingPoint() && (N1.isUndef() || N2.isUndef()))) { +    // If an operand is known to be a nan (or undef that could be a nan), we can +    // fold it. +    // Choosing NaN for the undef will always make unordered comparison succeed +    // and ordered comparison fails. +    // Matches behavior in llvm::ConstantFoldCompareInstruction.      switch (ISD::getUnorderedFlavor(Cond)) {      default:        llvm_unreachable("Unknown flavor!"); | 

