Skip to content

Commit 31d4e3c

Browse files
committed
using MTVSRBMI instead of constant pool
1 parent c3ec9e3 commit 31d4e3c

File tree

2 files changed

+53
-19
lines changed

2 files changed

+53
-19
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9580,6 +9580,37 @@ static bool isValidSplatLoad(const PPCSubtarget &Subtarget, const SDValue &Op,
95809580
return false;
95819581
}
95829582

9583+
bool isValidMtVsrbmi(APInt &BMI, BuildVectorSDNode &BVN) {
9584+
unsigned int NumOps = BVN.getNumOperands();
9585+
assert(NumOps > 0 && "isConstantSplat has 0-size build vector");
9586+
9587+
BMI.clearAllBits();
9588+
EVT VT = BVN.getValueType(0);
9589+
APInt ConstValue(VT.getSizeInBits(), 0);
9590+
9591+
unsigned EltWidth = VT.getScalarSizeInBits();
9592+
9593+
for (unsigned j = 0; j < NumOps; ++j) {
9594+
SDValue OpVal = BVN.getOperand(j);
9595+
unsigned BitPos = j * EltWidth;
9596+
auto *CN = dyn_cast<ConstantSDNode>(OpVal);
9597+
9598+
if (!CN)
9599+
return false;
9600+
9601+
ConstValue.insertBits(CN->getAPIntValue().zextOrTrunc(EltWidth), BitPos);
9602+
}
9603+
9604+
for (unsigned J = 0; J < 16; J++) {
9605+
APInt ExtractValue = ConstValue.extractBits(8, J * 8);
9606+
if (ExtractValue != 0x00 && ExtractValue != 0xFF)
9607+
return false;
9608+
if (ExtractValue == 0xFF)
9609+
BMI.setBit(J);
9610+
}
9611+
return true;
9612+
}
9613+
95839614
// If this is a case we can't handle, return null and let the default
95849615
// expansion code take care of it. If we CAN select this case, and if it
95859616
// selects to a single instruction, return Op. Otherwise, if we can codegen
@@ -9591,6 +9622,24 @@ SDValue PPCTargetLowering::LowerBUILD_VECTOR(SDValue Op,
95919622
BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode());
95929623
assert(BVN && "Expected a BuildVectorSDNode in LowerBUILD_VECTOR");
95939624

9625+
if(Subtarget.hasP10Vector()) {
9626+
APInt BMI(32, 0);
9627+
// If the value of the vector is all zeros or all ones,
9628+
// we do not convert it to MTVSRBMI.
9629+
// The xxleqv instruction sets a vector with all ones.
9630+
// The xxlxor instruction sets a vector with all zeros.
9631+
if (isValidMtVsrbmi(BMI, *BVN) && BMI != 0 && BMI!=0xffff ) {
9632+
SDValue SDConstant= DAG.getTargetConstant(BMI, dl, MVT::i32);
9633+
MachineSDNode* MSDNode = DAG.getMachineNode(PPC::MTVSRBMI, dl,MVT::v16i8, SDConstant);
9634+
SDValue SDV = SDValue(MSDNode,0);
9635+
EVT DVT = BVN->getValueType(0);
9636+
EVT SVT = SDV.getValueType();
9637+
if (SVT != DVT ) {
9638+
SDV = DAG.getNode(ISD::BITCAST, dl, DVT, SDV);
9639+
}
9640+
return SDV;
9641+
}
9642+
}
95949643
// Check if this is a splat of a constant value.
95959644
APInt APSplatBits, APSplatUndef;
95969645
unsigned SplatBitSize;

llvm/test/CodeGen/PowerPC/mtvsrbmi.ll

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,13 @@
1010
; RUN: | FileCheck %s --check-prefix=CHECK
1111

1212
define dso_local noundef range(i8 -1, 1) <16 x i8> @_Z5v00FFv() {
13-
; CHECK: L..CPI0_0:
14-
; CHECK-NEXT: .byte 255 # 0xff
15-
; CHECK-NEXT: .byte 0 # 0x0
16-
; CHECK-NEXT: .byte 0 # 0x0
17-
; CHECK-NEXT: .byte 0 # 0x0
18-
; CHECK-NEXT: .byte 0 # 0x0
19-
; CHECK-NEXT: .byte 0 # 0x0
20-
; CHECK-NEXT: .byte 0 # 0x0
21-
; CHECK-NEXT: .byte 0 # 0x0
22-
; CHECK-NEXT: .byte 0 # 0x0
23-
; CHECK-NEXT: .byte 0 # 0x0
24-
; CHECK-NEXT: .byte 0 # 0x0
25-
; CHECK-NEXT: .byte 0 # 0x0
26-
; CHECK-NEXT: .byte 0 # 0x0
27-
; CHECK-NEXT: .byte 0 # 0x0
28-
; CHECK-NEXT: .byte 0 # 0x0
29-
; CHECK-NEXT: .byte 0 # 0x0
13+
; CHECK-NOT: L..CPI0_0:
14+
; CHECK-NOT: .byte 255 # 0xff
15+
; CHECK-NOT: .byte 0 # 0x0
3016

3117
; CHECK-LABEL: _Z5v00FFv:
3218
; CHECK: # %bb.0: # %entry
33-
; CHECK-NEXT: lwz r3, L..C0(r2) # %const.0
34-
; CHECK-NEXT: lxv vs34, 0(r3)
19+
; CHECK-NEXT: mtvsrbmi v2, 1
3520
; CHECK-NEXT: blr
3621
entry:
3722
ret <16 x i8> <i8 -1, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0, i8 0>

0 commit comments

Comments
 (0)