Skip to content

Commit d7cb133

Browse files
committed
Addressed Most Code Review Comments
1 parent 3320d55 commit d7cb133

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,9 +2175,8 @@ SDValue DAGTypeLegalizer::PromoteIntOp_ATOMIC_STORE(AtomicSDNode *N) {
21752175

21762176
SDValue DAGTypeLegalizer::PromoteIntOp_BITCAST(SDNode *N) {
21772177
// Use the custom lowering.
2178-
if (const auto Res = LowerBitcast(N)) {
2178+
if (SDValue Res = LowerBitcast(N))
21792179
return Res;
2180-
}
21812180

21822181
// If it fails fall back to the default method
21832182
return CreateStackStoreLoad(N->getOperand(0), N->getValueType(0));

llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -910,36 +910,32 @@ SDValue DAGTypeLegalizer::CreateStackStoreLoad(SDValue Op,
910910
return DAG.getLoad(DestVT, dl, Store, StackPtr, MachinePointerInfo(), Align);
911911
}
912912

913-
static SDValue MaybeBitcast(SelectionDAG &DAG, SDLoc DL, EVT VT,
914-
SDValue Value) {
915-
if (Value->getValueType(0) == VT)
916-
return Value;
917-
return DAG.getNode(ISD::BITCAST, DL, VT, Value);
918-
}
919-
920913
SDValue DAGTypeLegalizer::LowerBitcast(SDNode *Node) const {
921914
assert(Node->getOpcode() == ISD::BITCAST && "Unexpected opcode!");
922915
// Handle bitcasting from v2i8 without hitting the default promotion
923916
// strategy which goes through stack memory.
924917
EVT FromVT = Node->getOperand(0)->getValueType(0);
925-
if (FromVT != MVT::v2i8) {
918+
if (FromVT != MVT::v2i8)
926919
return SDValue();
927-
}
928920

929921
// Pack vector elements into i16 and bitcast to final type
930922
SDLoc DL(Node);
931923
SDValue Vec0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8,
932924
Node->getOperand(0), DAG.getIntPtrConstant(0, DL));
933925
SDValue Vec1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i8,
934926
Node->getOperand(0), DAG.getIntPtrConstant(1, DL));
927+
935928
SDValue Extend0 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec0);
936929
SDValue Extend1 = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i16, Vec1);
937-
SDValue Const8 = DAG.getConstant(8, DL, MVT::i16);
930+
931+
EVT ShiftAmtTy = TLI.getShiftAmountTy(Extend1.getValueType(), DAG.getDataLayout());
932+
SDValue ShiftConst = DAG.getShiftAmountConstant(8, ShiftAmtTy, DL);
938933
SDValue AsInt = DAG.getNode(
939-
ISD::OR, DL, MVT::i16,
940-
{Extend0, DAG.getNode(ISD::SHL, DL, MVT::i16, {Extend1, Const8})});
934+
ISD::OR, DL, MVT::i16, Extend0,
935+
DAG.getNode(ISD::SHL, DL, Extend1.getValueType(), Extend1, ShiftConst));
941936
EVT ToVT = Node->getValueType(0);
942-
return MaybeBitcast(DAG, DL, ToVT, AsInt);
937+
938+
return DAG.getBitcast( ToVT, AsInt);
943939
}
944940

945941
/// Replace the node's results with custom code provided by the target and

0 commit comments

Comments
 (0)