Skip to content

Commit 39307de

Browse files
committed
don't custom lower i64 = bitcast v2f32
This is unnecessary. DAGCombiner already has rules for shift patterns. We also don't care about having the most optimal code in -O0. Finally, introducing build_pair at this stage defeats an existing peephole optimization in DAGCombiner. We also update the test case with -O3 compilation.
1 parent c9dd4b1 commit 39307de

File tree

2 files changed

+2476
-1131
lines changed

2 files changed

+2476
-1131
lines changed

llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp

Lines changed: 17 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,6 @@ NVPTXTargetLowering::NVPTXTargetLowering(const NVPTXTargetMachine &TM,
870870
// Handle custom lowering for: v2f32 = OP v2f32, v2f32
871871
for (const auto &Op : {ISD::FADD, ISD::FSUB, ISD::FMUL, ISD::FMA})
872872
setOperationAction(Op, MVT::v2f32, Custom);
873-
// Handle custom lowering for: i64 = bitcast v2f32
874-
setOperationAction(ISD::BITCAST, MVT::v2f32, Custom);
875873
// Handle custom lowering for: f32 = extract_vector_elt v2f32
876874
setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2f32, Custom);
877875
// Combine:
@@ -2123,58 +2121,24 @@ SDValue NVPTXTargetLowering::LowerBITCAST(SDValue Op, SelectionDAG &DAG) const {
21232121
// Handle bitcasting from v2i8 without hitting the default promotion
21242122
// strategy which goes through stack memory.
21252123
EVT FromVT = Op->getOperand(0)->getValueType(0);
2126-
EVT ToVT = Op->getValueType(0);
2127-
SDLoc DL(Op);
2128-
2129-
if (FromVT == MVT::v2i8) {
2130-
// Pack vector elements into i16 and bitcast to final type
2131-
SDValue Vec0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8,
2132-
Op->getOperand(0), DAG.getIntPtrConstant(0, DL));
2133-
SDValue Vec1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8,
2134-
Op->getOperand(0), DAG.getIntPtrConstant(1, DL));
2135-
SDValue Extend0 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec0);
2136-
SDValue Extend1 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec1);
2137-
SDValue Const8 = DAG.getConstant(8, DL, MVT::i16);
2138-
SDValue AsInt = DAG.getNode(
2139-
ISD::OR, DL, MVT::i16,
2140-
{Extend0, DAG.getNode(ISD::SHL, DL, MVT::i16, {Extend1, Const8})});
2141-
EVT ToVT = Op->getValueType(0);
2142-
return MaybeBitcast(DAG, DL, ToVT, AsInt);
2143-
}
2144-
2145-
if (FromVT == MVT::v2f32) {
2146-
// A bitcast to i64 from v2f32.
2147-
// See if we can legalize the operand.
2148-
const SDValue &Operand = Op->getOperand(0);
2149-
if (ToVT == MVT::i64 && Operand.getOpcode() == ISD::BUILD_VECTOR) {
2150-
const SDValue &BVOp0 = Operand.getOperand(0);
2151-
const SDValue &BVOp1 = Operand.getOperand(1);
2152-
2153-
auto CastToAPInt = [](SDValue Op) -> APInt {
2154-
if (Op->isUndef())
2155-
return APInt(64, 0); // undef values default to 0
2156-
return cast<ConstantFPSDNode>(Op)->getValueAPF().bitcastToAPInt().zext(
2157-
64);
2158-
};
2159-
2160-
if ((BVOp0->isUndef() || isa<ConstantFPSDNode>(BVOp0)) &&
2161-
(BVOp1->isUndef() || isa<ConstantFPSDNode>(BVOp1))) {
2162-
// cast two constants
2163-
APInt Value(64, 0);
2164-
Value = CastToAPInt(BVOp0) | CastToAPInt(BVOp1).shl(32);
2165-
return DAG.getConstant(Value, DL, MVT::i64);
2166-
}
2167-
2168-
// otherwise build an i64
2169-
return DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64,
2170-
DAG.getBitcast(MVT::i32, BVOp0),
2171-
DAG.getBitcast(MVT::i32, BVOp1));
2172-
}
2173-
2174-
// Otherwise, let SelectionDAG expand the operand
2175-
return SDValue();
2124+
if (FromVT != MVT::v2i8) {
2125+
return Op;
21762126
}
2177-
return Op;
2127+
2128+
// Pack vector elements into i16 and bitcast to final type
2129+
SDLoc DL(Op);
2130+
SDValue Vec0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8,
2131+
Op->getOperand(0), DAG.getIntPtrConstant(0, DL));
2132+
SDValue Vec1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8,
2133+
Op->getOperand(0), DAG.getIntPtrConstant(1, DL));
2134+
SDValue Extend0 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec0);
2135+
SDValue Extend1 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec1);
2136+
SDValue Const8 = DAG.getConstant(8, DL, MVT::i16);
2137+
SDValue AsInt = DAG.getNode(
2138+
ISD::OR, DL, MVT::i16,
2139+
{Extend0, DAG.getNode(ISD::SHL, DL, MVT::i16, {Extend1, Const8})});
2140+
EVT ToVT = Op->getValueType(0);
2141+
return MaybeBitcast(DAG, DL, ToVT, AsInt);
21782142
}
21792143

21802144
// We can init constant f16x2/v2i16/v4i8 with a single .b32 move. Normally it

0 commit comments

Comments
 (0)