Skip to content

Commit 0bcb1d6

Browse files
committed
[MIPS][MSA] Widen v2 vectors to the register length for MSA
Currently v2i8, v2i16 and v2i32 are being promoted to v2i64 which casts the vector back and forth, and instructions with the wrong format are being used. Widening them to avoid unnecessary bitcasts, loads and stores, and ensure the correct element size is used. * tests/CodeGen/Mips: Update tests after widening of v2 vectors. TODO: Update tests for mips32r5. skip-checks: true
1 parent ba3e6f0 commit 0bcb1d6

File tree

4 files changed

+571
-946
lines changed

4 files changed

+571
-946
lines changed

llvm/lib/Target/Mips/MipsSEISelLowering.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,45 @@ static cl::opt<bool> NoDPLoadStore("mno-ldc1-sdc1", cl::init(false),
5959
"stores to their single precision "
6060
"counterparts"));
6161

62+
// Widen the v2 vectors to the register width, i.e. v2i16 -> v8i16,
63+
// v2i32 -> v4i32, etc, to ensure the correct rail size is used, i.e.
64+
// INST.h for v16, INST.w for v32, INST.d for v64.
65+
TargetLoweringBase::LegalizeTypeAction
66+
MipsSETargetLowering::getPreferredVectorAction(MVT VT) const {
67+
if (this->Subtarget.hasMSA()) {
68+
switch (VT.SimpleTy) {
69+
// Leave v2i1 vectors to be promoted to larger ones.
70+
// Other i1 types will be promoted by default.
71+
case MVT::v2i1:
72+
return TypePromoteInteger;
73+
break;
74+
// 16-bit vector types (v2 and longer)
75+
case MVT::v2i8:
76+
// 32-bit vector types (v2 and longer)
77+
case MVT::v2i16:
78+
case MVT::v4i8:
79+
// 64-bit vector types (v2 and longer)
80+
case MVT::v2i32:
81+
case MVT::v4i16:
82+
case MVT::v8i8:
83+
return TypeWidenVector;
84+
break;
85+
// Only word (.w) and doubleword (.d) are available for floating point
86+
// vectors. That means floating point vectors should be either v2f64
87+
// or v4f32.
88+
// Here we only explicitly widen the f32 types - f16 will be promoted
89+
// by default.
90+
case MVT::v2f32:
91+
case MVT::v3f32:
92+
return TypeWidenVector;
93+
// v2i64 is already 128-bit wide.
94+
default:
95+
break;
96+
}
97+
}
98+
return TargetLoweringBase::getPreferredVectorAction(VT);
99+
}
100+
62101
MipsSETargetLowering::MipsSETargetLowering(const MipsTargetMachine &TM,
63102
const MipsSubtarget &STI)
64103
: MipsTargetLowering(TM, STI) {

llvm/lib/Target/Mips/MipsSEISelLowering.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class TargetRegisterClass;
4545
MachineMemOperand::Flags Flags = MachineMemOperand::MONone,
4646
unsigned *Fast = nullptr) const override;
4747

48+
TargetLoweringBase::LegalizeTypeAction
49+
getPreferredVectorAction(MVT VT) const override;
50+
4851
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override;
4952

5053
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override;

0 commit comments

Comments
 (0)