Skip to content

Commit 781b78a

Browse files
committed
[PowerPC] Only legalize FNEARBYINT with unsafe fp math
Commit 0f0330a legalized these nodes on PPC without consideration of unsafe math which means that we get inexact exceptions raised for nearbyint. Since this doesn't conform to the standard, switch this legalization to depend on unsafe fp math.
1 parent af340ae commit 781b78a

File tree

3 files changed

+260
-81
lines changed

3 files changed

+260
-81
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,17 +782,22 @@ PPCTargetLowering::PPCTargetLowering(const PPCTargetMachine &TM,
782782
}
783783
setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2f64, Legal);
784784

785+
// The nearbyint variants are not allowed to raise the inexact exception
786+
// so we can only code-gen them with unsafe math.
787+
if (TM.Options.UnsafeFPMath) {
788+
setOperationAction(ISD::FNEARBYINT, MVT::f64, Legal);
789+
setOperationAction(ISD::FNEARBYINT, MVT::f32, Legal);
790+
}
791+
785792
setOperationAction(ISD::FFLOOR, MVT::v2f64, Legal);
786793
setOperationAction(ISD::FCEIL, MVT::v2f64, Legal);
787794
setOperationAction(ISD::FTRUNC, MVT::v2f64, Legal);
788795
setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Legal);
789796
setOperationAction(ISD::FROUND, MVT::v2f64, Legal);
790-
setOperationAction(ISD::FNEARBYINT, MVT::f64, Legal);
791797
setOperationAction(ISD::FROUND, MVT::f64, Legal);
792798

793799
setOperationAction(ISD::FNEARBYINT, MVT::v4f32, Legal);
794800
setOperationAction(ISD::FROUND, MVT::v4f32, Legal);
795-
setOperationAction(ISD::FNEARBYINT, MVT::f32, Legal);
796801
setOperationAction(ISD::FROUND, MVT::f32, Legal);
797802

798803
setOperationAction(ISD::MUL, MVT::v2f64, Legal);

llvm/test/CodeGen/PowerPC/scalar-rounding-ops.ll

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,14 @@ declare i64 @llvm.llround.i64.f32(float)
342342

343343
define dso_local double @test_nearbyint(double %d) local_unnamed_addr {
344344
; BE-LABEL: test_nearbyint:
345-
; BE: # %bb.0: # %entry
346-
; BE-NEXT: xsrdpic f1, f1
347-
; BE-NEXT: blr
345+
; BE: # %bb.0: # %entry
346+
; BE: bl nearbyint
347+
; BE: blr
348348
;
349349
; CHECK-LABEL: test_nearbyint:
350-
; CHECK: # %bb.0: # %entry
351-
; CHECK-NEXT: xsrdpic f1, f1
352-
; CHECK-NEXT: blr
350+
; CHECK: # %bb.0: # %entry
351+
; CHECK: bl nearbyint
352+
; CHECK: blr
353353
;
354354
; FAST-LABEL: test_nearbyint:
355355
; FAST: # %bb.0: # %entry
@@ -364,14 +364,14 @@ declare double @llvm.nearbyint.f64(double)
364364

365365
define dso_local float @test_nearbyintf(float %f) local_unnamed_addr {
366366
; BE-LABEL: test_nearbyintf:
367-
; BE: # %bb.0: # %entry
368-
; BE-NEXT: xsrdpic f1, f1
369-
; BE-NEXT: blr
367+
; BE: # %bb.0: # %entry
368+
; BE: bl nearbyint
369+
; BE: blr
370370
;
371371
; CHECK-LABEL: test_nearbyintf:
372-
; CHECK: # %bb.0: # %entry
373-
; CHECK-NEXT: xsrdpic f1, f1
374-
; CHECK-NEXT: blr
372+
; CHECK: # %bb.0: # %entry
373+
; CHECK: bl nearbyintf
374+
; CHECK: blr
375375
;
376376
; FAST-LABEL: test_nearbyintf:
377377
; FAST: # %bb.0: # %entry

0 commit comments

Comments
 (0)