Skip to content

Commit fcc33dc

Browse files
RKSimontstellar
authored andcommitted
[X86] combineAndShuffleNot - ensure the type is legal before create X86ISD::ANDNP target nodes
Fixes #84660 (cherry picked from commit 862c7e0)
1 parent 39e3ba8 commit fcc33dc

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47878,6 +47878,7 @@ static SDValue combineAndShuffleNot(SDNode *N, SelectionDAG &DAG,
4787847878
SDValue X, Y;
4787947879
SDValue N0 = N->getOperand(0);
4788047880
SDValue N1 = N->getOperand(1);
47881+
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
4788147882

4788247883
if (SDValue Not = GetNot(N0)) {
4788347884
X = Not;
@@ -47891,9 +47892,11 @@ static SDValue combineAndShuffleNot(SDNode *N, SelectionDAG &DAG,
4789147892
X = DAG.getBitcast(VT, X);
4789247893
Y = DAG.getBitcast(VT, Y);
4789347894
SDLoc DL(N);
47895+
4789447896
// We do not split for SSE at all, but we need to split vectors for AVX1 and
4789547897
// AVX2.
47896-
if (!Subtarget.useAVX512Regs() && VT.is512BitVector()) {
47898+
if (!Subtarget.useAVX512Regs() && VT.is512BitVector() &&
47899+
TLI.isTypeLegal(VT.getHalfNumVectorElementsVT(*DAG.getContext()))) {
4789747900
SDValue LoX, HiX;
4789847901
std::tie(LoX, HiX) = splitVector(X, DAG, DL);
4789947902
SDValue LoY, HiY;
@@ -47903,7 +47906,11 @@ static SDValue combineAndShuffleNot(SDNode *N, SelectionDAG &DAG,
4790347906
SDValue HiV = DAG.getNode(X86ISD::ANDNP, DL, SplitVT, {HiX, HiY});
4790447907
return DAG.getNode(ISD::CONCAT_VECTORS, DL, VT, {LoV, HiV});
4790547908
}
47906-
return DAG.getNode(X86ISD::ANDNP, DL, VT, {X, Y});
47909+
47910+
if (TLI.isTypeLegal(VT))
47911+
return DAG.getNode(X86ISD::ANDNP, DL, VT, {X, Y});
47912+
47913+
return SDValue();
4790747914
}
4790847915

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

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

Lines changed: 19 additions & 0 deletions
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)