Skip to content

Commit bbefd57

Browse files
committed
[TargetLowering] Handle vector types in expandFixedPointMul (#102635)
In TargetLowering::expandFixedPointMul when expanding fixed point multiplication, and when using a widened MUL as strategy for the lowering, there was a bug resulting in assertion failures like this: Assertion `VT.isVector() == N1.getValueType().isVector() && "SIGN_EXTEND result type type should be vector iff the operand " "type is vector!"' failed. Problem was that we did not consider that VT could be a vector type when setting up the WideVT. This patch should fix that bug.
1 parent c69b8c4 commit bbefd57

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10782,6 +10782,9 @@ TargetLowering::expandFixedPointMul(SDNode *Node, SelectionDAG &DAG) const {
1078210782
unsigned LoHiOp = Signed ? ISD::SMUL_LOHI : ISD::UMUL_LOHI;
1078310783
unsigned HiOp = Signed ? ISD::MULHS : ISD::MULHU;
1078410784
EVT WideVT = EVT::getIntegerVT(*DAG.getContext(), VTSize * 2);
10785+
if (VT.isVector())
10786+
WideVT =
10787+
EVT::getVectorVT(*DAG.getContext(), WideVT, VT.getVectorElementCount());
1078510788
if (isOperationLegalOrCustom(LoHiOp, VT)) {
1078610789
SDValue Result = DAG.getNode(LoHiOp, dl, DAG.getVTList(VT, VT), LHS, RHS);
1078710790
Lo = Result.getValue(0);

llvm/test/CodeGen/AArch64/smul_fix.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,17 @@ define <4 x i64> @vec3(<4 x i64> %x, <4 x i64> %y) nounwind {
137137
%tmp = call <4 x i64> @llvm.smul.fix.v4i64(<4 x i64> %x, <4 x i64> %y, i32 32)
138138
ret <4 x i64> %tmp
139139
}
140+
141+
define <4 x i16> @widemul(<4 x i16> %x, <4 x i16> %y) nounwind {
142+
; CHECK-LABEL: widemul:
143+
; CHECK: // %bb.0:
144+
; CHECK-NEXT: smull v0.4s, v0.4h, v1.4h
145+
; CHECK-NEXT: shrn v1.4h, v0.4s, #16
146+
; CHECK-NEXT: xtn v2.4h, v0.4s
147+
; CHECK-NEXT: add v1.4h, v1.4h, v1.4h
148+
; CHECK-NEXT: shl v0.4h, v1.4h, #13
149+
; CHECK-NEXT: usra v0.4h, v2.4h, #2
150+
; CHECK-NEXT: ret
151+
%tmp = call <4 x i16> @llvm.smul.fix.v4i16(<4 x i16> %x, <4 x i16> %y, i32 2)
152+
ret <4 x i16> %tmp
153+
}

llvm/test/CodeGen/AArch64/umul_fix.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,17 @@ define <4 x i64> @vec3(<4 x i64> %x, <4 x i64> %y) nounwind {
145145
%tmp = call <4 x i64> @llvm.umul.fix.v4i64(<4 x i64> %x, <4 x i64> %y, i32 32)
146146
ret <4 x i64> %tmp
147147
}
148+
149+
define <4 x i16> @widemul(<4 x i16> %x, <4 x i16> %y) nounwind {
150+
; CHECK-LABEL: widemul:
151+
; CHECK: // %bb.0:
152+
; CHECK-NEXT: umull v0.4s, v0.4h, v1.4h
153+
; CHECK-NEXT: shrn v1.4h, v0.4s, #16
154+
; CHECK-NEXT: xtn v2.4h, v0.4s
155+
; CHECK-NEXT: add v1.4h, v1.4h, v1.4h
156+
; CHECK-NEXT: shl v0.4h, v1.4h, #11
157+
; CHECK-NEXT: usra v0.4h, v2.4h, #4
158+
; CHECK-NEXT: ret
159+
%tmp = call <4 x i16> @llvm.umul.fix.v4i16(<4 x i16> %x, <4 x i16> %y, i32 4)
160+
ret <4 x i16> %tmp
161+
}

0 commit comments

Comments
 (0)