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

Commit 707719e

Browse files
committed
[DAGCombiner] Enable AND combines of splatted constant vectors
Allow AND combines to use a vector splatted constant as well as a constant scalar. Preliminary part of D24253. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280926 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ad84cf4 commit 707719e

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,7 +3099,7 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
30993099

31003100
// fold (and c1, c2) -> c1&c2
31013101
ConstantSDNode *N0C = getAsNonOpaqueConstant(N0);
3102-
ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1);
3102+
ConstantSDNode *N1C = isConstOrConstSplat(N1);
31033103
if (N0C && N1C && !N1C->isOpaque())
31043104
return DAG.FoldConstantArithmetic(ISD::AND, SDLoc(N), VT, N0C, N1C);
31053105
// canonicalize constant to RHS
@@ -3119,14 +3119,14 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
31193119
return RAND;
31203120
// fold (and (or x, C), D) -> D if (C & D) == D
31213121
if (N1C && N0.getOpcode() == ISD::OR)
3122-
if (ConstantSDNode *ORI = dyn_cast<ConstantSDNode>(N0.getOperand(1)))
3122+
if (ConstantSDNode *ORI = isConstOrConstSplat(N0.getOperand(1)))
31233123
if ((ORI->getAPIntValue() & N1C->getAPIntValue()) == N1C->getAPIntValue())
31243124
return N1;
31253125
// fold (and (any_ext V), c) -> (zero_ext V) if 'and' only clears top bits.
31263126
if (N1C && N0.getOpcode() == ISD::ANY_EXTEND) {
31273127
SDValue N0Op0 = N0.getOperand(0);
31283128
APInt Mask = ~N1C->getAPIntValue();
3129-
Mask = Mask.trunc(N0Op0.getValueSizeInBits());
3129+
Mask = Mask.trunc(N0Op0.getScalarValueSizeInBits());
31303130
if (DAG.MaskedValueIsZero(N0Op0, Mask)) {
31313131
SDValue Zext = DAG.getNode(ISD::ZERO_EXTEND, SDLoc(N),
31323132
N0.getValueType(), N0Op0);
@@ -3177,7 +3177,7 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
31773177
// that will apply equally to all members of the vector, so AND all the
31783178
// lanes of the constant together.
31793179
EVT VT = Vector->getValueType(0);
3180-
unsigned BitWidth = VT.getVectorElementType().getSizeInBits();
3180+
unsigned BitWidth = VT.getScalarType().getSizeInBits();
31813181

31823182
// If the splat value has been compressed to a bitlength lower
31833183
// than the size of the vector lane, we need to re-expand it to
@@ -3251,9 +3251,9 @@ SDValue DAGCombiner::visitAND(SDNode *N) {
32513251
// fold (and (load x), 255) -> (zextload x, i8)
32523252
// fold (and (extload x, i16), 255) -> (zextload x, i8)
32533253
// fold (and (any_ext (extload x, i16)), 255) -> (zextload x, i8)
3254-
if (N1C && (N0.getOpcode() == ISD::LOAD ||
3255-
(N0.getOpcode() == ISD::ANY_EXTEND &&
3256-
N0.getOperand(0).getOpcode() == ISD::LOAD))) {
3254+
if (!VT.isVector() && N1C && (N0.getOpcode() == ISD::LOAD ||
3255+
(N0.getOpcode() == ISD::ANY_EXTEND &&
3256+
N0.getOperand(0).getOpcode() == ISD::LOAD))) {
32573257
bool HasAnyExt = N0.getOpcode() == ISD::ANY_EXTEND;
32583258
LoadSDNode *LN0 = HasAnyExt
32593259
? cast<LoadSDNode>(N0.getOperand(0))

test/CodeGen/X86/combine-and.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ define <4 x i32> @test17(<4 x i32> %A, <4 x i32> %B) {
186186
define <2 x i64> @and_or_v2i64(<2 x i64> %a0) {
187187
; CHECK-LABEL: and_or_v2i64:
188188
; CHECK: # BB#0:
189-
; CHECK-NEXT: orps {{.*}}(%rip), %xmm0
190-
; CHECK-NEXT: andps {{.*}}(%rip), %xmm0
189+
; CHECK-NEXT: movaps {{.*#+}} xmm0 = [8,8]
191190
; CHECK-NEXT: retq
192191
%1 = or <2 x i64> %a0, <i64 255, i64 255>
193192
%2 = and <2 x i64> %1, <i64 8, i64 8>
@@ -197,8 +196,7 @@ define <2 x i64> @and_or_v2i64(<2 x i64> %a0) {
197196
define <4 x i32> @and_or_v4i32(<4 x i32> %a0) {
198197
; CHECK-LABEL: and_or_v4i32:
199198
; CHECK: # BB#0:
200-
; CHECK-NEXT: orps {{.*}}(%rip), %xmm0
201-
; CHECK-NEXT: andps {{.*}}(%rip), %xmm0
199+
; CHECK-NEXT: movaps {{.*#+}} xmm0 = [3,3,3,3]
202200
; CHECK-NEXT: retq
203201
%1 = or <4 x i32> %a0, <i32 15, i32 15, i32 15, i32 15>
204202
%2 = and <4 x i32> %1, <i32 3, i32 3, i32 3, i32 3>

0 commit comments

Comments
 (0)