Skip to content

Commit 2f8d9fa

Browse files
committed
Remove UnsafeFPMath in visitFP_ROUND
1 parent 05b4a43 commit 2f8d9fa

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
@@ -18922,7 +18922,7 @@ SDValue DAGCombiner::visitFP_ROUND(SDNode *N) {
1892218922
// single-step fp_round we want to fold to.
1892318923
// In other words, double rounding isn't the same as rounding.
1892418924
// Also, this is a value preserving truncation iff both fp_round's are.
18925-
if (DAG.getTarget().Options.UnsafeFPMath || N0IsTrunc)
18925+
if (N->getFlags().hasAllowContract() || N0IsTrunc)
1892618926
return DAG.getNode(
1892718927
ISD::FP_ROUND, DL, VT, N0.getOperand(0),
1892818928
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)