[llvm] aaf66cc - [Hexagon] Record original result type in wide multiplication
Krzysztof Parzyszek via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 15 07:19:46 PST 2022
Author: Krzysztof Parzyszek
Date: 2022-12-15T07:19:23-08:00
New Revision: aaf66cc8a628a85ce00be5e8d816def9e54f0c5f
URL: https://github.com/llvm/llvm-project/commit/aaf66cc8a628a85ce00be5e8d816def9e54f0c5f
DIFF: https://github.com/llvm/llvm-project/commit/aaf66cc8a628a85ce00be5e8d816def9e54f0c5f.diff
LOG: [Hexagon] Record original result type in wide multiplication
Added:
Modified:
llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp b/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
index 7975fdd0fe3d..4f1c0ffd241a 100644
--- a/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
@@ -357,6 +357,7 @@ class HvxIdioms {
SValue X, Y;
// If present, add 1 << RoundAt before shift:
std::optional<unsigned> 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<FxpOp> {
using namespace PatternMatch;
auto *Ty = In.getType();
@@ -1292,6 +1293,7 @@ auto HvxIdioms::matchFxpMul(Instruction &In) const -> std::optional<FxpOp> {
// 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<VectorType>(Ty);
return Op;
}
@@ -1370,6 +1372,7 @@ auto HvxIdioms::processFxpMul(Instruction &In, const FxpOp &Op) const
SmallVector<Value *> 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));
More information about the llvm-commits
mailing list