Skip to content

Commit

Permalink
Propagate fmf for setcc/select folds
Browse files Browse the repository at this point in the history
Summary: This change facilitates propagating fmf which was placed on setcc from fcmp through folds with selects so that back ends can model this path for arithmetic folds on selects in SDAG.

Reviewers: qcolombet, spatel

Reviewed By: qcolombet

Subscribers: nemanjai, jsji

Differential Revision: https://reviews.llvm.org/D62552

llvm-svn: 362439
  • Loading branch information
Michael Berg committed Jun 3, 2019
1 parent bad43d8 commit 0b7f98d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7941,9 +7941,16 @@ SDValue DAGCombiner::visitSELECT(SDNode *N) {
}

if (TLI.isOperationLegal(ISD::SELECT_CC, VT) ||
(!LegalOperations && TLI.isOperationLegalOrCustom(ISD::SELECT_CC, VT)))
return DAG.getNode(ISD::SELECT_CC, DL, VT, Cond0, Cond1, N1, N2,
N0.getOperand(2));
(!LegalOperations &&
TLI.isOperationLegalOrCustom(ISD::SELECT_CC, VT))) {
// Any flags available in a select/setcc fold will be on the setcc as they
// migrated from fcmp
const SDNodeFlags Flags = N0.getNode()->getFlags();
SDValue SelectNode = DAG.getNode(ISD::SELECT_CC, DL, VT, Cond0, Cond1, N1,
N2, N0.getOperand(2));
SelectNode->setFlags(Flags);
return SelectNode;
}

return SimplifySelect(DL, N0, N1, N2);
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/PowerPC/fmf-propagation.ll
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ define float @sqrt_fast(float %x) {
; fcmp can have fast-math-flags.

; FMFDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fcmp_nnan:'
; FMFDEBUG: select_cc {{t[0-9]+}}
; FMFDEBUG: select_cc nnan {{t[0-9]+}}
; FMFDEBUG: Type-legalized selection DAG: %bb.0 'fcmp_nnan:'

; GLOBALDEBUG-LABEL: Optimized lowered selection DAG: %bb.0 'fcmp_nnan:'
; GLOBALDEBUG: select_cc {{t[0-9]+}}
; GLOBALDEBUG: select_cc nnan {{t[0-9]+}}
; GLOBALDEBUG: Type-legalized selection DAG: %bb.0 'fcmp_nnan:'

define double @fcmp_nnan(double %a, double %y, double %z) {
Expand Down

0 comments on commit 0b7f98d

Please sign in to comment.