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

Commit 97ca021

Browse files
committed
[DAGCombiner] Add vector support to (mul (shl X, Y), Z) -> (shl (mul X, Z), Y) style combines
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284122 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c31d80d commit 97ca021

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,11 +2148,10 @@ SDValue DAGCombiner::visitMUL(SDNode *N) {
21482148
getShiftAmountTy(N0.getValueType()))));
21492149
}
21502150

2151-
APInt Val;
21522151
// (mul (shl X, c1), c2) -> (mul X, c2 << c1)
2153-
if (N1IsConst && N0.getOpcode() == ISD::SHL &&
2154-
(ISD::isConstantSplatVector(N0.getOperand(1).getNode(), Val) ||
2155-
isa<ConstantSDNode>(N0.getOperand(1)))) {
2152+
if (N0.getOpcode() == ISD::SHL &&
2153+
isConstantOrConstantVector(N1) &&
2154+
isConstantOrConstantVector(N0.getOperand(1))) {
21562155
SDValue C3 = DAG.getNode(ISD::SHL, SDLoc(N), VT, N1, N0.getOperand(1));
21572156
AddToWorklist(C3.getNode());
21582157
return DAG.getNode(ISD::MUL, SDLoc(N), VT, N0.getOperand(0), C3);
@@ -2162,14 +2161,14 @@ SDValue DAGCombiner::visitMUL(SDNode *N) {
21622161
// use.
21632162
{
21642163
SDValue Sh(nullptr, 0), Y(nullptr, 0);
2164+
21652165
// Check for both (mul (shl X, C), Y) and (mul Y, (shl X, C)).
21662166
if (N0.getOpcode() == ISD::SHL &&
2167-
(ISD::isConstantSplatVector(N0.getOperand(1).getNode(), Val) ||
2168-
isa<ConstantSDNode>(N0.getOperand(1))) &&
2167+
isConstantOrConstantVector(N0.getOperand(1)) &&
21692168
N0.getNode()->hasOneUse()) {
21702169
Sh = N0; Y = N1;
21712170
} else if (N1.getOpcode() == ISD::SHL &&
2172-
isa<ConstantSDNode>(N1.getOperand(1)) &&
2171+
isConstantOrConstantVector(N1.getOperand(1)) &&
21732172
N1.getNode()->hasOneUse()) {
21742173
Sh = N1; Y = N0;
21752174
}

test/CodeGen/X86/combine-mul.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ define <4 x i32> @combine_vec_mul_shl_const(<4 x i32> %x) {
146146
;
147147
; AVX-LABEL: combine_vec_mul_shl_const:
148148
; AVX: # BB#0:
149-
; AVX-NEXT: vpsllvd {{.*}}(%rip), %xmm0, %xmm0
150149
; AVX-NEXT: vpmulld {{.*}}(%rip), %xmm0, %xmm0
151150
; AVX-NEXT: retq
152151
%1 = shl <4 x i32> %x, <i32 1, i32 2, i32 8, i32 16>
@@ -164,8 +163,8 @@ define <4 x i32> @combine_vec_mul_shl_oneuse0(<4 x i32> %x, <4 x i32> %y) {
164163
;
165164
; AVX-LABEL: combine_vec_mul_shl_oneuse0:
166165
; AVX: # BB#0:
167-
; AVX-NEXT: vpsllvd {{.*}}(%rip), %xmm0, %xmm0
168166
; AVX-NEXT: vpmulld %xmm1, %xmm0, %xmm0
167+
; AVX-NEXT: vpsllvd {{.*}}(%rip), %xmm0, %xmm0
169168
; AVX-NEXT: retq
170169
%1 = shl <4 x i32> %x, <i32 1, i32 2, i32 8, i32 16>
171170
%2 = mul <4 x i32> %1, %y
@@ -181,8 +180,8 @@ define <4 x i32> @combine_vec_mul_shl_oneuse1(<4 x i32> %x, <4 x i32> %y) {
181180
;
182181
; AVX-LABEL: combine_vec_mul_shl_oneuse1:
183182
; AVX: # BB#0:
183+
; AVX-NEXT: vpmulld %xmm1, %xmm0, %xmm0
184184
; AVX-NEXT: vpsllvd {{.*}}(%rip), %xmm0, %xmm0
185-
; AVX-NEXT: vpmulld %xmm0, %xmm1, %xmm0
186185
; AVX-NEXT: retq
187186
%1 = shl <4 x i32> %x, <i32 1, i32 2, i32 8, i32 16>
188187
%2 = mul <4 x i32> %y, %1

0 commit comments

Comments
 (0)