From: Simon Pilgrim Date: Mon, 11 Mar 2019 15:01:31 +0000 (+0000) Subject: [DAG] TargetLowering::SimplifySetCC - call FoldSetCC early to handle constant/commute... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=71dcb3c2106b5548b743390fada18110e7161565;p=llvm [DAG] TargetLowering::SimplifySetCC - call FoldSetCC early to handle constant/commute folds. Noticed while looking at PR40800 (and also D57921) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355828 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/lib/CodeGen/SelectionDAG/TargetLowering.cpp index c4b46dd9f3d..093e35b86cb 100644 --- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -2353,14 +2353,9 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1, SelectionDAG &DAG = DCI.DAG; EVT OpVT = N0.getValueType(); - // These setcc operations always fold. - switch (Cond) { - default: break; - case ISD::SETFALSE: - case ISD::SETFALSE2: return DAG.getBoolConstant(false, dl, VT, OpVT); - case ISD::SETTRUE: - case ISD::SETTRUE2: return DAG.getBoolConstant(true, dl, VT, OpVT); - } + // Constant fold or commute setcc. + if (SDValue Fold = DAG.FoldSetCC(VT, N0, N1, Cond, dl)) + return Fold; // Ensure that the constant occurs on the RHS and fold constant comparisons. // TODO: Handle non-splat vector constants. All undef causes trouble. @@ -2947,11 +2942,9 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1, } } - if (isa(N0.getNode())) { - // Constant fold or commute setcc. - SDValue O = DAG.FoldSetCC(VT, N0, N1, Cond, dl); - if (O.getNode()) return O; - } else if (auto *CFP = dyn_cast(N1.getNode())) { + if (!isa(N0) && isa(N1)) { + auto *CFP = cast(N1); + // If the RHS of an FP comparison is a constant, simplify it away in // some cases. if (CFP->getValueAPF().isNaN()) {