mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
[Hexagon] Generate constant splats instead of loads from constant pool
llvm-svn: 323568
This commit is contained in:
parent
75b93bc978
commit
fcb6fc5908
@ -911,18 +911,24 @@ static bool isPermutation(ArrayRef<int> Mask) {
|
||||
}
|
||||
|
||||
bool HvxSelector::selectVectorConstants(SDNode *N) {
|
||||
// Constant vectors are generated as loads from constant pools.
|
||||
// Constant vectors are generated as loads from constant pools or
|
||||
// as VSPLATs of a constant value.
|
||||
// Since they are generated during the selection process, the main
|
||||
// selection algorithm is not aware of them. Select them directly
|
||||
// here.
|
||||
SmallVector<SDNode*,4> Loads;
|
||||
SmallVector<SDNode*,4> Nodes;
|
||||
SetVector<SDNode*> WorkQ;
|
||||
|
||||
// The DAG can change (due to CSE) during selection, so cache all the
|
||||
// unselected nodes first to avoid traversing a mutating DAG.
|
||||
|
||||
auto IsLoadToSelect = [] (SDNode *N) {
|
||||
if (!N->isMachineOpcode() && N->getOpcode() == ISD::LOAD) {
|
||||
auto IsNodeToSelect = [] (SDNode *N) {
|
||||
if (N->isMachineOpcode())
|
||||
return false;
|
||||
unsigned Opc = N->getOpcode();
|
||||
if (Opc == HexagonISD::VSPLAT || Opc == ISD::BITCAST)
|
||||
return true;
|
||||
if (Opc == ISD::LOAD) {
|
||||
SDValue Addr = cast<LoadSDNode>(N)->getBasePtr();
|
||||
unsigned AddrOpc = Addr.getOpcode();
|
||||
if (AddrOpc == HexagonISD::AT_PCREL || AddrOpc == HexagonISD::CP)
|
||||
@ -935,18 +941,16 @@ bool HvxSelector::selectVectorConstants(SDNode *N) {
|
||||
WorkQ.insert(N);
|
||||
for (unsigned i = 0; i != WorkQ.size(); ++i) {
|
||||
SDNode *W = WorkQ[i];
|
||||
if (IsLoadToSelect(W)) {
|
||||
Loads.push_back(W);
|
||||
continue;
|
||||
}
|
||||
if (IsNodeToSelect(W))
|
||||
Nodes.push_back(W);
|
||||
for (unsigned j = 0, f = W->getNumOperands(); j != f; ++j)
|
||||
WorkQ.insert(W->getOperand(j).getNode());
|
||||
}
|
||||
|
||||
for (SDNode *L : Loads)
|
||||
for (SDNode *L : Nodes)
|
||||
ISel.Select(L);
|
||||
|
||||
return !Loads.empty();
|
||||
return !Nodes.empty();
|
||||
}
|
||||
|
||||
void HvxSelector::materialize(const ResultStack &Results) {
|
||||
|
@ -151,22 +151,6 @@ HexagonTargetLowering::buildHvxVectorReg(ArrayRef<SDValue> Values,
|
||||
unsigned ElemWidth = ElemTy.getSizeInBits();
|
||||
unsigned HwLen = Subtarget.getVectorLength();
|
||||
|
||||
// TODO: Recognize constant splats.
|
||||
SmallVector<ConstantInt*, 128> Consts(VecLen);
|
||||
bool AllConst = getBuildVectorConstInts(Values, VecTy, DAG, Consts);
|
||||
if (AllConst) {
|
||||
if (llvm::all_of(Consts, [](ConstantInt *CI) { return CI->isZero(); }))
|
||||
return getZero(dl, VecTy, DAG);
|
||||
|
||||
ArrayRef<Constant*> Tmp((Constant**)Consts.begin(),
|
||||
(Constant**)Consts.end());
|
||||
Constant *CV = ConstantVector::get(Tmp);
|
||||
unsigned Align = HwLen;
|
||||
SDValue CP = LowerConstantPool(DAG.getConstantPool(CV, VecTy, Align), DAG);
|
||||
return DAG.getLoad(VecTy, dl, DAG.getEntryNode(), CP,
|
||||
MachinePointerInfo::getConstantPool(MF), Align);
|
||||
}
|
||||
|
||||
unsigned ElemSize = ElemWidth / 8;
|
||||
assert(ElemSize*VecLen == HwLen);
|
||||
SmallVector<SDValue,32> Words;
|
||||
@ -196,7 +180,26 @@ HexagonTargetLowering::buildHvxVectorReg(ArrayRef<SDValue> Values,
|
||||
}
|
||||
if (IsSplat) {
|
||||
assert(SplatV.getNode());
|
||||
return DAG.getNode(HexagonISD::VSPLAT, dl, VecTy, SplatV);
|
||||
auto *IdxN = dyn_cast<ConstantSDNode>(SplatV.getNode());
|
||||
if (IdxN && IdxN->isNullValue())
|
||||
return getZero(dl, VecTy, DAG);
|
||||
MVT WordTy = MVT::getVectorVT(MVT::i32, HwLen/4);
|
||||
SDValue SV = DAG.getNode(HexagonISD::VSPLAT, dl, WordTy, SplatV);
|
||||
return DAG.getBitcast(VecTy, SV);
|
||||
}
|
||||
|
||||
// Delay recognizing constant vectors until here, so that we can generate
|
||||
// a vsplat.
|
||||
SmallVector<ConstantInt*, 128> Consts(VecLen);
|
||||
bool AllConst = getBuildVectorConstInts(Values, VecTy, DAG, Consts);
|
||||
if (AllConst) {
|
||||
ArrayRef<Constant*> Tmp((Constant**)Consts.begin(),
|
||||
(Constant**)Consts.end());
|
||||
Constant *CV = ConstantVector::get(Tmp);
|
||||
unsigned Align = HwLen;
|
||||
SDValue CP = LowerConstantPool(DAG.getConstantPool(CV, VecTy, Align), DAG);
|
||||
return DAG.getLoad(VecTy, dl, DAG.getEntryNode(), CP,
|
||||
MachinePointerInfo::getConstantPool(MF), Align);
|
||||
}
|
||||
|
||||
// Construct two halves in parallel, then or them together.
|
||||
|
@ -3001,6 +3001,19 @@ def VSxth: OutPatFrag<(ops node:$Vs), (V6_vunpackh $Vs)>;
|
||||
def VZxtb: OutPatFrag<(ops node:$Vs), (V6_vunpackub $Vs)>;
|
||||
def VZxth: OutPatFrag<(ops node:$Vs), (V6_vunpackuh $Vs)>;
|
||||
|
||||
def SplatB: SDNodeXForm<imm, [{
|
||||
uint32_t V = N->getZExtValue();
|
||||
assert(isUInt<8>(V));
|
||||
uint32_t S = V << 24 | V << 16 | V << 8 | V;
|
||||
return CurDAG->getTargetConstant(S, SDLoc(N), MVT::i32);
|
||||
}]>;
|
||||
|
||||
def SplatH: SDNodeXForm<imm, [{
|
||||
uint32_t V = N->getZExtValue();
|
||||
assert(isUInt<16>(V));
|
||||
return CurDAG->getTargetConstant(V << 16 | V, SDLoc(N), MVT::i32);
|
||||
}]>;
|
||||
|
||||
let Predicates = [UseHVX] in {
|
||||
def: Pat<(VecI8 vzero), (V6_vd0)>;
|
||||
def: Pat<(VecI16 vzero), (V6_vd0)>;
|
||||
@ -3027,6 +3040,14 @@ let Predicates = [UseHVX] in {
|
||||
def: Pat<(HexagonVINSERTW0 HVI32:$Vu, I32:$Rt),
|
||||
(V6_vinsertwr HvxVR:$Vu, I32:$Rt)>;
|
||||
|
||||
let AddedComplexity = 10 in {
|
||||
def: Pat<(VecI8 (HexagonVSPLAT u8_0ImmPred:$V)),
|
||||
(V6_lvsplatw (ToI32 (SplatB $V)))>;
|
||||
def: Pat<(VecI16 (HexagonVSPLAT u16_0ImmPred:$V)),
|
||||
(V6_lvsplatw (ToI32 (SplatH $V)))>;
|
||||
def: Pat<(VecI32 (HexagonVSPLAT anyimm:$V)),
|
||||
(V6_lvsplatw (ToI32 $V))>;
|
||||
}
|
||||
def: Pat<(VecI8 (HexagonVSPLAT I32:$Rs)),
|
||||
(V6_lvsplatw (S2_vsplatrb I32:$Rs))>;
|
||||
def: Pat<(VecI16 (HexagonVSPLAT I32:$Rs)),
|
||||
|
12
test/CodeGen/Hexagon/autohvx/isel-const-splat.ll
Normal file
12
test/CodeGen/Hexagon/autohvx/isel-const-splat.ll
Normal file
@ -0,0 +1,12 @@
|
||||
; RUN: llc -march=hexagon < %s | FileCheck %s
|
||||
|
||||
; CHECK: r[[V:[0-9]+]] = ##16843009
|
||||
; CHECK: vsplat(r[[V]])
|
||||
|
||||
define <64 x i8> @fred(<64 x i8> %a0) #0 {
|
||||
%p = shufflevector <64 x i8> %a0, <64 x i8> undef, <64 x i32> <i32 1, i32 0, i32 3, i32 2, i32 5, i32 4, i32 7, i32 6, i32 9, i32 8, i32 11, i32 10, i32 13, i32 12, i32 15, i32 14, i32 17, i32 16, i32 19, i32 18, i32 21, i32 20, i32 23, i32 22, i32 25, i32 24, i32 27, i32 26, i32 29, i32 28, i32 31, i32 30, i32 33, i32 32, i32 35, i32 34, i32 37, i32 36, i32 39, i32 38, i32 41, i32 40, i32 43, i32 42, i32 45, i32 44, i32 47, i32 46, i32 49, i32 48, i32 51, i32 50, i32 53, i32 52, i32 55, i32 54, i32 57, i32 56, i32 59, i32 58, i32 61, i32 60, i32 63, i32 62>
|
||||
ret <64 x i8> %p
|
||||
}
|
||||
|
||||
attributes #0 = { nounwind readnone "target-cpu"="hexagonv60" "target-features"="+hvx,+hvx-length64b" }
|
||||
|
Loading…
Reference in New Issue
Block a user