-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[DAG] Add generic expansion for ISD::FCANONICALIZE nodes #142105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3356,6 +3356,31 @@ bool SelectionDAGLegalize::ExpandNode(SDNode *Node) { | |
Results.push_back(Op); | ||
break; | ||
} | ||
case ISD::FCANONICALIZE: { | ||
// This implements llvm.canonicalize.f* by multiplication with 1.0, as | ||
// suggested in | ||
// https://llvm.org/docs/LangRef.html#llvm-canonicalize-intrinsic. | ||
// It uses strict_fp operations even outside a strict_fp context in order | ||
// to guarantee that the canonicalization is not optimized away by later | ||
// passes. | ||
|
||
// Create strict multiplication by 1.0. | ||
SDValue Operand = Node->getOperand(0); | ||
EVT VT = Operand.getValueType(); | ||
SDValue One = DAG.getConstantFP(1.0, dl, VT); | ||
SDValue Chain = DAG.getEntryNode(); | ||
SDValue Mul = DAG.getNode(ISD::STRICT_FMUL, dl, {VT, MVT::Other}, | ||
{Chain, Operand, One}); | ||
|
||
// Propagate existing flags on canonicalize, and additionally set | ||
// NoFPExcept. | ||
SDNodeFlags CanonicalizeFlags = Node->getFlags(); | ||
CanonicalizeFlags.setNoFPExcept(true); | ||
Mul->setFlags(CanonicalizeFlags); | ||
|
||
Results.push_back(Mul); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ignoring the new result chain feels wrong but it's probably correct in this context There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dominik-steenken Add a comment mentioning that ignoring the output chain was intended. |
||
break; | ||
} | ||
case ISD::SIGN_EXTEND_INREG: { | ||
EVT ExtraVT = cast<VTSDNode>(Node->getOperand(1))->getVT(); | ||
EVT VT = Node->getValueType(0); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Losing the fast math flags. You can propagate the existing flags, and additionally add NoFPExcept
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm now propagating the flags and have added
NoFPExcept
.