Skip to content

Commit 8e98435

Browse files
authored
[GISel][Combine] Enhance combining on G_BUILD_VECTOR
Reviewers: aemerson, arsenm Reviewed By: arsenm Pull Request: #87831
1 parent 7248c9f commit 8e98435

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,8 +2925,10 @@ bool CombinerHelper::matchCombineInsertVecElts(
29252925
}
29262926
return true;
29272927
}
2928-
// If we didn't end in a G_IMPLICIT_DEF, bail out.
2929-
return TmpInst->getOpcode() == TargetOpcode::G_IMPLICIT_DEF;
2928+
// If we didn't end in a G_IMPLICIT_DEF and the source is not fully
2929+
// overwritten, bail out.
2930+
return TmpInst->getOpcode() == TargetOpcode::G_IMPLICIT_DEF ||
2931+
all_of(MatchInfo, [](Register Reg) { return !!Reg; });
29302932
}
29312933

29322934
void CombinerHelper::applyCombineInsertVecElts(

llvm/test/CodeGen/AArch64/GlobalISel/combine-extract-vec-elt.mir

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,37 @@ body: |
220220
$x0 = COPY %extract(s64)
221221
RET_ReallyLR implicit $x0
222222
223+
...
224+
---
225+
# This test checks that this combine runs after the insertvec->build_vector
226+
name: extract_from_insert2
227+
tracksRegLiveness: true
228+
liveins:
229+
- { reg: '$x0' }
230+
- { reg: '$x1' }
231+
frameInfo:
232+
maxAlignment: 1
233+
body: |
234+
bb.1:
235+
liveins: $q0, $x0, $x1
236+
; CHECK-LABEL: name: extract_from_insert2
237+
; CHECK: liveins: $q0, $x0, $x1
238+
; CHECK-NEXT: {{ $}}
239+
; CHECK-NEXT: %arg1:_(s64) = COPY $x0
240+
; CHECK-NEXT: %arg2:_(s64) = COPY $x1
241+
; CHECK-NEXT: %ins2:_(<2 x s64>) = G_BUILD_VECTOR %arg1(s64), %arg2(s64)
242+
; CHECK-NEXT: $q0 = COPY %ins2(<2 x s64>)
243+
; CHECK-NEXT: RET_ReallyLR implicit $q0
244+
%arg0:_(<2 x s64>) = COPY $q0
245+
%arg1:_(s64) = COPY $x0
246+
%arg2:_(s64) = COPY $x1
247+
%zero:_(s32) = G_CONSTANT i32 0
248+
%one:_(s32) = G_CONSTANT i32 1
249+
%ins1:_(<2 x s64>) = G_INSERT_VECTOR_ELT %arg0, %arg1(s64), %zero(s32)
250+
%ins2:_(<2 x s64>) = G_INSERT_VECTOR_ELT %ins1, %arg2(s64), %one(s32)
251+
$q0 = COPY %ins2(<2 x s64>)
252+
RET_ReallyLR implicit $q0
253+
223254
...
224255
---
225256
name: extract_from_idx_negative

0 commit comments

Comments
 (0)