Skip to content

Commit baf931a

Browse files
author
Krzysztof Parzyszek
committed
[Hexagon] Reconsider getMask fix, return original mask, convert later
The getPayload/getMask/getPassThrough functions should return values that could be composed into a masked load/store without any additional type casts. The previous fix violated that. Instead, convert scalar mask to a vector right before rescaling.
1 parent 7beee56 commit baf931a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,7 @@ auto AlignVectors::getMask(Value *Val) const -> Value * {
416416
int ElemCount = VecTy->getElementCount().getFixedValue();
417417
return HVC.getFullValue(HVC.getBoolTy(ElemCount));
418418
}
419-
// For scalars, return a vector <1 x i1>.
420-
return HVC.getFullValue(HVC.getBoolTy(1));
419+
return HVC.getFullValue(HVC.getBoolTy());
421420
}
422421

423422
auto AlignVectors::getPassThrough(Value *Val) const -> Value * {
@@ -811,14 +810,24 @@ auto AlignVectors::realignGroup(const MoveGroup &Move) const -> bool {
811810
// Stores.
812811
ByteSpan ASpanV, ASpanM;
813812

813+
// Return a vector value corresponding to the input value Val:
814+
// either <1 x Val> for scalar Val, or Val itself for vector Val.
815+
auto MakeVec = [](IRBuilder<> &Builder, Value *Val) -> Value * {
816+
Type *Ty = Val->getType();
817+
if (Ty->isVectorTy())
818+
return Val;
819+
auto *VecTy = VectorType::get(Ty, 1, /*Scalable*/ false);
820+
return Builder.CreateBitCast(Val, VecTy);
821+
};
822+
814823
for (int i = -1; i != NumSectors; ++i) {
815824
ByteSpan Section = VSpan.section(i * ScLen, ScLen).normalize();
816825
Value *AccumV = UndefValue::get(SecTy);
817826
Value *AccumM = HVC.getNullValue(SecTy);
818827
for (ByteSpan::Block &S : Section) {
819828
Value *Pay = getPayload(S.Seg.Val);
820-
Value *Mask = HVC.rescale(Builder, getMask(S.Seg.Val), Pay->getType(),
821-
HVC.getByteTy());
829+
Value *Mask = HVC.rescale(Builder, MakeVec(Builder, getMask(S.Seg.Val)),
830+
Pay->getType(), HVC.getByteTy());
822831
AccumM = HVC.insertb(Builder, AccumM, HVC.vbytes(Builder, Mask),
823832
S.Seg.Start, S.Seg.Size, S.Pos);
824833
AccumV = HVC.insertb(Builder, AccumV, HVC.vbytes(Builder, Pay),

0 commit comments

Comments
 (0)