[llvm] [DAGCombiner] Fold trunc(build_vector(ext(x), ext(x)) -> build_vector(x,x) (PR #179857)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 10 07:56:42 PST 2026
================
@@ -16634,16 +16634,19 @@ SDValue DAGCombiner::visitTRUNCATE(SDNode *N) {
// Attempt to pre-truncate BUILD_VECTOR sources.
if (N0.getOpcode() == ISD::BUILD_VECTOR && !LegalOperations &&
N0.hasOneUse() &&
- TLI.isTruncateFree(SrcVT.getScalarType(), VT.getScalarType()) &&
// Avoid creating illegal types if running after type legalizer.
(!LegalTypes || TLI.isTypeLegal(VT.getScalarType()))) {
- EVT SVT = VT.getScalarType();
- SmallVector<SDValue, 8> TruncOps;
- for (const SDValue &Op : N0->op_values()) {
- SDValue TruncOp = DAG.getNode(ISD::TRUNCATE, DL, SVT, Op);
- TruncOps.push_back(TruncOp);
+ if (TLI.isTruncateFree(SrcVT.getScalarType(), VT.getScalarType()))
+ return DAG.UnrollVectorOp(N);
+
+ // trunc(build_vector(ext(x), ext(x)) -> build_vector(x,x)
+ if (SDValue SplatVal = DAG.getSplatValue(N0)) {
+ unsigned Opcode = SplatVal.getOpcode();
+ if ((Opcode == ISD::SIGN_EXTEND || Opcode == ISD::ZERO_EXTEND ||
+ Opcode == ISD::ANY_EXTEND) &&
----------------
RKSimon wrote:
`if (ISD::isExtOpcode(SplatVal.getOpcode()) && SrcVT.getScalarType() == SplatVal.getValueType())`
https://github.com/llvm/llvm-project/pull/179857
More information about the llvm-commits
mailing list