Skip to content

Commit 468ff70

Browse files
committed
[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
1 parent 4b581e8 commit 468ff70

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45014,32 +45014,9 @@ static SDValue combineVectorHADDSUB(SDNode *N, SelectionDAG &DAG,
4501445014
"Unexpected horizontal add/sub opcode");
4501545015

4501645016
if (!shouldUseHorizontalOp(true, DAG, Subtarget)) {
45017-
// For slow-hop targets, if we have a hop with a single op, see if we already
45018-
// have another user that we can reuse and shuffle the result.
4501945017
MVT VT = N->getSimpleValueType(0);
4502045018
SDValue LHS = N->getOperand(0);
4502145019
SDValue RHS = N->getOperand(1);
45022-
if (VT.is128BitVector() && LHS == RHS) {
45023-
for (SDNode *User : LHS->uses()) {
45024-
if (User != N && User->getOpcode() == N->getOpcode()) {
45025-
MVT ShufVT = VT.isFloatingPoint() ? MVT::v4f32 : MVT::v4i32;
45026-
if (User->getOperand(0) == LHS && !User->getOperand(1).isUndef()) {
45027-
return DAG.getBitcast(
45028-
VT,
45029-
DAG.getVectorShuffle(ShufVT, SDLoc(N),
45030-
DAG.getBitcast(ShufVT, SDValue(User, 0)),
45031-
DAG.getUNDEF(ShufVT), {0, 1, 0, 1}));
45032-
}
45033-
if (User->getOperand(1) == LHS && !User->getOperand(0).isUndef()) {
45034-
return DAG.getBitcast(
45035-
VT,
45036-
DAG.getVectorShuffle(ShufVT, SDLoc(N),
45037-
DAG.getBitcast(ShufVT, SDValue(User, 0)),
45038-
DAG.getUNDEF(ShufVT), {2, 3, 2, 3}));
45039-
}
45040-
}
45041-
}
45042-
}
4504345020

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

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

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