Skip to content

Commit c1909d7

Browse files
committed
[DAGCombiner] Fix crash for the merge stores with different value type
The crash case comes from llvm#58350. It have two stores, one store is type f32 and the other is v1f32. When we try to merge these two stores on v1f32, the memVT is vector type so the old code will use ISD::EXTRACT_SUBVECTOR for type f32 also then compiler crash. So this patch insert a build_vector for f32 store to generate v1f32 also when memVT is v1f32. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D135954
1 parent f1f3612 commit c1909d7

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18321,6 +18321,9 @@ bool DAGCombiner::mergeStoresOfConstantsOrVecElts(
1832118321
// We may need to add a bitcast here to get types to line up.
1832218322
if (MemVTScalarTy != Val.getValueType().getScalarType()) {
1832318323
Val = DAG.getBitcast(MemVT, Val);
18324+
} else if (MemVT.isVector() &&
18325+
Val.getOpcode() == ISD::EXTRACT_VECTOR_ELT) {
18326+
Val = DAG.getNode(ISD::BUILD_VECTOR, DL, MemVT, Val);
1832418327
} else {
1832518328
unsigned OpC = MemVT.isVector() ? ISD::EXTRACT_SUBVECTOR
1832618329
: ISD::EXTRACT_VECTOR_ELT;

llvm/test/CodeGen/AArch64/pr58350.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=aarch64-none-linux-gnu | FileCheck %s
3+
4+
; This used to hit an assertion caused by dagcombine merge store.
5+
; When the store memVT is v1f32 and the other store to be merged
6+
; is f32, we need to build vector for the f32 store.
7+
8+
define void @f(<1 x float> %a, i64 %b) {
9+
; CHECK-LABEL: f:
10+
; CHECK: // %bb.0:
11+
; CHECK-NEXT: sub sp, sp, #16
12+
; CHECK-NEXT: .cfi_def_cfa_offset 16
13+
; CHECK-NEXT: adrp x8, .LCPI0_0
14+
; CHECK-NEXT: and x9, x0, #0x1
15+
; CHECK-NEXT: mov x10, sp
16+
; CHECK-NEXT: // kill: def $d0 killed $d0 def $q0
17+
; CHECK-NEXT: ldr d1, [x8, :lo12:.LCPI0_0]
18+
; CHECK-NEXT: bfi x10, x9, #2, #1
19+
; CHECK-NEXT: str d1, [sp]
20+
; CHECK-NEXT: ldr s1, [x10]
21+
; CHECK-NEXT: mov v1.s[1], v0.s[0]
22+
; CHECK-NEXT: str d1, [sp, #8]
23+
; CHECK-NEXT: add sp, sp, #16
24+
; CHECK-NEXT: ret
25+
%P = alloca i64
26+
%E = extractelement <2 x float> <float 0.5, float 1.0>, i64 %b
27+
%G = getelementptr <1 x float>, ptr %P, i64 1
28+
store float %E, ptr %P
29+
store <1 x float> %a, ptr %G
30+
ret void
31+
}

0 commit comments

Comments
 (0)