-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Nvptx port LowerBITCAST to SelectionDAG #120903
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 4 commits
e1b6fce
3320d55
d7cb133
b674487
f8dadde
a6ca08a
75a533c
686f698
d8a82eb
e5f7304
8d01cbe
87530e4
7a5cfe4
66bfc99
f278d56
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 |
|---|---|---|
|
|
@@ -910,6 +910,35 @@ SDValue DAGTypeLegalizer::CreateStackStoreLoad(SDValue Op, | |
| return DAG.getLoad(DestVT, dl, Store, StackPtr, MachinePointerInfo(), Align); | ||
| } | ||
|
|
||
| SDValue DAGTypeLegalizer::LowerBitcast(SDNode *Node) const { | ||
| assert(Node->getOpcode() == ISD::BITCAST && "Unexpected opcode!"); | ||
| // Handle bitcasting from v2i8 without hitting the default promotion | ||
| // strategy which goes through stack memory. | ||
| EVT FromVT = Node->getOperand(0)->getValueType(0); | ||
| if (FromVT != MVT::v2i8) | ||
| return SDValue(); | ||
|
|
||
| // Pack vector elements into i16 and bitcast to final type | ||
| SDLoc DL(Node); | ||
| SDValue Vec0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, | ||
| Node->getOperand(0), DAG.getIntPtrConstant(0, DL)); | ||
| SDValue Vec1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, | ||
| Node->getOperand(0), DAG.getIntPtrConstant(1, DL)); | ||
|
|
||
| SDValue Extend0 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec0); | ||
| SDValue Extend1 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec1); | ||
|
|
||
| EVT ShiftAmtTy = | ||
| TLI.getShiftAmountTy(Extend1.getValueType(), DAG.getDataLayout()); | ||
| SDValue ShiftConst = DAG.getShiftAmountConstant(8, ShiftAmtTy, DL); | ||
|
||
| SDValue AsInt = DAG.getNode( | ||
| ISD::OR, DL, MVT::i16, Extend0, | ||
| DAG.getNode(ISD::SHL, DL, Extend1.getValueType(), Extend1, ShiftConst)); | ||
| EVT ToVT = Node->getValueType(0); | ||
|
|
||
| return DAG.getBitcast(ToVT, AsInt); | ||
| } | ||
|
|
||
| /// Replace the node's results with custom code provided by the target and | ||
| /// return "true", or do nothing and return "false". | ||
| /// The last parameter is FALSE if we are dealing with a node with legal | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2086,30 +2086,6 @@ NVPTXTargetLowering::LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const { | |
| return DAG.getBuildVector(Node->getValueType(0), dl, Ops); | ||
| } | ||
|
|
||
| SDValue NVPTXTargetLowering::LowerBITCAST(SDValue Op, SelectionDAG &DAG) const { | ||
| // Handle bitcasting from v2i8 without hitting the default promotion | ||
| // strategy which goes through stack memory. | ||
| EVT FromVT = Op->getOperand(0)->getValueType(0); | ||
| if (FromVT != MVT::v2i8) { | ||
| return Op; | ||
| } | ||
|
|
||
| // Pack vector elements into i16 and bitcast to final type | ||
| SDLoc DL(Op); | ||
| SDValue Vec0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, | ||
| Op->getOperand(0), DAG.getIntPtrConstant(0, DL)); | ||
| SDValue Vec1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8, | ||
| Op->getOperand(0), DAG.getIntPtrConstant(1, DL)); | ||
| SDValue Extend0 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec0); | ||
| SDValue Extend1 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec1); | ||
| SDValue Const8 = DAG.getConstant(8, DL, MVT::i16); | ||
| SDValue AsInt = DAG.getNode( | ||
| ISD::OR, DL, MVT::i16, | ||
| {Extend0, DAG.getNode(ISD::SHL, DL, MVT::i16, {Extend1, Const8})}); | ||
| EVT ToVT = Op->getValueType(0); | ||
| return MaybeBitcast(DAG, DL, ToVT, AsInt); | ||
| } | ||
|
|
||
| // We can init constant f16x2/v2i16/v4i8 with a single .b32 move. Normally it | ||
| // would get lowered as two constant loads and vector-packing move. | ||
| // Instead we want just a constant move: | ||
|
|
@@ -2619,7 +2595,7 @@ NVPTXTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { | |
| case ISD::BUILD_VECTOR: | ||
| return LowerBUILD_VECTOR(Op, DAG); | ||
| case ISD::BITCAST: | ||
| return LowerBITCAST(Op, DAG); | ||
| return SDValue(); | ||
|
||
| case ISD::EXTRACT_SUBVECTOR: | ||
| return Op; | ||
| case ISD::EXTRACT_VECTOR_ELT: | ||
|
|
||
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.
This is too specific of a type check for the generic legalizer. This code should be generalized over the types supported
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.
What other types do you think we should support? Or would this be the preferred method from int->vec and vice versa? ie.
I could see that changing a lot of code though.