Skip to content

Commit 2f502f3

Browse files
committed
[Hexagon] Remove unnecessarily complicated helpers (NFC)
All the constant construction APIs already have native splat support. They can be directly used with a vector. It's not necessary to first create a scalar constant and then splat it to the element count.
1 parent 734ea9a commit 2f502f3

File tree

1 file changed

+12
-43
lines changed

1 file changed

+12
-43
lines changed

llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp

Lines changed: 12 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ class HexagonVectorCombine {
120120
size_t length(Value *Val) const;
121121
size_t length(Type *Ty) const;
122122

123-
Constant *getNullValue(Type *Ty) const;
124-
Constant *getFullValue(Type *Ty) const;
125-
Constant *getConstSplat(Type *Ty, int Val) const;
126-
127123
Value *simplify(Value *Val) const;
128124

129125
Value *insertb(IRBuilderBase &Builder, Value *Dest, Value *Src, int Start,
@@ -682,8 +678,8 @@ auto AlignVectors::getMask(Value *Val) const -> Value * {
682678

683679
Type *ValTy = getPayload(Val)->getType();
684680
if (auto *VecTy = dyn_cast<VectorType>(ValTy))
685-
return HVC.getFullValue(HVC.getBoolTy(HVC.length(VecTy)));
686-
return HVC.getFullValue(HVC.getBoolTy());
681+
return Constant::getAllOnesValue(HVC.getBoolTy(HVC.length(VecTy)));
682+
return Constant::getAllOnesValue(HVC.getBoolTy());
687683
}
688684

689685
auto AlignVectors::getPassThrough(Value *Val) const -> Value * {
@@ -1122,7 +1118,7 @@ auto AlignVectors::realignLoadGroup(IRBuilderBase &Builder,
11221118
BasicBlock *BaseBlock = Builder.GetInsertBlock();
11231119

11241120
ByteSpan ASpan;
1125-
auto *True = HVC.getFullValue(HVC.getBoolTy(ScLen));
1121+
auto *True = Constant::getAllOnesValue(HVC.getBoolTy(ScLen));
11261122
auto *Undef = UndefValue::get(SecTy);
11271123

11281124
// Created load does not have to be "Instruction" (e.g. "undef").
@@ -1349,7 +1345,7 @@ auto AlignVectors::realignStoreGroup(IRBuilderBase &Builder,
13491345
ByteSpan VSection =
13501346
VSpan.section(Index * ScLen, ScLen).shift(-Index * ScLen);
13511347
Value *Undef = UndefValue::get(SecTy);
1352-
Value *Zero = HVC.getNullValue(SecTy);
1348+
Value *Zero = Constant::getNullValue(SecTy);
13531349
Value *AccumV = Undef;
13541350
Value *AccumM = Zero;
13551351
for (ByteSpan::Block &S : VSection) {
@@ -2699,11 +2695,11 @@ auto HvxIdioms::processFxpMulChopped(IRBuilderBase &Builder, Instruction &In,
26992695
// Do full-precision multiply and shift.
27002696
Value *Prod32 = createMul16(Builder, Op.X, Op.Y);
27012697
if (Rounding) {
2702-
Value *RoundVal = HVC.getConstSplat(Prod32->getType(), 1 << *Op.RoundAt);
2698+
Value *RoundVal = ConstantInt::get(Prod32->getType(), 1 << *Op.RoundAt);
27032699
Prod32 = Builder.CreateAdd(Prod32, RoundVal, "add");
27042700
}
27052701

2706-
Value *ShiftAmt = HVC.getConstSplat(Prod32->getType(), Op.Frac);
2702+
Value *ShiftAmt = ConstantInt::get(Prod32->getType(), Op.Frac);
27072703
Value *Shifted = Op.X.Sgn == Signed || Op.Y.Sgn == Signed
27082704
? Builder.CreateAShr(Prod32, ShiftAmt, "asr")
27092705
: Builder.CreateLShr(Prod32, ShiftAmt, "lsr");
@@ -2722,18 +2718,18 @@ auto HvxIdioms::processFxpMulChopped(IRBuilderBase &Builder, Instruction &In,
27222718

27232719
// Add the optional rounding to the proper word.
27242720
if (Op.RoundAt.has_value()) {
2725-
Value *Zero = HVC.getNullValue(WordX[0]->getType());
2721+
Value *Zero = Constant::getNullValue(WordX[0]->getType());
27262722
SmallVector<Value *> RoundV(WordP.size(), Zero);
27272723
RoundV[*Op.RoundAt / 32] =
2728-
HVC.getConstSplat(HvxWordTy, 1 << (*Op.RoundAt % 32));
2724+
ConstantInt::get(HvxWordTy, 1 << (*Op.RoundAt % 32));
27292725
WordP = createAddLong(Builder, WordP, RoundV);
27302726
}
27312727

27322728
// createRightShiftLong?
27332729

27342730
// Shift all products right by Op.Frac.
27352731
unsigned SkipWords = Op.Frac / 32;
2736-
Constant *ShiftAmt = HVC.getConstSplat(HvxWordTy, Op.Frac % 32);
2732+
Constant *ShiftAmt = ConstantInt::get(HvxWordTy, Op.Frac % 32);
27372733

27382734
for (int Dst = 0, End = WordP.size() - SkipWords; Dst != End; ++Dst) {
27392735
int Src = Dst + SkipWords;
@@ -2802,7 +2798,7 @@ auto HvxIdioms::createAddCarry(IRBuilderBase &Builder, Value *X, Value *Y,
28022798
} else {
28032799
AddCarry = HVC.HST.getIntrinsicId(Hexagon::V6_vaddcarry);
28042800
if (CarryIn == nullptr)
2805-
CarryIn = HVC.getNullValue(HVC.getBoolTy(HVC.length(VecTy)));
2801+
CarryIn = Constant::getNullValue(HVC.getBoolTy(HVC.length(VecTy)));
28062802
Args.push_back(CarryIn);
28072803
}
28082804
Value *Ret = HVC.createHvxIntrinsic(Builder, AddCarry,
@@ -2950,7 +2946,7 @@ auto HvxIdioms::createMulLong(IRBuilderBase &Builder, ArrayRef<Value *> WordX,
29502946
}
29512947
}
29522948

2953-
Value *Zero = HVC.getNullValue(WordX[0]->getType());
2949+
Value *Zero = Constant::getNullValue(WordX[0]->getType());
29542950

29552951
auto pop_back_or_zero = [Zero](auto &Vector) -> Value * {
29562952
if (Vector.empty())
@@ -3146,33 +3142,6 @@ auto HexagonVectorCombine::length(Type *Ty) const -> size_t {
31463142
return VecTy->getElementCount().getFixedValue();
31473143
}
31483144

3149-
auto HexagonVectorCombine::getNullValue(Type *Ty) const -> Constant * {
3150-
assert(Ty->isIntOrIntVectorTy());
3151-
auto Zero = ConstantInt::get(Ty->getScalarType(), 0);
3152-
if (auto *VecTy = dyn_cast<VectorType>(Ty))
3153-
return ConstantVector::getSplat(VecTy->getElementCount(), Zero);
3154-
return Zero;
3155-
}
3156-
3157-
auto HexagonVectorCombine::getFullValue(Type *Ty) const -> Constant * {
3158-
assert(Ty->isIntOrIntVectorTy());
3159-
auto Minus1 = ConstantInt::getAllOnesValue(Ty->getScalarType());
3160-
if (auto *VecTy = dyn_cast<VectorType>(Ty))
3161-
return ConstantVector::getSplat(VecTy->getElementCount(), Minus1);
3162-
return Minus1;
3163-
}
3164-
3165-
auto HexagonVectorCombine::getConstSplat(Type *Ty, int Val) const
3166-
-> Constant * {
3167-
assert(Ty->isVectorTy());
3168-
auto VecTy = cast<VectorType>(Ty);
3169-
Type *ElemTy = VecTy->getElementType();
3170-
// Add support for floats if needed.
3171-
auto *Splat = ConstantVector::getSplat(VecTy->getElementCount(),
3172-
ConstantInt::get(ElemTy, Val));
3173-
return Splat;
3174-
}
3175-
31763145
auto HexagonVectorCombine::simplify(Value *V) const -> Value * {
31773146
if (auto *In = dyn_cast<Instruction>(V)) {
31783147
SimplifyQuery Q(DL, &TLI, &DT, &AC, In);
@@ -3580,7 +3549,7 @@ auto HexagonVectorCombine::joinVectorElements(IRBuilderBase &Builder,
35803549
// If there are too few, fill them with the sign bit.
35813550
Value *Last = Inputs.back();
35823551
Value *Sign = Builder.CreateAShr(
3583-
Last, getConstSplat(Last->getType(), Width - 1), "asr");
3552+
Last, ConstantInt::get(Last->getType(), Width - 1), "asr");
35843553
Inputs.resize(NeedInputs, Sign);
35853554
}
35863555

0 commit comments

Comments
 (0)