Skip to content

Commit 618d3ae

Browse files
committedOct 20, 2016
[DAGCombiner] Add general constant vector support to (srl (shl x, c), c) -> (and x, cst2)
We already supported scalar constant / splatted constant vector - now accepts any (non opaque) constant scalar / vector llvm-svn: 284717
1 parent 113860b commit 618d3ae

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed
 

Diff for: ‎llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -4920,14 +4920,14 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
49204920
}
49214921

49224922
// fold (srl (shl x, c), c) -> (and x, cst2)
4923-
if (N1C && N0.getOpcode() == ISD::SHL && N0.getOperand(1) == N1) {
4924-
unsigned BitSize = N0.getScalarValueSizeInBits();
4925-
if (BitSize <= 64) {
4926-
uint64_t ShAmt = N1C->getZExtValue() + 64 - BitSize;
4927-
SDLoc DL(N);
4928-
return DAG.getNode(ISD::AND, DL, VT, N0.getOperand(0),
4929-
DAG.getConstant(~0ULL >> ShAmt, DL, VT));
4930-
}
4923+
if (N0.getOpcode() == ISD::SHL && N0.getOperand(1) == N1 &&
4924+
isConstantOrConstantVector(N1, /* NoOpaques */ true)) {
4925+
SDLoc DL(N);
4926+
APInt AllBits = APInt::getAllOnesValue(N0.getScalarValueSizeInBits());
4927+
SDValue Mask =
4928+
DAG.getNode(ISD::SRL, DL, VT, DAG.getConstant(AllBits, DL, VT), N1);
4929+
AddToWorklist(Mask.getNode());
4930+
return DAG.getNode(ISD::AND, DL, VT, N0.getOperand(0), Mask);
49314931
}
49324932

49334933
// fold (srl (anyextend x), c) -> (and (anyextend (srl x, c)), mask)

Diff for: ‎llvm/test/CodeGen/X86/combine-srl.ll

+2-14
Original file line numberDiff line numberDiff line change
@@ -374,24 +374,12 @@ define <4 x i32> @combine_vec_lshr_shl_mask0(<4 x i32> %x) {
374374
define <4 x i32> @combine_vec_lshr_shl_mask1(<4 x i32> %x) {
375375
; SSE-LABEL: combine_vec_lshr_shl_mask1:
376376
; SSE: # BB#0:
377-
; SSE-NEXT: pmulld {{.*}}(%rip), %xmm0
378-
; SSE-NEXT: movdqa %xmm0, %xmm1
379-
; SSE-NEXT: psrld $5, %xmm1
380-
; SSE-NEXT: movdqa %xmm0, %xmm2
381-
; SSE-NEXT: psrld $3, %xmm2
382-
; SSE-NEXT: pblendw {{.*#+}} xmm2 = xmm2[0,1,2,3],xmm1[4,5,6,7]
383-
; SSE-NEXT: movdqa %xmm0, %xmm1
384-
; SSE-NEXT: psrld $4, %xmm1
385-
; SSE-NEXT: psrld $2, %xmm0
386-
; SSE-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1,2,3],xmm1[4,5,6,7]
387-
; SSE-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm2[2,3],xmm0[4,5],xmm2[6,7]
377+
; SSE-NEXT: andps {{.*}}(%rip), %xmm0
388378
; SSE-NEXT: retq
389379
;
390380
; AVX-LABEL: combine_vec_lshr_shl_mask1:
391381
; AVX: # BB#0:
392-
; AVX-NEXT: vmovdqa {{.*#+}} xmm1 = [2,3,4,5]
393-
; AVX-NEXT: vpsllvd %xmm1, %xmm0, %xmm0
394-
; AVX-NEXT: vpsrlvd %xmm1, %xmm0, %xmm0
382+
; AVX-NEXT: vandps {{.*}}(%rip), %xmm0, %xmm0
395383
; AVX-NEXT: retq
396384
%1 = shl <4 x i32> %x, <i32 2, i32 3, i32 4, i32 5>
397385
%2 = lshr <4 x i32> %1, <i32 2, i32 3, i32 4, i32 5>

0 commit comments

Comments
 (0)