@@ -13752,8 +13752,12 @@ static void createTblForTrunc(TruncInst *TI, bool IsLittleEndian) {
13752
13752
"Unsupported destination vector element type");
13753
13753
unsigned SrcElemTySz =
13754
13754
cast<IntegerType>(SrcTy->getElementType())->getBitWidth();
13755
- unsigned TruncFactor =
13756
- SrcElemTySz / cast<IntegerType>(DstTy->getElementType())->getBitWidth();
13755
+ unsigned DstElemTySz =
13756
+ cast<IntegerType>(DstTy->getElementType())->getBitWidth();
13757
+ assert((SrcElemTySz % DstElemTySz == 0) &&
13758
+ "Cannot lower truncate to tbl instructions for a source element size "
13759
+ "that is not divisible by the destination element size");
13760
+ unsigned TruncFactor = SrcElemTySz / DstElemTySz;
13757
13761
assert((SrcElemTySz == 16 || SrcElemTySz == 32 || SrcElemTySz == 64) &&
13758
13762
"Unsupported source vector element type size");
13759
13763
Type *VecTy = FixedVectorType::get(Builder.getInt8Ty(), 16);
@@ -13765,12 +13769,11 @@ static void createTblForTrunc(TruncInst *TI, bool IsLittleEndian) {
13765
13769
SmallVector<Constant *, 16> MaskConst;
13766
13770
for (int Itr = 0; Itr < 16; Itr++) {
13767
13771
if (Itr < NumElements)
13768
- MaskConst.push_back(ConstantInt::get(
13769
- Builder.getInt8Ty(), IsLittleEndian
13770
- ? Itr * TruncFactor
13771
- : Itr * TruncFactor + (TruncFactor - 1)));
13772
+ MaskConst.push_back(Builder.getInt8(
13773
+ IsLittleEndian ? Itr * TruncFactor
13774
+ : Itr * TruncFactor + (TruncFactor - 1)));
13772
13775
else
13773
- MaskConst.push_back(ConstantInt::get( Builder.getInt8Ty(), 255));
13776
+ MaskConst.push_back(Builder.getInt8( 255));
13774
13777
}
13775
13778
13776
13779
int MaxTblSz = 128 * 4;
@@ -13793,7 +13796,7 @@ static void createTblForTrunc(TruncInst *TI, bool IsLittleEndian) {
13793
13796
Parts.push_back(Builder.CreateBitCast(
13794
13797
Builder.CreateShuffleVector(TI->getOperand(0), ShuffleLanes), VecTy));
13795
13798
13796
- if (Parts.size() > = 4) {
13799
+ if (Parts.size() = = 4) {
13797
13800
auto *F = Intrinsic::getDeclaration(TI->getModule(),
13798
13801
Intrinsic::aarch64_neon_tbl4, VecTy);
13799
13802
Parts.push_back(ConstantVector::get(MaskConst));
0 commit comments