[llvm] [CodeGen] Lower vector interleaves of const splats to a wider splat (PR #151110)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 29 03:40:02 PDT 2025
================
@@ -12594,27 +12594,40 @@ void SelectionDAGBuilder::visitVectorDeinterleave(const CallInst &I,
setValue(&I, Res);
}
-void SelectionDAGBuilder::visitVectorInterleave(const CallInst &I,
+void SelectionDAGBuilder::visitVectorInterleave(const CallInst &CI,
unsigned Factor) {
auto DL = getCurSDLoc();
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
- EVT InVT = getValue(I.getOperand(0)).getValueType();
- EVT OutVT = TLI.getValueType(DAG.getDataLayout(), I.getType());
+ EVT InVT = getValue(CI.getOperand(0)).getValueType();
+ EVT OutVT = TLI.getValueType(DAG.getDataLayout(), CI.getType());
SmallVector<SDValue, 8> InVecs(Factor);
- for (unsigned i = 0; i < Factor; ++i) {
- InVecs[i] = getValue(I.getOperand(i));
- assert(InVecs[i].getValueType() == InVecs[0].getValueType() &&
+ bool OperandsAreSame = true;
+ for (unsigned I = 0; I < Factor; ++I) {
+ InVecs[I] = getValue(CI.getOperand(I));
+ assert(InVecs[I].getValueType() == InVecs[0].getValueType() &&
"Expected VTs to be the same");
+ if (InVecs[I] != InVecs[0])
+ OperandsAreSame = false;
+ }
+
+ if (OperandsAreSame) {
+ if (auto *C = dyn_cast<Constant>(CI.getOperand(0))) {
+ if (auto *SV = C->getSplatValue()) {
+ SDValue Res = DAG.getNode(ISD::SPLAT_VECTOR, DL, OutVT, getValue(SV));
----------------
lukel97 wrote:
I presume we want to use build_vector for fixed vector types, it's still canonical? `DAG.getSplat` will choose between the two I think
```suggestion
SDValue Res = DAG.getSplat(OutVT, DL, getValue(SV));
```
https://github.com/llvm/llvm-project/pull/151110
More information about the llvm-commits
mailing list