From aaf66cc8a628a85ce00be5e8d816def9e54f0c5f Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Wed, 14 Dec 2022 16:23:45 -0800 Subject: [PATCH] [Hexagon] Record original result type in wide multiplication --- llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp b/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp index 7975fdd0..4f1c0ff 100644 --- a/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp +++ b/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp @@ -357,6 +357,7 @@ private: SValue X, Y; // If present, add 1 << RoundAt before shift: std::optional RoundAt; + VectorType *ResTy; }; auto getNumSignificantBits(Value *V, Instruction *In) const @@ -1245,7 +1246,7 @@ auto HvxIdioms::canonSgn(SValue X, SValue Y) const // Match // (X * Y) [>> N], or -// ((X * Y) + (1 << N-1)) >> N +// ((X * Y) + (1 << M)) >> N auto HvxIdioms::matchFxpMul(Instruction &In) const -> std::optional { using namespace PatternMatch; auto *Ty = In.getType(); @@ -1292,6 +1293,7 @@ auto HvxIdioms::matchFxpMul(Instruction &In) const -> std::optional { // FIXME: The information below is recomputed. Op.X.Sgn = getNumSignificantBits(Op.X.Val, &In).second; Op.Y.Sgn = getNumSignificantBits(Op.Y.Val, &In).second; + Op.ResTy = cast(Ty); return Op; } @@ -1370,6 +1372,7 @@ auto HvxIdioms::processFxpMul(Instruction &In, const FxpOp &Op) const SmallVector Results; FxpOp ChopOp = Op; + ChopOp.ResTy = VectorType::get(Op.ResTy->getElementType(), ChopLen, false); for (unsigned V = 0; V != VecLen / ChopLen; ++V) { ChopOp.X.Val = HVC.subvector(Builder, X, V * ChopLen, ChopLen); @@ -1481,7 +1484,7 @@ auto HvxIdioms::processFxpMulChopped(IRBuilderBase &Builder, Instruction &In, if (SkipWords != 0) WordP.resize(WordP.size() - SkipWords); - return HVC.joinVectorElements(Builder, WordP, InpTy); + return HVC.joinVectorElements(Builder, WordP, Op.ResTy); } auto HvxIdioms::createMulQ15(IRBuilderBase &Builder, SValue X, SValue Y, @@ -2259,6 +2262,8 @@ auto HexagonVectorCombine::joinVectorElements(IRBuilderBase &Builder, unsigned NeedInputs = ToWidth / Width; if (Inputs.size() != NeedInputs) { + // Having too many inputs is ok: drop the high bits (usual wrap-around). + // If there are too few, fill them with the sign bit. Value *Last = Inputs.back(); Value *Sign = Builder.CreateAShr(Last, getConstSplat(Last->getType(), Width - 1)); -- 2.7.4