Skip to content

Commit b794c0a

Browse files
author
Stefan Maksimovic
committedJun 23, 2017
[mips][msa] Splat.d endianness check
Before this change, it was always the first element of a vector that got splatted since the lower 6 bits of vshf.d $wd were always zero for little endian. Additionally, masking has been performed for vshf via which splat.d is created. Vshf has a property where if its first operand's elements have either bit 6 or 7 set, destination element is set to zero. Initially masked with 63 to avoid this property, which would result in generation of and.v + vshf.d in all cases. Masking with one results in generating a single splati.d instruction when possible. Differential Revision: https://reviews.llvm.org/D32216 llvm-svn: 306090
1 parent 575b25f commit b794c0a

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed
 

‎llvm/lib/Target/Mips/MipsSEISelLowering.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,28 +1257,34 @@ static SDValue lowerMSACopyIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) {
12571257
static SDValue lowerMSASplatZExt(SDValue Op, unsigned OpNr, SelectionDAG &DAG) {
12581258
EVT ResVecTy = Op->getValueType(0);
12591259
EVT ViaVecTy = ResVecTy;
1260+
bool BigEndian = !DAG.getSubtarget().getTargetTriple().isLittleEndian();
12601261
SDLoc DL(Op);
12611262

12621263
// When ResVecTy == MVT::v2i64, LaneA is the upper 32 bits of the lane and
12631264
// LaneB is the lower 32-bits. Otherwise LaneA and LaneB are alternating
12641265
// lanes.
1265-
SDValue LaneA;
1266-
SDValue LaneB = Op->getOperand(2);
1266+
SDValue LaneA = Op->getOperand(OpNr);
1267+
SDValue LaneB;
12671268

12681269
if (ResVecTy == MVT::v2i64) {
1269-
LaneA = DAG.getConstant(0, DL, MVT::i32);
1270+
LaneB = DAG.getConstant(0, DL, MVT::i32);
12701271
ViaVecTy = MVT::v4i32;
1272+
if(BigEndian)
1273+
std::swap(LaneA, LaneB);
12711274
} else
1272-
LaneA = LaneB;
1275+
LaneB = LaneA;
12731276

12741277
SDValue Ops[16] = { LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB,
12751278
LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB };
12761279

12771280
SDValue Result = DAG.getBuildVector(
12781281
ViaVecTy, DL, makeArrayRef(Ops, ViaVecTy.getVectorNumElements()));
12791282

1280-
if (ViaVecTy != ResVecTy)
1281-
Result = DAG.getNode(ISD::BITCAST, DL, ResVecTy, Result);
1283+
if (ViaVecTy != ResVecTy) {
1284+
SDValue One = DAG.getConstant(1, DL, ViaVecTy);
1285+
Result = DAG.getNode(ISD::BITCAST, DL, ResVecTy,
1286+
DAG.getNode(ISD::AND, DL, ViaVecTy, Result, One));
1287+
}
12821288

12831289
return Result;
12841290
}

‎llvm/test/CodeGen/Mips/msa/3r_splat.ll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,24 @@ declare <2 x i64> @llvm.mips.splat.d(<2 x i64>, i32) nounwind
9292
; MIPS64-DAG: splat.d [[R4:\$w[0-9]+]], [[R3]][$4]
9393
; MIPS64-DAG: st.d [[R4]], 0([[R2]])
9494
; MIPS32: .size llvm_mips_splat_d_test
95+
96+
define void @llvm_mips_splat_d_arg_test(i32 %arg) {
97+
entry:
98+
%0 = tail call <2 x i64> @llvm.mips.splat.d(<2 x i64> <i64 12720328, i64 10580959>, i32 %arg)
99+
store volatile <2 x i64> %0, <2 x i64>* @llvm_mips_splat_d_RES
100+
ret void
101+
}
102+
; CHECK-LABEL: llvm_mips_splat_d_arg_test
103+
; CHECK: ldi.w [[R1:\$w[0-9]+]], 1
104+
; CHECK: and.v [[R2:\$w[0-9]+]], {{\$w[0-9]+}}, [[R1]]
105+
; CHECK: vshf.d [[R2]], {{.*}}
106+
107+
define void @llvm_mips_splat_d_imm_test() {
108+
entry:
109+
%0 = tail call <2 x i64> @llvm.mips.splat.d(<2 x i64> <i64 12720328, i64 10580959>, i32 76)
110+
store volatile<2 x i64> %0, <2 x i64>* @llvm_mips_splat_d_RES
111+
ret void
112+
}
113+
; CHECK-LABEL: llvm_mips_splat_d_imm_test
114+
; CHECK: splati. d {{.*}}, {{.*}}[0]
115+
; CHECK-NOT: vshf.d

0 commit comments

Comments
 (0)
Please sign in to comment.