[PATCH] D18000: [x86] fix cost model inaccuracy for vector memory ops

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 9 10:28:51 PST 2016


spatel created this revision.
spatel added reviewers: DavidKreitzer, RKSimon, zansari.
spatel added a subscriber: llvm-commits.
Herald added a subscriber: mcrosier.

The irony of this patch is that the one CPU that is affected is AMD Jaguar, and Jaguar has a completely double-pumped AVX implementation. But getting the cost model to reflect that is a much bigger problem. The small goal here is simply to improve on the lie that !AVX2 == SandyBridge.

http://reviews.llvm.org/D18000

Files:
  lib/Target/X86/X86TargetTransformInfo.cpp
  test/Transforms/LoopVectorize/X86/avx1.ll

Index: test/Transforms/LoopVectorize/X86/avx1.ll
===================================================================
--- test/Transforms/LoopVectorize/X86/avx1.ll
+++ test/Transforms/LoopVectorize/X86/avx1.ll
@@ -26,10 +26,10 @@
   ret i32 undef
 }
 
-;;; FIXME: If 32-byte accesses are fast, this should use a <4 x i64> load.
 
 ; CHECK-LABEL: @read_mod_i64(
-; CHECK: load <2 x i64>
+; SLOWMEM32: load <2 x i64>
+; FASTMEM32: load <4 x i64>
 ; CHECK: ret i32
 define i32 @read_mod_i64(i64* nocapture %a, i32 %n) nounwind uwtable ssp {
   %1 = icmp sgt i32 %n, 0
Index: lib/Target/X86/X86TargetTransformInfo.cpp
===================================================================
--- lib/Target/X86/X86TargetTransformInfo.cpp
+++ lib/Target/X86/X86TargetTransformInfo.cpp
@@ -983,10 +983,10 @@
   // Each load/store unit costs 1.
   int Cost = LT.first * 1;
 
-  // On Sandybridge 256bit load/stores are double pumped
-  // (but not on Haswell).
-  if (LT.second.getSizeInBits() > 128 && !ST->hasAVX2())
-    Cost*=2;
+  // This isn't exactly right. We're using slow unaligned 32-byte accesses as a
+  // proxy for a double-pumped AVX memory interface such as on Sandybridge.
+  if (LT.second.getStoreSize() == 32 && ST->isUnalignedMem32Slow())
+    Cost *= 2;
 
   return Cost;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18000.50157.patch
Type: text/x-patch
Size: 1283 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160309/c8088e19/attachment.bin>


More information about the llvm-commits mailing list