Skip to content

Commit e7b41df

Browse files
[SelectionDAGBuilder] Propagate fast-math flags to fpext (#167574)
As in title. Without this, fpext behaves in selectionDAG as always having no fast-math flags.
1 parent 0fa6a67 commit e7b41df

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18673,11 +18673,13 @@ SDValue DAGCombiner::visitFDIV(SDNode *N) {
1867318673
if (Flags.hasAllowReciprocal()) {
1867418674
// If this FDIV is part of a reciprocal square root, it may be folded
1867518675
// into a target-specific square root estimate instruction.
18676+
bool N1AllowReciprocal = N1->getFlags().hasAllowReciprocal();
1867618677
if (N1.getOpcode() == ISD::FSQRT) {
1867718678
if (SDValue RV = buildRsqrtEstimate(N1.getOperand(0)))
1867818679
return DAG.getNode(ISD::FMUL, DL, VT, N0, RV);
1867918680
} else if (N1.getOpcode() == ISD::FP_EXTEND &&
18680-
N1.getOperand(0).getOpcode() == ISD::FSQRT) {
18681+
N1.getOperand(0).getOpcode() == ISD::FSQRT &&
18682+
N1AllowReciprocal) {
1868118683
if (SDValue RV = buildRsqrtEstimate(N1.getOperand(0).getOperand(0))) {
1868218684
RV = DAG.getNode(ISD::FP_EXTEND, SDLoc(N1), VT, RV);
1868318685
AddToWorklist(RV.getNode());

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3976,7 +3976,10 @@ void SelectionDAGBuilder::visitFPExt(const User &I) {
39763976
SDValue N = getValue(I.getOperand(0));
39773977
EVT DestVT = DAG.getTargetLoweringInfo().getValueType(DAG.getDataLayout(),
39783978
I.getType());
3979-
setValue(&I, DAG.getNode(ISD::FP_EXTEND, getCurSDLoc(), DestVT, N));
3979+
SDNodeFlags Flags;
3980+
if (auto *TruncInst = dyn_cast<FPMathOperator>(&I))
3981+
Flags.copyFMF(*TruncInst);
3982+
setValue(&I, DAG.getNode(ISD::FP_EXTEND, getCurSDLoc(), DestVT, N, Flags));
39803983
}
39813984

39823985
void SelectionDAGBuilder::visitFPToUI(const User &I) {

llvm/test/CodeGen/PowerPC/recipest.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ define double @foof_fmf(double %a, float %b) nounwind {
164164
; CHECK-P9-NEXT: xsmuldp f1, f1, f0
165165
; CHECK-P9-NEXT: blr
166166
%x = call contract reassoc arcp float @llvm.sqrt.f32(float %b)
167-
%y = fpext float %x to double
167+
%y = fpext arcp float %x to double
168168
%r = fdiv contract reassoc arcp double %a, %y
169169
ret double %r
170170
}

0 commit comments

Comments
 (0)