Skip to content

Commit 8b13f3d

Browse files
committed
Remove UnsafeFPMath in visitFP_ROUND
1 parent 2de50fe commit 8b13f3d

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18860,7 +18860,7 @@ SDValue DAGCombiner::visitFP_ROUND(SDNode *N) {
1886018860
// single-step fp_round we want to fold to.
1886118861
// In other words, double rounding isn't the same as rounding.
1886218862
// Also, this is a value preserving truncation iff both fp_round's are.
18863-
if (DAG.getTarget().Options.UnsafeFPMath || N0IsTrunc)
18863+
if (N->getFlags().hasAllowContract() || N0IsTrunc)
1886418864
return DAG.getNode(
1886518865
ISD::FP_ROUND, DL, VT, N0.getOperand(0),
1886618866
DAG.getIntPtrConstant(NIsTrunc && N0IsTrunc, DL, /*isTarget=*/true));

llvm/test/CodeGen/X86/fp-double-rounding.ll

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@
44
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
55
target triple = "x86_64--"
66

7-
; CHECK-LABEL: double_rounding:
7+
; CHECK-LABEL: double_rounding_safe:
88
; SAFE: callq __trunctfdf2
99
; SAFE-NEXT: cvtsd2ss %xmm0
10+
define void @double_rounding_safe(ptr %x, ptr %f) {
11+
entry:
12+
%0 = load fp128, ptr %x, align 16
13+
%1 = fptrunc fp128 %0 to double
14+
%2 = fptrunc double %1 to float
15+
store float %2, ptr %f, align 4
16+
ret void
17+
}
18+
; CHECK-LABEL: double_rounding:
1019
; UNSAFE: callq __trunctfsf2
1120
; UNSAFE-NOT: cvt
1221
define void @double_rounding(ptr %x, ptr %f) {
1322
entry:
1423
%0 = load fp128, ptr %x, align 16
15-
%1 = fptrunc fp128 %0 to double
16-
%2 = fptrunc double %1 to float
24+
%1 = fptrunc contract fp128 %0 to double
25+
%2 = fptrunc contract double %1 to float
1726
store float %2, ptr %f, align 4
1827
ret void
1928
}

0 commit comments

Comments
 (0)