Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions llvm/lib/Analysis/ConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2679,11 +2679,9 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
case Intrinsic::nvvm_round_ftz_f:
case Intrinsic::nvvm_round_f:
case Intrinsic::nvvm_round_d: {
// Use APFloat implementation instead of native libm call, as some
// implementations (e.g. on PPC) do not preserve the sign of negative 0.
bool IsFTZ = nvvm::UnaryMathIntrinsicShouldFTZ(IntrinsicID);
auto V = IsFTZ ? FTZPreserveSign(APF) : APF;
V.roundToIntegral(APFloat::rmNearestTiesToAway);
V.roundToIntegral(APFloat::rmNearestTiesToEven);
return ConstantFP::get(Ty->getContext(), V);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,54 @@ define float @test_round_ftz_f_neg_1_5() {
ret float %res
}

define double @test_round_d_2_5() {
; CHECK-LABEL: define double @test_round_d_2_5() {
; CHECK-NEXT: ret double 2.000000e+00
;
%res = call double @llvm.nvvm.round.d(double 2.5)
ret double %res
}

define float @test_round_f_2_5() {
; CHECK-LABEL: define float @test_round_f_2_5() {
; CHECK-NEXT: ret float 2.000000e+00
;
%res = call float @llvm.nvvm.round.f(float 2.5)
ret float %res
}

define float @test_round_ftz_f_2_5() {
; CHECK-LABEL: define float @test_round_ftz_f_2_5() {
; CHECK-NEXT: ret float 2.000000e+00
;
%res = call float @llvm.nvvm.round.ftz.f(float 2.5)
ret float %res
}

define double @test_round_d_neg_2_5() {
; CHECK-LABEL: define double @test_round_d_neg_2_5() {
; CHECK-NEXT: ret double -2.000000e+00
;
%res = call double @llvm.nvvm.round.d(double -2.5)
ret double %res
}

define float @test_round_f_neg_2_5() {
; CHECK-LABEL: define float @test_round_f_neg_2_5() {
; CHECK-NEXT: ret float -2.000000e+00
;
%res = call float @llvm.nvvm.round.f(float -2.5)
ret float %res
}

define float @test_round_ftz_f_neg_2_5() {
; CHECK-LABEL: define float @test_round_ftz_f_neg_2_5() {
; CHECK-NEXT: ret float -2.000000e+00
;
%res = call float @llvm.nvvm.round.ftz.f(float -2.5)
ret float %res
}

define double @test_round_d_neg_subnorm() {
; CHECK-LABEL: define double @test_round_d_neg_subnorm() {
; CHECK-NEXT: ret double -0.000000e+00
Expand Down
Loading