[llvm] [NVPTX] Don't use stack memory when bitcasting to/from v2i8 (PR #113928)
Justin Fargnoli via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 28 23:13:23 PDT 2024
================
@@ -2311,6 +2315,47 @@ 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 to/from v2i8 without hitting the default promotion
+ // strategy which goes through stack memory.
+ SDNode *Node = Op.getNode();
+ SDLoc dl(Node);
+
+ auto maybeBitcast = [&](EVT vt, SDValue val) {
+ if (val->getValueType(0) == vt) {
+ return val;
+ }
+ return DAG.getNode(ISD::BITCAST, dl, vt, val);
+ };
+
+ EVT VT = Op->getValueType(0);
+ EVT fromVT = Op->getOperand(0)->getValueType(0);
+
+ if (VT == MVT::v2i8) {
+ // Bitcast to i16 and unpack elements into a vector
+ SDValue reg = maybeBitcast(MVT::i16, Op->getOperand(0));
+ SDValue v0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::i8, reg);
+ SDValue C8 = DAG.getConstant(8, dl, MVT::i16);
+ SDValue v1 = DAG.getNode(ISD::TRUNCATE, dl, MVT::i8,
----------------
justinfargnoli wrote:
I think it would be useful to have some more descriptive variable names here and in the `else if` below.
https://github.com/llvm/llvm-project/pull/113928
More information about the llvm-commits
mailing list