Skip to content

Commit 75e33f7

Browse files
RKSimontstellar
authored andcommitted
[X86] combineVectorHADDSUB - remove the broken HOP(x,x) merging code (PR51974)
This intention of this code turns out to be superfluous as we can handle this with shuffle combining, and it has a critical flaw in that it doesn't check for dependencies. Fixes PR51974 (cherry picked from commit 468ff70)
1 parent 6349865 commit 75e33f7

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

-23
Original file line numberDiff line numberDiff line change
@@ -44076,32 +44076,9 @@ static SDValue combineVectorHADDSUB(SDNode *N, SelectionDAG &DAG,
4407644076
"Unexpected horizontal add/sub opcode");
4407744077

4407844078
if (!shouldUseHorizontalOp(true, DAG, Subtarget)) {
44079-
// For slow-hop targets, if we have a hop with a single op, see if we already
44080-
// have another user that we can reuse and shuffle the result.
4408144079
MVT VT = N->getSimpleValueType(0);
4408244080
SDValue LHS = N->getOperand(0);
4408344081
SDValue RHS = N->getOperand(1);
44084-
if (VT.is128BitVector() && LHS == RHS) {
44085-
for (SDNode *User : LHS->uses()) {
44086-
if (User != N && User->getOpcode() == N->getOpcode()) {
44087-
MVT ShufVT = VT.isFloatingPoint() ? MVT::v4f32 : MVT::v4i32;
44088-
if (User->getOperand(0) == LHS && !User->getOperand(1).isUndef()) {
44089-
return DAG.getBitcast(
44090-
VT,
44091-
DAG.getVectorShuffle(ShufVT, SDLoc(N),
44092-
DAG.getBitcast(ShufVT, SDValue(User, 0)),
44093-
DAG.getUNDEF(ShufVT), {0, 1, 0, 1}));
44094-
}
44095-
if (User->getOperand(1) == LHS && !User->getOperand(0).isUndef()) {
44096-
return DAG.getBitcast(
44097-
VT,
44098-
DAG.getVectorShuffle(ShufVT, SDLoc(N),
44099-
DAG.getBitcast(ShufVT, SDValue(User, 0)),
44100-
DAG.getUNDEF(ShufVT), {2, 3, 2, 3}));
44101-
}
44102-
}
44103-
}
44104-
}
4410544082

4410644083
// HOP(HOP'(X,X),HOP'(Y,Y)) -> HOP(PERMUTE(HOP'(X,Y)),PERMUTE(HOP'(X,Y)).
4410744084
if (LHS != RHS && LHS.getOpcode() == N->getOpcode() &&

llvm/test/CodeGen/X86/horizontal-shuffle-2.ll

+19
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,25 @@ define <4 x float> @test_unpacklo_hadd_v4f32_unary(<4 x float> %0) {
171171
ret <4 x float> %3
172172
}
173173

174+
define <8 x i16> @PR51974(<8 x i16> %a0) {
175+
; SSE-LABEL: PR51974:
176+
; SSE: ## %bb.0:
177+
; SSE-NEXT: movdqa %xmm0, %xmm1
178+
; SSE-NEXT: phaddw %xmm0, %xmm1
179+
; SSE-NEXT: phaddw %xmm0, %xmm1
180+
; SSE-NEXT: movdqa %xmm1, %xmm0
181+
; SSE-NEXT: ret{{[l|q]}}
182+
;
183+
; AVX-LABEL: PR51974:
184+
; AVX: ## %bb.0:
185+
; AVX-NEXT: vphaddw %xmm0, %xmm0, %xmm1
186+
; AVX-NEXT: vphaddw %xmm0, %xmm1, %xmm0
187+
; AVX-NEXT: ret{{[l|q]}}
188+
%r0 = call <8 x i16> @llvm.x86.ssse3.phadd.w.128(<8 x i16> %a0, <8 x i16> %a0)
189+
%r1 = call <8 x i16> @llvm.x86.ssse3.phadd.w.128(<8 x i16> %r0, <8 x i16> %a0)
190+
ret <8 x i16> %r1
191+
}
192+
174193
declare <4 x float> @llvm.x86.sse3.hadd.ps(<4 x float>, <4 x float>)
175194
declare <4 x float> @llvm.x86.sse3.hsub.ps(<4 x float>, <4 x float>)
176195
declare <2 x double> @llvm.x86.sse3.hadd.pd(<2 x double>, <2 x double>)

0 commit comments

Comments
 (0)