Skip to content
Open
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
10 changes: 7 additions & 3 deletions llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2793,12 +2793,16 @@ static SDValue lowerFREM(SDValue Op, SelectionDAG &DAG,
EVT Ty = Op.getValueType();
SDNodeFlags Flags = Op->getFlags();

// fdiv can still generate inf and nan when nnan and ninf are set.
SDNodeFlags NewFlags = Flags;
NewFlags.setNoNaNs(false);
NewFlags.setNoInfs(false);
SDValue Div = DAG.getNode(ISD::FDIV, DL, Ty, X, Y, Flags);
SDValue Trunc = DAG.getNode(ISD::FTRUNC, DL, Ty, Div, Flags);
SDValue Trunc = DAG.getNode(ISD::FTRUNC, DL, Ty, Div, NewFlags);
SDValue Mul = DAG.getNode(ISD::FMUL, DL, Ty, Trunc, Y,
Flags | SDNodeFlags::AllowContract);
NewFlags | SDNodeFlags::AllowContract);
SDValue Sub = DAG.getNode(ISD::FSUB, DL, Ty, X, Mul,
Flags | SDNodeFlags::AllowContract);
NewFlags | SDNodeFlags::AllowContract);

if (AllowUnsafeFPMath || Flags.hasNoInfs())
return Sub;
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/CodeGen/NVPTX/frem-ninf-nnan.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; RUN: llc %s --stop-after=nvptx-isel -mcpu=sm_60 -o - | FileCheck %s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend using -stop-after=finalize-isel instead if you want to check mir


target triple = "nvptx64-unknown-cuda"

define float @frem_ninf_nnan(float %a, float %b) {
; CHECK: nnan ninf FDIV32rr_prec
; CHECK-NOT: nnan ninf contract FNEGf32
; CHECK: contract FNEGf32
%r = frem ninf nnan float %a, %b
ret float %r
}
Loading