Skip to content

Commit 92d7992

Browse files
authored
[AArch64] Only apply bool vector bitcast opt if result is scalar (#81256)
This optimization tries to optimize bitcasts from `<N x i1>` to iN, but currently also triggers for `<N x i1>` to `<M x iK>` bitcasts, if custom lowering has been requested for these for an unrelated reason. Fix this by explicitly checking that the result type is scalar. Fixes #81216.
1 parent 074f7c2 commit 92d7992

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -24615,7 +24615,8 @@ void AArch64TargetLowering::ReplaceBITCASTResults(
2461524615
return;
2461624616
}
2461724617

24618-
if (SrcVT.isVector() && SrcVT.getVectorElementType() == MVT::i1)
24618+
if (SrcVT.isVector() && SrcVT.getVectorElementType() == MVT::i1 &&
24619+
!VT.isVector())
2461924620
return replaceBoolVectorBitcast(N, Results, DAG);
2462024621

2462124622
if (VT != MVT::i16 || (SrcVT != MVT::f16 && SrcVT != MVT::bf16))

llvm/test/CodeGen/AArch64/vec-combine-compare-to-bitmask.ll

+28
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,31 @@ define i6 @no_combine_illegal_num_elements(<6 x i32> %vec) {
489489
%bitmask = bitcast <6 x i1> %cmp_result to i6
490490
ret i6 %bitmask
491491
}
492+
493+
; Only apply the combine when casting a vector to a scalar.
494+
define <2 x i8> @vector_to_vector_cast(<16 x i1> %arg) nounwind {
495+
; CHECK-LABEL: vector_to_vector_cast:
496+
; CHECK: ; %bb.0:
497+
; CHECK-NEXT: sub sp, sp, #16
498+
; CHECK-NEXT: shl.16b v0, v0, #7
499+
; CHECK-NEXT: Lloh36:
500+
; CHECK-NEXT: adrp x8, lCPI20_0@PAGE
501+
; CHECK-NEXT: Lloh37:
502+
; CHECK-NEXT: ldr q1, [x8, lCPI20_0@PAGEOFF]
503+
; CHECK-NEXT: add x8, sp, #14
504+
; CHECK-NEXT: cmlt.16b v0, v0, #0
505+
; CHECK-NEXT: and.16b v0, v0, v1
506+
; CHECK-NEXT: ext.16b v1, v0, v0, #8
507+
; CHECK-NEXT: zip1.16b v0, v0, v1
508+
; CHECK-NEXT: addv.8h h0, v0
509+
; CHECK-NEXT: str h0, [sp, #14]
510+
; CHECK-NEXT: ld1.b { v0 }[0], [x8]
511+
; CHECK-NEXT: orr x8, x8, #0x1
512+
; CHECK-NEXT: ld1.b { v0 }[4], [x8]
513+
; CHECK-NEXT: ; kill: def $d0 killed $d0 killed $q0
514+
; CHECK-NEXT: add sp, sp, #16
515+
; CHECK-NEXT: ret
516+
; CHECK-NEXT: .loh AdrpLdr Lloh36, Lloh37
517+
%bc = bitcast <16 x i1> %arg to <2 x i8>
518+
ret <2 x i8> %bc
519+
}

0 commit comments

Comments
 (0)