[llvm] [SelectionDAG] Use correct result type in visitEXTRACT_VECTOR_ELT (PR #148707)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 14 12:15:30 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
Author: Da Li (李达) (dlee992)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/148707.diff
1 Files Affected:
- (modified) llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (+3-3)
``````````diff
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;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/148707
More information about the llvm-commits
mailing list