Skip to content

Commit 79a2aa6

Browse files
author
Simon Moll
committed
Merge commit '53efbc15cb8e2b98bbd02ff39765561d2426b111' into merge/ve-mask-broadcast
2 parents ad523ac + 53efbc1 commit 79a2aa6

File tree

7 files changed

+113
-17
lines changed

7 files changed

+113
-17
lines changed

llvm/lib/Target/VE/ShuffleSynthesis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ struct GatherShuffleOp final : public AbstractShuffleOp {
11731173
}
11741174

11751175
SDValue MaxVLV = CDAG.getConstEVL(MaxVL);
1176-
SDValue BasePtrV = CDAG.getBroadcast(PtrVecVT, VecSlotPtr);
1176+
SDValue BasePtrV = CDAG.getBroadcast(PtrVecVT, VecSlotPtr, MaxVLV);
11771177
SDValue OffsetV = CDAG.getNode(
11781178
ISD::BUILD_VECTOR, PtrVecVT,
11791179
GatherOffsets); // TODO directly call into constant vector generation

llvm/lib/Target/VE/VE.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace llvm {
3838

3939
/// Target Constants {
4040
const unsigned StandardVectorWidth = 256;
41-
const unsigned PackedWidth = 512;
41+
const unsigned PackedVectorWidth = 512;
4242
/// } Target Constants
4343

4444
// Enums corresponding to VE condition codes, both icc's and fcc's. These

llvm/lib/Target/VE/VECustomDAG.cpp

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,20 @@ static SDValue supplementPackedReplication(SDValue Op, SelectionDAG &DAG) {
696696
return DAG.getNode(VEISD::VEC_BROADCAST, DL, VT, {ReplOp, VLOp});
697697
}
698698

699-
bool isMaskType(EVT VT) {
700-
if (!VT.isVector())
701-
return false;
699+
MVT getLegalVectorType(Packing P, MVT ElemVT) {
700+
return MVT::getVectorVT(ElemVT, P == Packing::Normal ? StandardVectorWidth
701+
: PackedVectorWidth);
702+
}
702703

703-
// an actual bit mask type
704-
return VT.getVectorElementType() == MVT::i1;
704+
Packing getTypePacking(EVT VT) {
705+
assert(VT.isVector());
706+
return isPackedVectorType(VT) ? Packing::Dense : Packing::Normal;
707+
}
708+
709+
bool isMaskType(EVT SomeVT) {
710+
if (!SomeVT.isVector())
711+
return false;
712+
return SomeVT.getVectorElementType() == MVT::i1;
705713
}
706714

707715
bool maySafelyIgnoreMask(unsigned VVPOpcode) {
@@ -1085,6 +1093,48 @@ SDValue VECustomDAG::getConstant(uint64_t Val, EVT VT, bool IsTarget,
10851093

10861094
void VECustomDAG::dumpValue(SDValue V) const { V->print(dbgs(), &DAG); }
10871095

1096+
SDValue VECustomDAG::getConstantMask(Packing Packing, bool AllTrue) const {
1097+
auto MaskVT = getLegalVectorType(Packing, MVT::i1);
1098+
1099+
// VEISelDAGtoDAG will replace this pattern with the constant-true VM.
1100+
auto TrueVal = DAG.getConstant(-1, DL, MVT::i32);
1101+
auto AVL = getConstant(MaskVT.getVectorNumElements(), MVT::i32);
1102+
auto Res = getNode(VEISD::VEC_BROADCAST, MaskVT, {TrueVal, AVL});
1103+
if (AllTrue)
1104+
return Res;
1105+
1106+
return DAG.getNOT(DL, Res, Res.getValueType());
1107+
}
1108+
1109+
SDValue VECustomDAG::getMaskBroadcast(EVT ResultVT, SDValue Scalar,
1110+
SDValue AVL) const {
1111+
// Constant mask splat.
1112+
if (auto BcConst = dyn_cast<ConstantSDNode>(Scalar))
1113+
return getConstantMask(getTypePacking(ResultVT),
1114+
BcConst->getSExtValue() != 0);
1115+
1116+
// Expand the broadcast to a vector comparison.
1117+
auto ScalarBoolVT = Scalar.getSimpleValueType();
1118+
assert(ScalarBoolVT == MVT::i32);
1119+
1120+
// Cast to i32 ty.
1121+
SDValue CmpElem = DAG.getSExtOrTrunc(Scalar, DL, MVT::i32);
1122+
unsigned ElemCount = ResultVT.getVectorNumElements();
1123+
MVT CmpVecTy = MVT::getVectorVT(ScalarBoolVT, ElemCount);
1124+
1125+
// Broadcast to vector.
1126+
SDValue BCVec =
1127+
DAG.getNode(VEISD::VEC_BROADCAST, DL, CmpVecTy, {CmpElem, AVL});
1128+
SDValue ZeroVec =
1129+
getBroadcast(CmpVecTy, {DAG.getConstant(0, DL, ScalarBoolVT)}, AVL);
1130+
1131+
MVT BoolVecTy = MVT::getVectorVT(MVT::i1, ElemCount);
1132+
1133+
// Broadcast(Data) != Broadcast(0)
1134+
// TODO: Use a VVP operation for this.
1135+
return DAG.getSetCC(DL, BoolVecTy, BCVec, ZeroVec, ISD::CondCode::SETNE);
1136+
}
1137+
10881138
SDValue VECustomDAG::getVectorExtract(SDValue VecV, SDValue IdxV) const {
10891139
assert(VecV.getValueType().isVector());
10901140
auto ElemVT = VecV.getValueType().getVectorElementType();
@@ -1167,7 +1217,7 @@ SDValue VECustomDAG::createConstantTargetMask(VVPWideningInfo WidenInfo) const {
11671217
// we do not want to go through ::ReplaceNodeResults again only to have them
11681218
// widened
11691219
unsigned NativeVectorWidth =
1170-
WidenInfo.PackedMode ? PackedWidth : StandardVectorWidth;
1220+
WidenInfo.PackedMode ? PackedVectorWidth : StandardVectorWidth;
11711221

11721222
// Generate a remainder mask for packed operations
11731223
Packing PackFlag = WidenInfo.PackedMode ? Packing::Dense : Packing::Normal;
@@ -1182,7 +1232,7 @@ SDValue VECustomDAG::createConstantTargetMask(VVPWideningInfo WidenInfo) const {
11821232
MaskBits.flip();
11831233
size_t OddRemainderBitPos = WidenInfo.ActiveVectorLength;
11841234
MaskBits[OddRemainderBitPos] = false;
1185-
return createConstMask<>(PackedWidth, MaskBits);
1235+
return createConstMask<>(PackedVectorWidth, MaskBits);
11861236
}
11871237
}
11881238

llvm/lib/Target/VE/VECustomDAG.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ SDValue getUnpackAVL(SDValue N);
195195

196196
/// } Packing
197197

198+
bool isMaskType(EVT SomeVT);
199+
198200
bool isVVPOrVEC(unsigned);
199201

200202
bool maySafelyIgnoreMask(unsigned Opc);
@@ -241,6 +243,12 @@ std::pair<SDValue, bool> getAnnotatedNodeAVL(SDValue);
241243

242244
/// } AVL Functions
243245

246+
// Get the vector or mask register type for this packing and element type.
247+
MVT getLegalVectorType(Packing P, MVT ElemVT);
248+
249+
// Whether this type belongs to a packed mask or vector register.
250+
Packing getTypePacking(EVT);
251+
244252
/// Helper class for short hand custom node creation ///
245253
struct VECustomDAG {
246254
const VELoweringInfo &VLI;
@@ -292,7 +300,6 @@ struct VECustomDAG {
292300
SDValue foldAndUnpackMask(SDValue MaskVector, SDValue Mask, PackElem Part,
293301
SDValue AVL) const;
294302
/// } Mask Insert/Extract
295-
SDValue getBroadcast(EVT ResultVT, SDValue Scalar, SDValue AVL = SDValue()) const;
296303

297304
// Extract an SX register from a mask
298305
SDValue createMaskExtract(SDValue MaskV, SDValue Idx) const;
@@ -525,6 +532,9 @@ struct VECustomDAG {
525532

526533
raw_ostream &print(raw_ostream &, SDValue) const;
527534
void dump(SDValue) const;
535+
SDValue getConstantMask(Packing Packing, bool AllTrue) const;
536+
SDValue getMaskBroadcast(EVT ResultVT, SDValue Scalar, SDValue AVL) const;
537+
SDValue getBroadcast(EVT ResultVT, SDValue Scalar, SDValue AVL) const;
528538

529539
// Wrap AVL in a LEGALAVL node (unless it is one already).
530540
SDValue annotateLegalAVL(SDValue AVL) const;

llvm/lib/Target/VE/VEISelDAGToDAG.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "VE.h"
1314
#include "VETargetMachine.h"
1415
#include "llvm/CodeGen/MachineRegisterInfo.h"
1516
#include "llvm/CodeGen/SelectionDAGISel.h"

llvm/lib/Target/VE/VVPISelLowering.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ static bool OpNeedsSplitting(SDNode &Op) {
141141
return !supportsPackedMode(Op.getOpcode(), OpVecTy);
142142
#if 0
143143
unsigned OpVectorLength = OpVecTy.getVectorNumElements();
144-
assert((OpVectorLength <= PackedWidth) &&
144+
assert((OpVectorLength <= PackedVectorWidth) &&
145145
"Operation should have been split during legalization");
146146
return (OpVectorLength != StandardVectorWidth) &&
147-
(OpVectorLength != PackedWidth);
147+
(OpVectorLength != PackedVectorWidth);
148148
#endif
149149
}
150150

@@ -441,7 +441,7 @@ void VETargetLowering::initVPUActions() {
441441
// Vector length legalization
442442
auto LegalizeVectorLength = [&](unsigned VL) -> unsigned {
443443
if (this->Subtarget->hasPackedMode()) {
444-
return VL > StandardVectorWidth ? PackedWidth : StandardVectorWidth;
444+
return VL > StandardVectorWidth ? PackedVectorWidth : StandardVectorWidth;
445445
} else {
446446
return StandardVectorWidth;
447447
}
@@ -590,7 +590,7 @@ void VETargetLowering::initVPUActions() {
590590
unsigned W = VT.getVectorMinNumElements();
591591

592592
// Use default splitting for vlens > 512
593-
if (W > PackedWidth)
593+
if (W > PackedVectorWidth)
594594
continue;
595595

596596
// Promotion rule, accept native element bit sizes
@@ -761,7 +761,7 @@ EVT VETargetLowering::LegalizeVectorType(EVT ResTy, SDValue Op,
761761
assert(ResTy.isVector());
762762
unsigned TargetWidth = (Subtarget->hasPackedMode() &&
763763
ResTy.getVectorNumElements() > StandardVectorWidth)
764-
? PackedWidth
764+
? PackedVectorWidth
765765
: StandardVectorWidth;
766766

767767
// Use vXi1 as result type in native widening mode
@@ -1439,12 +1439,12 @@ VVPWideningInfo VETargetLowering::pickResultType(VECustomDAG &CDAG, SDValue Op,
14391439

14401440
if ((ElemTy != MVT::i1 && ElemTy != MVT::i32 && ElemTy != MVT::f32 &&
14411441
ElemTy != MVT::f64 && ElemTy != MVT::i64) ||
1442-
(OpVectorLength > PackedWidth)) {
1442+
(OpVectorLength > PackedVectorWidth)) {
14431443
LLVM_DEBUG(dbgs() << "\tToNative: Over-sized data type\n";);
14441444
return VVPWideningInfo();
14451445
}
14461446

1447-
VectorWidth = PackedWidth;
1447+
VectorWidth = PackedVectorWidth;
14481448
} else {
14491449
VectorWidth = StandardVectorWidth;
14501450
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=ve-unknown-unknown -mattr=+vpu | FileCheck %s
3+
4+
define fastcc <256 x i1> @brd_v256i1_s(i1 %s) {
5+
; CHECK-LABEL: brd_v256i1_s:
6+
; CHECK: # %bb.0:
7+
; CHECK-NEXT: lea %s1, 256
8+
; CHECK-NEXT: lvl %s1
9+
; CHECK-NEXT: vbrd %v0, %s0
10+
; CHECK-NEXT: vfmk.w.ne %vm1, %v0
11+
; CHECK-NEXT: b.l.t (, %s10)
12+
%val = insertelement <256 x i1> undef, i1 %s, i32 0
13+
%ret = shufflevector <256 x i1> %val, <256 x i1> undef, <256 x i32> zeroinitializer
14+
ret <256 x i1> %ret
15+
}
16+
17+
define fastcc <256 x i1> @brd_v256i1_zero() {
18+
; CHECK-LABEL: brd_v256i1_zero:
19+
; CHECK: # %bb.0:
20+
; CHECK-NEXT: xorm %vm1, %vm0, %vm0
21+
; CHECK-NEXT: b.l.t (, %s10)
22+
%val = insertelement <256 x i1> undef, i1 0, i32 0
23+
%ret = shufflevector <256 x i1> %val, <256 x i1> undef, <256 x i32> zeroinitializer
24+
ret <256 x i1> %ret
25+
}
26+
27+
define fastcc <256 x i1> @brd_v256i1_one() {
28+
; CHECK-LABEL: brd_v256i1_one:
29+
; CHECK: # %bb.0:
30+
; CHECK-NEXT: andm %vm1, %vm0, %vm0
31+
; CHECK-NEXT: b.l.t (, %s10)
32+
%val = insertelement <256 x i1> undef, i1 1, i32 0
33+
%ret = shufflevector <256 x i1> %val, <256 x i1> undef, <256 x i32> zeroinitializer
34+
ret <256 x i1> %ret
35+
}

0 commit comments

Comments
 (0)