Skip to content

Commit 03f338e

Browse files
committed
[AArch64] Ensure we do not access illegal operands in tryCombineMULLWithUZP1
#65015 shows a case where tryCombineMULLWithUZP1 could attempt to look at the wrong operand of another user instruction. This adds an extra else as if we don't find the right opcode, we don't need to check the operands. Differential Revision: https://reviews.llvm.org/D159282
1 parent 87117a2 commit 03f338e

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23017,19 +23017,20 @@ static SDValue tryCombineMULLWithUZP1(SDNode *N,
2301723017
// Check ExtractLow's user.
2301823018
if (HasFoundMULLow) {
2301923019
SDNode *ExtractLowUser = *ExtractLow.getNode()->use_begin();
23020-
if (ExtractLowUser->getOpcode() != N->getOpcode())
23020+
if (ExtractLowUser->getOpcode() != N->getOpcode()) {
2302123021
HasFoundMULLow = false;
23022-
23023-
if (ExtractLowUser->getOperand(0) == ExtractLow) {
23024-
if (ExtractLowUser->getOperand(1).getOpcode() == ISD::TRUNCATE)
23025-
TruncLow = ExtractLowUser->getOperand(1);
23026-
else
23027-
HasFoundMULLow = false;
2302823022
} else {
23029-
if (ExtractLowUser->getOperand(0).getOpcode() == ISD::TRUNCATE)
23030-
TruncLow = ExtractLowUser->getOperand(0);
23031-
else
23032-
HasFoundMULLow = false;
23023+
if (ExtractLowUser->getOperand(0) == ExtractLow) {
23024+
if (ExtractLowUser->getOperand(1).getOpcode() == ISD::TRUNCATE)
23025+
TruncLow = ExtractLowUser->getOperand(1);
23026+
else
23027+
HasFoundMULLow = false;
23028+
} else {
23029+
if (ExtractLowUser->getOperand(0).getOpcode() == ISD::TRUNCATE)
23030+
TruncLow = ExtractLowUser->getOperand(0);
23031+
else
23032+
HasFoundMULLow = false;
23033+
}
2303323034
}
2303423035
}
2303523036

llvm/test/CodeGen/AArch64/aarch64-smull.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,8 +1330,27 @@ entry:
13301330
ret void
13311331
}
13321332

1333+
define <2 x i32> @do_stuff(<2 x i64> %0, <2 x i64> %1) {
1334+
; CHECK-LABEL: do_stuff:
1335+
; CHECK: // %bb.0:
1336+
; CHECK-NEXT: uzp1 v0.4s, v0.4s, v0.4s
1337+
; CHECK-NEXT: smull2 v0.2d, v1.4s, v0.4s
1338+
; CHECK-NEXT: xtn v0.2s, v0.2d
1339+
; CHECK-NEXT: add v0.2s, v0.2s, v1.2s
1340+
; CHECK-NEXT: ret
1341+
%bc.1 = bitcast <2 x i64> %1 to <4 x i32>
1342+
%trunc.0 = trunc <2 x i64> %0 to <2 x i32>
1343+
%shuff.hi = shufflevector <4 x i32> %bc.1, <4 x i32> zeroinitializer, <2 x i32> <i32 2, i32 3>
1344+
%shuff.lo = shufflevector <4 x i32> %bc.1, <4 x i32> zeroinitializer, <2 x i32> <i32 0, i32 1>
1345+
%smull = tail call <2 x i64> @llvm.aarch64.neon.smull.v2i64(<2 x i32> %shuff.hi, <2 x i32> %trunc.0)
1346+
%trunc.smull = trunc <2 x i64> %smull to <2 x i32>
1347+
%final = add <2 x i32> %trunc.smull, %shuff.lo
1348+
ret <2 x i32> %final
1349+
}
1350+
13331351
declare <8 x i16> @llvm.aarch64.neon.pmull.v8i16(<8 x i8>, <8 x i8>)
13341352
declare <8 x i16> @llvm.aarch64.neon.smull.v8i16(<8 x i8>, <8 x i8>)
13351353
declare <8 x i16> @llvm.aarch64.neon.umull.v8i16(<8 x i8>, <8 x i8>)
13361354
declare <4 x i32> @llvm.aarch64.neon.smull.v4i32(<4 x i16>, <4 x i16>)
13371355
declare <4 x i32> @llvm.aarch64.neon.umull.v4i32(<4 x i16>, <4 x i16>)
1356+
declare <2 x i64> @llvm.aarch64.neon.smull.v2i64(<2 x i32>, <2 x i32>)

0 commit comments

Comments
 (0)