Skip to content

Commit 862c7e0

Browse files
committed
[X86] combineAndShuffleNot - ensure the type is legal before create X86ISD::ANDNP target nodes
Fixes llvm#84660
1 parent 033dbbe commit 862c7e0

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -48179,6 +48179,7 @@ static SDValue combineAndShuffleNot(SDNode *N, SelectionDAG &DAG,
4817948179
SDValue X, Y;
4818048180
SDValue N0 = N->getOperand(0);
4818148181
SDValue N1 = N->getOperand(1);
48182+
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
4818248183

4818348184
if (SDValue Not = GetNot(N0)) {
4818448185
X = Not;
@@ -48192,9 +48193,11 @@ static SDValue combineAndShuffleNot(SDNode *N, SelectionDAG &DAG,
4819248193
X = DAG.getBitcast(VT, X);
4819348194
Y = DAG.getBitcast(VT, Y);
4819448195
SDLoc DL(N);
48196+
4819548197
// We do not split for SSE at all, but we need to split vectors for AVX1 and
4819648198
// AVX2.
48197-
if (!Subtarget.useAVX512Regs() && VT.is512BitVector()) {
48199+
if (!Subtarget.useAVX512Regs() && VT.is512BitVector() &&
48200+
TLI.isTypeLegal(VT.getHalfNumVectorElementsVT(*DAG.getContext()))) {
4819848201
SDValue LoX, HiX;
4819948202
std::tie(LoX, HiX) = splitVector(X, DAG, DL);
4820048203
SDValue LoY, HiY;
@@ -48204,7 +48207,11 @@ static SDValue combineAndShuffleNot(SDNode *N, SelectionDAG &DAG,
4820448207
SDValue HiV = DAG.getNode(X86ISD::ANDNP, DL, SplitVT, {HiX, HiY});
4820548208
return DAG.getNode(ISD::CONCAT_VECTORS, DL, VT, {LoV, HiV});
4820648209
}
48207-
return DAG.getNode(X86ISD::ANDNP, DL, VT, {X, Y});
48210+
48211+
if (TLI.isTypeLegal(VT))
48212+
return DAG.getNode(X86ISD::ANDNP, DL, VT, {X, Y});
48213+
48214+
return SDValue();
4820848215
}
4820948216

4821048217
// Try to widen AND, OR and XOR nodes to VT in order to remove casts around

llvm/test/CodeGen/X86/combine-and.ll

+19
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,25 @@ define <4 x i32> @neg_scalar_broadcast_two_uses(i32 %a0, <4 x i32> %a1, ptr %a2)
11711171
ret <4 x i32> %4
11721172
}
11731173

1174+
; PR84660 - check for illegal types
1175+
define <2 x i128> @neg_scalar_broadcast_illegaltype(i128 %arg) {
1176+
; CHECK-LABEL: neg_scalar_broadcast_illegaltype:
1177+
; CHECK: # %bb.0:
1178+
; CHECK-NEXT: movq %rdi, %rax
1179+
; CHECK-NEXT: notl %esi
1180+
; CHECK-NEXT: andl $1, %esi
1181+
; CHECK-NEXT: movq %rsi, 16(%rdi)
1182+
; CHECK-NEXT: movq %rsi, (%rdi)
1183+
; CHECK-NEXT: movq $0, 24(%rdi)
1184+
; CHECK-NEXT: movq $0, 8(%rdi)
1185+
; CHECK-NEXT: retq
1186+
%i = xor i128 %arg, 1
1187+
%i1 = insertelement <2 x i128> zeroinitializer, i128 %i, i64 0
1188+
%i2 = shufflevector <2 x i128> %i1, <2 x i128> zeroinitializer, <2 x i32> zeroinitializer
1189+
%i3 = and <2 x i128> <i128 1, i128 1>, %i2
1190+
ret <2 x i128> %i3
1191+
}
1192+
11741193
define <2 x i64> @andnp_xx(<2 x i64> %v0) nounwind {
11751194
; SSE-LABEL: andnp_xx:
11761195
; SSE: # %bb.0:

0 commit comments

Comments
 (0)