aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
diff options
context:
space:
mode:
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);