[llvm] [SelectionDAG] Use correct result type in visitEXTRACT_VECTOR_ELT (PR #148707)

Da Li 李达 via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 14 12:14:42 PDT 2025


https://github.com/dlee992 created https://github.com/llvm/llvm-project/pull/148707

In `visitEXTRACT_VECTOR_ELT`, we should use `ScalarVT` instead of `LVT` as the result VT for return and method call. 

If the DAG has these two nodes (this is generated from `llvm-project/llvm/test/CodeGen/Generic/extractelement-shuffle.ll` with a private backend implementation):
```
        t22: v64i32,ch = load<(load (s2048) from %stack.0, align 64)> t43, FrameIndex:i64<0>, undef:i64
      t24: i64 = extract_vector_elt t22, Constant:i64<3>
```
It could apply this combiner rule (i.e., `(vextract (v4f32 load $addr), c) -> (f32 load $addr+c*size)`) then hit a failure:
```
Combining: t24: i64 = extract_vector_elt t22, Constant:i64<3>
Creating constant: t47: i64 = Constant<63>
Creating constant: t48: i64 = Constant<4>
Creating constant: t49: i64 = Constant<12>
Creating new node: t50: i64 = add FrameIndex:i64<0>, Constant:i64<12>
Creating new node: t51: i32,ch = load<(load (s32) from %stack.0 + 12)> t43, t50, undef:i64
 ... into: t51: i32,ch = load<(load (s32) from %stack.0 + 12)> t43, t50, undef:i64
llc: ${HOME}/llvm-project/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp:1830: void (anonymous namespace)::DAGCombiner::Run(CombineLevel): Assertion `N->getValueType(0) == RV.getValueType() && N->getNumValues() == 1 && "Type mismatch"' failed.
```

This PR will fix this issue.

>From cb71f48f5f380a928bac4d99e60eabc4436f1762 Mon Sep 17 00:00:00 2001
From: dlee992 <lidanuaa at gmail.com>
Date: Mon, 14 Jul 2025 14:04:49 -0500
Subject: [PATCH] use ScalarVT in visitEXTRACT_VECTOR_ELT

---
 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 8136f1794775e..f26ee0ace6919 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -23440,10 +23440,10 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR_ELT(SDNode *N) {
 
   // If Idx was -1 above, Elt is going to be -1, so just return undef.
   if (Elt == -1)
-    return DAG.getUNDEF(LVT);
+    return DAG.getUNDEF(ScalarVT);
 
-  if (SDValue Scalarized =
-          TLI.scalarizeExtractedVectorLoad(LVT, DL, VecVT, Index, LN0, DAG)) {
+  if (SDValue Scalarized = TLI.scalarizeExtractedVectorLoad(ScalarVT, DL, VecVT,
+                                                            Index, LN0, DAG)) {
     ++OpsNarrowed;
     return Scalarized;
   }



More information about the llvm-commits mailing list