Skip to content

Commit e5827e7

Browse files
committed
[AArch64] Protect against scalable vectors in performUADDVAddCombine.
Fixes llvm#162983
1 parent eaa6a28 commit e5827e7

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19093,7 +19093,8 @@ static SDValue performUADDVAddCombine(SDValue A, SelectionDAG &DAG) {
1909319093
SDValue Ext1 = Op1.getOperand(0);
1909419094
if (Ext0.getOpcode() != ISD::EXTRACT_SUBVECTOR ||
1909519095
Ext1.getOpcode() != ISD::EXTRACT_SUBVECTOR ||
19096-
Ext0.getOperand(0) != Ext1.getOperand(0))
19096+
Ext0.getOperand(0) != Ext1.getOperand(0) ||
19097+
Ext0.getOperand(0).getValueType().isScalableVector())
1909719098
return SDValue();
1909819099
// Check that the type is twice the add types, and the extract are from
1909919100
// upper/lower parts of the same source.

llvm/test/CodeGen/AArch64/vecreduce-add.ll

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4775,6 +4775,39 @@ entry:
47754775
ret i32 %z5
47764776
}
47774777

4778+
define i64 @extract_scalable(<2 x i32> %0) "target-features"="+sve2" {
4779+
; CHECK-SD-LABEL: extract_scalable:
4780+
; CHECK-SD: // %bb.0:
4781+
; CHECK-SD-NEXT: movi v1.2s, #1
4782+
; CHECK-SD-NEXT: ptrue p0.s, vl2
4783+
; CHECK-SD-NEXT: // kill: def $d0 killed $d0 def $z0
4784+
; CHECK-SD-NEXT: sdivr z0.s, p0/m, z0.s, z1.s
4785+
; CHECK-SD-NEXT: saddl v0.2d, v0.2s, v0.2s
4786+
; CHECK-SD-NEXT: addp d0, v0.2d
4787+
; CHECK-SD-NEXT: fmov x0, d0
4788+
; CHECK-SD-NEXT: ret
4789+
;
4790+
; CHECK-GI-LABEL: extract_scalable:
4791+
; CHECK-GI: // %bb.0:
4792+
; CHECK-GI-NEXT: // kill: def $d0 killed $d0 def $q0
4793+
; CHECK-GI-NEXT: fmov w9, s0
4794+
; CHECK-GI-NEXT: mov w8, #1 // =0x1
4795+
; CHECK-GI-NEXT: mov w10, v0.s[1]
4796+
; CHECK-GI-NEXT: sdiv w9, w8, w9
4797+
; CHECK-GI-NEXT: sdiv w8, w8, w10
4798+
; CHECK-GI-NEXT: fmov s0, w9
4799+
; CHECK-GI-NEXT: mov v0.s[1], w8
4800+
; CHECK-GI-NEXT: saddl v0.2d, v0.2s, v0.2s
4801+
; CHECK-GI-NEXT: addp d0, v0.2d
4802+
; CHECK-GI-NEXT: fmov x0, d0
4803+
; CHECK-GI-NEXT: ret
4804+
%2 = sdiv <2 x i32> splat (i32 1), %0
4805+
%3 = sext <2 x i32> %2 to <2 x i64>
4806+
%4 = add <2 x i64> %3, %3
4807+
%5 = tail call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %4)
4808+
ret i64 %5
4809+
}
4810+
47784811
declare <8 x i32> @llvm.abs.v8i32(<8 x i32>, i1 immarg) #1
47794812
declare i16 @llvm.vector.reduce.add.v32i16(<32 x i16>)
47804813
declare i16 @llvm.vector.reduce.add.v24i16(<24 x i16>)

0 commit comments

Comments
 (0)