Skip to content
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

[LegalizeDAG] PromoteNode FABS: Override promotion with clear sign bit #106076

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
22 changes: 21 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5576,6 +5576,27 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
Results.push_back(Tmp2.getValue(1));
break;
}
case ISD::FABS: {
// if we can convert to a same sized int value, we bitcast to it,
// clear the sign bit and bitcast back to the original type.
EVT IntVT = OVT.changeTypeToInteger();
if (TLI.isTypeLegal(IntVT)) {
SDValue Cast = DAG.getNode(ISD::BITCAST, dl, IntVT, Node->getOperand(0));

APInt SignMask = APInt::getSignMask(IntVT.getScalarSizeInBits());

// Mask = ~(1 << (Size-1))
SDValue Mask = DAG.getConstant(SignMask, dl, IntVT);

SDValue And = DAG.getNode(ISD::AND, dl, IntVT, Cast, Mask);

SDValue Result = DAG.getNode(ISD::BITCAST, dl, OVT, And);
Results.push_back(Result);
break;
}

[[fallthrough]];
}
case ISD::FFLOOR:
case ISD::FCEIL:
case ISD::FRINT:
Expand All @@ -5597,7 +5618,6 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
case ISD::FLOG:
case ISD::FLOG2:
case ISD::FLOG10:
case ISD::FABS:
case ISD::FEXP:
case ISD::FEXP2:
case ISD::FEXP10:
Expand Down
Loading