Skip to content

Commit c1570e9

Browse files
committed
[DAGCombiner][X86][WIP] Combine (build_vector (load X))->(vecty (load X))
This is an alternative to llvm#88261. This gets the mmx cases from that patch without affecting RISC-V. The code here is largely lifted from the (bitcast (load))->(load) code.
1 parent a06073f commit c1570e9

File tree

4 files changed

+251
-834
lines changed

4 files changed

+251
-834
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23501,6 +23501,32 @@ SDValue DAGCombiner::visitBUILD_VECTOR(SDNode *N) {
2350123501
return DAG.getNode(ISD::SPLAT_VECTOR, SDLoc(N), VT, V);
2350223502
}
2350323503

23504+
if (N->getNumOperands() == 1) {
23505+
SDValue N0 = N->getOperand(0);
23506+
if (ISD::isNormalLoad(N0.getNode()) && N0.hasOneUse() &&
23507+
// Do not remove the cast if the types differ in endian layout.
23508+
TLI.hasBigEndianPartOrdering(N0.getValueType(), DAG.getDataLayout()) ==
23509+
TLI.hasBigEndianPartOrdering(VT, DAG.getDataLayout()) &&
23510+
// If the load is volatile, we only want to change the load type if the
23511+
// resulting load is legal. Otherwise we might increase the number of
23512+
// memory accesses. We don't care if the original type was legal or not
23513+
// as we assume software couldn't rely on the number of accesses of an
23514+
// illegal type.
23515+
((!LegalOperations && cast<LoadSDNode>(N0)->isSimple()) ||
23516+
TLI.isOperationLegal(ISD::LOAD, VT))) {
23517+
LoadSDNode *LN0 = cast<LoadSDNode>(N0);
23518+
23519+
if (TLI.isLoadBitCastBeneficial(N0.getValueType(), VT, DAG,
23520+
*LN0->getMemOperand())) {
23521+
SDValue Load =
23522+
DAG.getLoad(VT, SDLoc(N), LN0->getChain(), LN0->getBasePtr(),
23523+
LN0->getMemOperand());
23524+
DAG.ReplaceAllUsesOfValueWith(N0.getValue(1), Load.getValue(1));
23525+
return Load;
23526+
}
23527+
}
23528+
}
23529+
2350423530
return SDValue();
2350523531
}
2350623532

llvm/test/CodeGen/X86/2007-05-15-maskmovq.ll

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,11 @@ define void @test(<1 x i64> %c64, <1 x i64> %mask1, ptr %P) {
66
; CHECK: ## %bb.0: ## %entry
77
; CHECK-NEXT: pushl %edi
88
; CHECK-NEXT: .cfi_def_cfa_offset 8
9-
; CHECK-NEXT: subl $16, %esp
10-
; CHECK-NEXT: .cfi_def_cfa_offset 24
119
; CHECK-NEXT: .cfi_offset %edi, -8
12-
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
13-
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
14-
; CHECK-NEXT: movl %ecx, {{[0-9]+}}(%esp)
15-
; CHECK-NEXT: movl %eax, (%esp)
16-
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %eax
17-
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %ecx
18-
; CHECK-NEXT: movl %ecx, {{[0-9]+}}(%esp)
19-
; CHECK-NEXT: movl %eax, {{[0-9]+}}(%esp)
2010
; CHECK-NEXT: movl {{[0-9]+}}(%esp), %edi
21-
; CHECK-NEXT: movq (%esp), %mm0
11+
; CHECK-NEXT: movq {{[0-9]+}}(%esp), %mm0
2212
; CHECK-NEXT: movq {{[0-9]+}}(%esp), %mm1
23-
; CHECK-NEXT: maskmovq %mm0, %mm1
24-
; CHECK-NEXT: addl $16, %esp
13+
; CHECK-NEXT: maskmovq %mm1, %mm0
2514
; CHECK-NEXT: popl %edi
2615
; CHECK-NEXT: retl
2716
entry:

0 commit comments

Comments
 (0)