Skip to content

Commit c869bec

Browse files
committed
fixup! Address review comments
- Change what getMask returns - Change the name of TLI hooks - Limit the TLI hooks to scalable vectors only for now
1 parent 156661a commit c869bec

File tree

4 files changed

+41
-47
lines changed

4 files changed

+41
-47
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,12 +3158,10 @@ class TargetLoweringBase {
31583158
///
31593159
/// \p Load is a vp.load instruction.
31603160
/// \p Mask is a mask value
3161-
/// \p DeinterleaveIntrin is vector.deinterleave intrinsic
31623161
/// \p DeinterleaveRes is a list of deinterleaved results.
31633162
virtual bool
3164-
lowerInterleavedScalableLoad(VPIntrinsic *Load, Value *Mask,
3165-
IntrinsicInst *DeinterleaveIntrin,
3166-
ArrayRef<Value *> DeinterleaveRes) const {
3163+
lowerDeinterleavedIntrinsicToVPLoad(VPIntrinsic *Load, Value *Mask,
3164+
ArrayRef<Value *> DeinterleaveRes) const {
31673165
return false;
31683166
}
31693167

@@ -3172,12 +3170,10 @@ class TargetLoweringBase {
31723170
///
31733171
/// \p Store is the vp.store instruction.
31743172
/// \p Mask is a mask value
3175-
/// \p InterleaveIntrin is vector.interleave intrinsic
31763173
/// \p InterleaveOps is a list of values being interleaved.
31773174
virtual bool
3178-
lowerInterleavedScalableStore(VPIntrinsic *Store, Value *Mask,
3179-
IntrinsicInst *InterleaveIntrin,
3180-
ArrayRef<Value *> InterleaveOps) const {
3175+
lowerInterleavedIntrinsicToVPStore(VPIntrinsic *Store, Value *Mask,
3176+
ArrayRef<Value *> InterleaveOps) const {
31813177
return false;
31823178
}
31833179

llvm/lib/CodeGen/InterleavedAccessPass.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ getVectorDeinterleaveFactor(IntrinsicInst *II,
637637
/// - if a value within the option is nullptr, the value corresponds to all-true
638638
/// mask
639639
/// - return nullopt if mask cannot be deinterleaved
640-
static std::optional<Value *> getMask(Value *WideMask, unsigned Factor) {
640+
static Value *getMask(Value *WideMask, unsigned Factor) {
641641
using namespace llvm::PatternMatch;
642642
if (auto *IMI = dyn_cast<IntrinsicInst>(WideMask)) {
643643
SmallVector<Value *, 8> Operands;
@@ -650,8 +650,9 @@ static std::optional<Value *> getMask(Value *WideMask, unsigned Factor) {
650650
}
651651
}
652652
if (match(WideMask, m_AllOnes()))
653-
return nullptr;
654-
return std::nullopt;
653+
return WideMask;
654+
655+
return nullptr;
655656
}
656657

657658
bool InterleavedAccessImpl::lowerDeinterleaveIntrinsic(
@@ -673,7 +674,7 @@ bool InterleavedAccessImpl::lowerDeinterleaveIntrinsic(
673674
return false;
674675
// Check mask operand. Handle both all-true and interleaved mask.
675676
Value *WideMask = VPLoad->getOperand(1);
676-
std::optional<Value *> Mask = getMask(WideMask, Factor);
677+
Value *Mask = getMask(WideMask, Factor);
677678
if (!Mask)
678679
return false;
679680

@@ -682,8 +683,8 @@ bool InterleavedAccessImpl::lowerDeinterleaveIntrinsic(
682683

683684
// Since lowerInterleaveLoad expects Shuffles and LoadInst, use special
684685
// TLI function to emit target-specific interleaved instruction.
685-
if (!TLI->lowerInterleavedScalableLoad(VPLoad, *Mask, DI,
686-
DeinterleaveValues))
686+
if (!TLI->lowerDeinterleavedIntrinsicToVPLoad(VPLoad, Mask,
687+
DeinterleaveValues))
687688
return false;
688689

689690
} else {
@@ -725,7 +726,7 @@ bool InterleavedAccessImpl::lowerInterleaveIntrinsic(
725726
return false;
726727

727728
Value *WideMask = VPStore->getOperand(2);
728-
std::optional<Value *> Mask = getMask(WideMask, Factor);
729+
Value *Mask = getMask(WideMask, Factor);
729730
if (!Mask)
730731
return false;
731732

@@ -734,8 +735,8 @@ bool InterleavedAccessImpl::lowerInterleaveIntrinsic(
734735

735736
// Since lowerInterleavedStore expects Shuffle and StoreInst, use special
736737
// TLI function to emit target-specific interleaved instruction.
737-
if (!TLI->lowerInterleavedScalableStore(VPStore, *Mask, II,
738-
InterleaveValues))
738+
if (!TLI->lowerInterleavedIntrinsicToVPStore(VPStore, Mask,
739+
InterleaveValues))
739740
return false;
740741
} else {
741742
auto *SI = cast<StoreInst>(StoredBy);

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22555,15 +22555,20 @@ bool RISCVTargetLowering::lowerInterleaveIntrinsicToStore(
2255522555
///
2255622556
/// NOTE: the deinterleave2 intrinsic won't be touched and is expected to be
2255722557
/// removed by the caller
22558-
bool RISCVTargetLowering::lowerInterleavedScalableLoad(
22559-
VPIntrinsic *Load, Value *Mask, IntrinsicInst *DeinterleaveIntrin,
22558+
bool RISCVTargetLowering::lowerDeinterleavedIntrinsicToVPLoad(
22559+
VPIntrinsic *Load, Value *Mask,
2256022560
ArrayRef<Value *> DeInterleaveResults) const {
22561+
assert(Mask && "Expect a valid mask");
2256122562
assert(Load->getIntrinsicID() == Intrinsic::vp_load &&
2256222563
"Unexpected intrinsic");
2256322564

2256422565
const unsigned Factor = DeInterleaveResults.size();
2256522566

22566-
auto *WideVTy = cast<VectorType>(Load->getType());
22567+
auto *WideVTy = dyn_cast<ScalableVectorType>(Load->getType());
22568+
// TODO: Support fixed vectors.
22569+
if (!WideVTy)
22570+
return false;
22571+
2256722572
unsigned WideNumElements = WideVTy->getElementCount().getKnownMinValue();
2256822573
assert(WideNumElements % Factor == 0 &&
2256922574
"ElementCount of a wide load must be divisible by interleave factor");
@@ -22605,10 +22610,6 @@ bool RISCVTargetLowering::lowerInterleavedScalableLoad(
2260522610
SmallVector<Value *> Operands;
2260622611
Operands.append({PoisonVal, Load->getArgOperand(0)});
2260722612

22608-
if (!Mask)
22609-
Mask = ConstantVector::getSplat(VTy->getElementCount(),
22610-
ConstantInt::getTrue(Load->getContext()));
22611-
2261222613
Function *VlsegNFunc = Intrinsic::getOrInsertDeclaration(
2261322614
Load->getModule(), IntrMaskIds[Factor - 2],
2261422615
{VecTupTy, Mask->getType(), EVL->getType()});
@@ -22653,16 +22654,12 @@ bool RISCVTargetLowering::lowerInterleavedScalableLoad(
2265322654
/// into
2265422655
/// `<vscale x 8 x i32>`. This will resuling a simple unit stride store rather
2265522656
/// than a segment store, which is more expensive in this case.
22656-
static Value *foldInterleaved2OfConstSplats(IntrinsicInst *InterleaveIntrin,
22657+
static Value *foldInterleaved2OfConstSplats(Value *Op0, Value *Op1,
2265722658
VectorType *VTy,
2265822659
const TargetLowering *TLI,
2265922660
Instruction *VPStore) {
22660-
// We only handle Factor = 2 for now.
22661-
assert(InterleaveIntrin->arg_size() == 2);
22662-
auto *SplatVal0 = dyn_cast_or_null<ConstantInt>(
22663-
getSplatValue(InterleaveIntrin->getArgOperand(0)));
22664-
auto *SplatVal1 = dyn_cast_or_null<ConstantInt>(
22665-
getSplatValue(InterleaveIntrin->getArgOperand(1)));
22661+
auto *SplatVal0 = dyn_cast_or_null<ConstantInt>(getSplatValue(Op0));
22662+
auto *SplatVal1 = dyn_cast_or_null<ConstantInt>(getSplatValue(Op1));
2266622663
if (!SplatVal0 || !SplatVal1)
2266722664
return nullptr;
2266822665

@@ -22711,15 +22708,19 @@ static Value *foldInterleaved2OfConstSplats(IntrinsicInst *InterleaveIntrin,
2271122708
/// <vscale x 32 x i8> %load2, ptr %ptr,
2271222709
/// %mask,
2271322710
/// i64 %rvl)
22714-
bool RISCVTargetLowering::lowerInterleavedScalableStore(
22715-
VPIntrinsic *Store, Value *Mask, IntrinsicInst *InterleaveIntrin,
22711+
bool RISCVTargetLowering::lowerInterleavedIntrinsicToVPStore(
22712+
VPIntrinsic *Store, Value *Mask,
2271622713
ArrayRef<Value *> InterleaveOperands) const {
22714+
assert(Mask && "Expect a valid mask");
2271722715
assert(Store->getIntrinsicID() == Intrinsic::vp_store &&
2271822716
"Unexpected intrinsic");
2271922717

2272022718
const unsigned Factor = InterleaveOperands.size();
2272122719

22722-
VectorType *VTy = cast<VectorType>(InterleaveOperands[0]->getType());
22720+
auto *VTy = dyn_cast<ScalableVectorType>(InterleaveOperands[0]->getType());
22721+
// TODO: Support fixed vectors.
22722+
if (!VTy)
22723+
return false;
2272322724

2272422725
// FIXME: Should pass alignment attribute from pointer, but vectorizer needs
2272522726
// to emit it first.
@@ -22731,9 +22732,10 @@ bool RISCVTargetLowering::lowerInterleavedScalableStore(
2273122732
return false;
2273222733

2273322734
if (Factor == 2)
22734-
if (Value *BC =
22735-
foldInterleaved2OfConstSplats(InterleaveIntrin, VTy, this, Store)) {
22736-
InterleaveIntrin->replaceAllUsesWith(BC);
22735+
if (Value *BC = foldInterleaved2OfConstSplats(
22736+
InterleaveOperands[0], InterleaveOperands[1], VTy, this, Store)) {
22737+
// Store is guranteed to be the only user of the interleaved intrinsic.
22738+
Store->getOperand(0)->replaceAllUsesWith(BC);
2273722739
return true;
2273822740
}
2273922741

@@ -22770,10 +22772,6 @@ bool RISCVTargetLowering::lowerInterleavedScalableStore(
2277022772
Operands.push_back(StoredVal);
2277122773
Operands.push_back(Store->getArgOperand(1));
2277222774

22773-
if (!Mask)
22774-
Mask = ConstantVector::getSplat(VTy->getElementCount(),
22775-
ConstantInt::getTrue(Store->getContext()));
22776-
2277722775
Function *VssegNFunc = Intrinsic::getOrInsertDeclaration(
2277822776
Store->getModule(), IntrMaskIds[Factor - 2],
2277922777
{VecTupTy, Mask->getType(), EVL->getType()});

llvm/lib/Target/RISCV/RISCVISelLowering.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -910,14 +910,13 @@ class RISCVTargetLowering : public TargetLowering {
910910
bool lowerInterleaveIntrinsicToStore(
911911
StoreInst *SI, ArrayRef<Value *> InterleaveValues) const override;
912912

913-
bool lowerInterleavedScalableLoad(
914-
VPIntrinsic *Load, Value *Mask, IntrinsicInst *DeinterleaveIntrin,
913+
bool lowerDeinterleavedIntrinsicToVPLoad(
914+
VPIntrinsic *Load, Value *Mask,
915915
ArrayRef<Value *> DeinterleaveRes) const override;
916916

917-
bool
918-
lowerInterleavedScalableStore(VPIntrinsic *Store, Value *Mask,
919-
IntrinsicInst *InterleaveIntrin,
920-
ArrayRef<Value *> InterleaveOps) const override;
917+
bool lowerInterleavedIntrinsicToVPStore(
918+
VPIntrinsic *Store, Value *Mask,
919+
ArrayRef<Value *> InterleaveOps) const override;
921920

922921
bool supportKCFIBundles() const override { return true; }
923922

0 commit comments

Comments
 (0)