[PATCH] D26790: [X86] Add a hasOneUse check to selectScalarSSELoad to keep the same load from being folded multiple times
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 16 22:04:33 PST 2016
craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel, zvi, delena.
craig.topper added a subscriber: llvm-commits.
When selectScalarSSELoad is looking for a scalar_to_vector of a scalar load, it makes sure the load is only used by the scalar_to_vector. But it doesn't make sure the scalar_to_vector is only used once. This can cause the same load to be folded multiple times. This can be bad for performance.
https://reviews.llvm.org/D26790
Files:
lib/Target/X86/X86ISelDAGToDAG.cpp
test/CodeGen/X86/vec_ss_load_fold.ll
Index: test/CodeGen/X86/vec_ss_load_fold.ll
===================================================================
--- test/CodeGen/X86/vec_ss_load_fold.ll
+++ test/CodeGen/X86/vec_ss_load_fold.ll
@@ -381,33 +381,37 @@
; X32-LABEL: double_fold:
; X32: ## BB#0: ## %entry
; X32-NEXT: movl {{[0-9]+}}(%esp), %eax
-; X32-NEXT: movaps %xmm0, %xmm1
-; X32-NEXT: minss (%eax), %xmm1
-; X32-NEXT: maxss (%eax), %xmm0
-; X32-NEXT: addps %xmm1, %xmm0
+; X32-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
+; X32-NEXT: movaps %xmm0, %xmm2
+; X32-NEXT: minss %xmm1, %xmm2
+; X32-NEXT: maxss %xmm1, %xmm0
+; X32-NEXT: addps %xmm2, %xmm0
; X32-NEXT: retl
;
; X64-LABEL: double_fold:
; X64: ## BB#0: ## %entry
-; X64-NEXT: movaps %xmm0, %xmm1
-; X64-NEXT: minss (%rdi), %xmm1
-; X64-NEXT: maxss (%rdi), %xmm0
-; X64-NEXT: addps %xmm1, %xmm0
+; X64-NEXT: movss {{.*#+}} xmm1 = mem[0],zero,zero,zero
+; X64-NEXT: movaps %xmm0, %xmm2
+; X64-NEXT: minss %xmm1, %xmm2
+; X64-NEXT: maxss %xmm1, %xmm0
+; X64-NEXT: addps %xmm2, %xmm0
; X64-NEXT: retq
;
; X32_AVX-LABEL: double_fold:
; X32_AVX: ## BB#0: ## %entry
; X32_AVX-NEXT: movl {{[0-9]+}}(%esp), %eax
-; X32_AVX-NEXT: vminss (%eax), %xmm0, %xmm1
-; X32_AVX-NEXT: vmaxss (%eax), %xmm0, %xmm0
-; X32_AVX-NEXT: vaddps %xmm0, %xmm1, %xmm0
+; X32_AVX-NEXT: vmovss {{.*#+}} xmm1 = mem[0],zero,zero,zero
+; X32_AVX-NEXT: vminss %xmm1, %xmm0, %xmm2
+; X32_AVX-NEXT: vmaxss %xmm1, %xmm0, %xmm0
+; X32_AVX-NEXT: vaddps %xmm0, %xmm2, %xmm0
; X32_AVX-NEXT: retl
;
; X64_AVX-LABEL: double_fold:
; X64_AVX: ## BB#0: ## %entry
-; X64_AVX-NEXT: vminss (%rdi), %xmm0, %xmm1
-; X64_AVX-NEXT: vmaxss (%rdi), %xmm0, %xmm0
-; X64_AVX-NEXT: vaddps %xmm0, %xmm1, %xmm0
+; X64_AVX-NEXT: vmovss {{.*#+}} xmm1 = mem[0],zero,zero,zero
+; X64_AVX-NEXT: vminss %xmm1, %xmm0, %xmm2
+; X64_AVX-NEXT: vmaxss %xmm1, %xmm0, %xmm0
+; X64_AVX-NEXT: vaddps %xmm0, %xmm2, %xmm0
; X64_AVX-NEXT: retq
entry:
%0 = load float, float* %x, align 1
Index: lib/Target/X86/X86ISelDAGToDAG.cpp
===================================================================
--- lib/Target/X86/X86ISelDAGToDAG.cpp
+++ lib/Target/X86/X86ISelDAGToDAG.cpp
@@ -1513,7 +1513,7 @@
SDValue &Scale, SDValue &Index,
SDValue &Disp, SDValue &Segment,
SDValue &PatternNodeWithChain) {
- if (N.getOpcode() == ISD::SCALAR_TO_VECTOR) {
+ if (N.getOpcode() == ISD::SCALAR_TO_VECTOR && N.getNode()->hasOneUse()) {
PatternNodeWithChain = N.getOperand(0);
if (ISD::isNON_EXTLoad(PatternNodeWithChain.getNode()) &&
PatternNodeWithChain.hasOneUse() &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26790.78321.patch
Type: text/x-patch
Size: 2814 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161117/c8ebe51f/attachment-0001.bin>
More information about the llvm-commits
mailing list