Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 6e9255f

Browse files
committed
[DAGCombine] Add (sext_in_reg (zext x)) -> (sext x) combine
Handle the case where a sign extension has ended up being split into separate stages (typically to get around vector legal ops) and a zext + sext_in_reg gets inserted. Differential Revision: https://reviews.llvm.org/D27461 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@288842 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 02d8347 commit 6e9255f

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7137,6 +7137,15 @@ SDValue DAGCombiner::visitSIGN_EXTEND_INREG(SDNode *N) {
71377137
return DAG.getNode(ISD::SIGN_EXTEND, SDLoc(N), VT, N00, N1);
71387138
}
71397139

7140+
// fold (sext_in_reg (zext x)) -> (sext x)
7141+
// iff we are extending the source sign bit.
7142+
if (N0.getOpcode() == ISD::ZERO_EXTEND) {
7143+
SDValue N00 = N0.getOperand(0);
7144+
if (N00.getScalarValueSizeInBits() == EVTBits &&
7145+
(!LegalOperations || TLI.isOperationLegal(ISD::SIGN_EXTEND, VT)))
7146+
return DAG.getNode(ISD::SIGN_EXTEND, SDLoc(N), VT, N00, N1);
7147+
}
7148+
71407149
// fold (sext_in_reg x) -> (zext_in_reg x) if the sign bit is known zero.
71417150
if (DAG.MaskedValueIsZero(N0, APInt::getBitsSet(VTBits, EVTBits-1, EVTBits)))
71427151
return DAG.getZeroExtendInReg(N0, SDLoc(N), EVT.getScalarType());

test/CodeGen/X86/combine-sext-in-reg.ll

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,12 @@ define <4 x i64> @sextinreg_zext_sext_v16i8_4i64(<16 x i8> %a0) {
3030
; SSE-NEXT: pmovsxbq %xmm0, %xmm2
3131
; SSE-NEXT: psrld $16, %xmm0
3232
; SSE-NEXT: pmovsxbq %xmm0, %xmm1
33-
; SSE-NEXT: psllq $32, %xmm2
34-
; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm2[1,1,3,3]
35-
; SSE-NEXT: psrad $31, %xmm2
36-
; SSE-NEXT: pblendw {{.*#+}} xmm2 = xmm0[0,1],xmm2[2,3],xmm0[4,5],xmm2[6,7]
37-
; SSE-NEXT: psllq $32, %xmm1
38-
; SSE-NEXT: pshufd {{.*#+}} xmm0 = xmm1[1,1,3,3]
39-
; SSE-NEXT: psrad $31, %xmm1
40-
; SSE-NEXT: pblendw {{.*#+}} xmm1 = xmm0[0,1],xmm1[2,3],xmm0[4,5],xmm1[6,7]
4133
; SSE-NEXT: movdqa %xmm2, %xmm0
4234
; SSE-NEXT: retq
4335
;
4436
; AVX-LABEL: sextinreg_zext_sext_v16i8_4i64:
4537
; AVX: # BB#0:
4638
; AVX-NEXT: vpmovsxbq %xmm0, %ymm0
47-
; AVX-NEXT: vpsllq $32, %ymm0, %ymm0
48-
; AVX-NEXT: vpsrad $31, %ymm0, %ymm1
49-
; AVX-NEXT: vpshufd {{.*#+}} ymm0 = ymm0[1,1,3,3,5,5,7,7]
50-
; AVX-NEXT: vpblendd {{.*#+}} ymm0 = ymm0[0],ymm1[1],ymm0[2],ymm1[3],ymm0[4],ymm1[5],ymm0[6],ymm1[7]
5139
; AVX-NEXT: retq
5240
%1 = shufflevector <16 x i8> %a0, <16 x i8> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
5341
%2 = sext <4 x i8> %1 to <4 x i32>

0 commit comments

Comments
 (0)