aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
diff options
context:
space:
mode:
authorPaul Walker <paul.walker@arm.com>2025-06-17 11:09:22 +0100
committerGitHub <noreply@github.com>2025-06-17 11:09:22 +0100
commit465e3ce9f10019db071dc7794ae9ab22f9fc76f7 (patch)
tree1ea01ee8d81fba06e21c1467fa6d1549ebc374bc /llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
parentc377ce1216a8ce73c940d2366a7bf223790f43b4 (diff)
downloadllvm-465e3ce9f10019db071dc7794ae9ab22f9fc76f7.zip
llvm-465e3ce9f10019db071dc7794ae9ab22f9fc76f7.tar.gz
llvm-465e3ce9f10019db071dc7794ae9ab22f9fc76f7.tar.bz2
[LLVM][CodeGen] Lower ConstantInt vectors like shufflevector base splats. (#144395)
ConstantInt vectors utilise DAG.getConstant() when constructing the initial DAG. This can have the effect of legalising the constant before the DAG combiner is run, significant altering the generated code. To mitigate this (hopefully as a temporary measure) we instead try to construct the DAG in the same way as shufflevector based splats.
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index c63eb7f..4f548cb 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1791,8 +1791,26 @@ SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {
if (const Constant *C = dyn_cast<Constant>(V)) {
EVT VT = TLI.getValueType(DAG.getDataLayout(), V->getType(), true);
- if (const ConstantInt *CI = dyn_cast<ConstantInt>(C))
- return DAG.getConstant(*CI, getCurSDLoc(), VT);
+ if (const ConstantInt *CI = dyn_cast<ConstantInt>(C)) {
+ SDLoc DL = getCurSDLoc();
+
+ // DAG.getConstant() may attempt to legalise the vector constant which can
+ // significantly change the combines applied to the DAG. To reduce the
+ // divergence when enabling ConstantInt based vectors we try to construct
+ // the DAG in the same way as shufflevector based splats. TODO: The
+ // divergence sometimes leads to better optimisations. Ideally we should
+ // prevent DAG.getConstant() from legalising too early but there are some
+ // degradations preventing this.
+ if (VT.isScalableVector())
+ return DAG.getNode(
+ ISD::SPLAT_VECTOR, DL, VT,
+ DAG.getConstant(CI->getValue(), DL, VT.getVectorElementType()));
+ if (VT.isFixedLengthVector())
+ return DAG.getSplatBuildVector(
+ VT, DL,
+ DAG.getConstant(CI->getValue(), DL, VT.getVectorElementType()));
+ return DAG.getConstant(*CI, DL, VT);
+ }
if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
return DAG.getGlobalAddress(GV, getCurSDLoc(), VT);