Skip to content

Commit 457ddd3

Browse files
author
Sean Fertile
committed
[PowerPC] Correctly specify the cache line size for Power 7, 8 and 9.
Fixes PPCTTIImpl::getCacheLineSize() returning the wrong cache line size for newer ppc processors. Commiting on behalf of Stefan Pintilie. Differential Revision: https://reviews.llvm.org/D33656 llvm-svn: 304317
1 parent ca77dd5 commit 457ddd3

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

llvm/lib/Target/PowerPC/PPCTargetTransformInfo.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,18 @@ unsigned PPCTTIImpl::getRegisterBitWidth(bool Vector) {
244244
}
245245

246246
unsigned PPCTTIImpl::getCacheLineSize() {
247-
// This is currently only used for the data prefetch pass which is only
248-
// enabled for BG/Q by default.
249-
return CacheLineSize;
247+
// Check first if the user specified a custom line size.
248+
if (CacheLineSize.getNumOccurrences() > 0)
249+
return CacheLineSize;
250+
251+
// On P7, P8 or P9 we have a cache line size of 128.
252+
unsigned Directive = ST->getDarwinDirective();
253+
if (Directive == PPC::DIR_PWR7 || Directive == PPC::DIR_PWR8 ||
254+
Directive == PPC::DIR_PWR9)
255+
return 128;
256+
257+
// On other processors return a default of 64 bytes.
258+
return 64;
250259
}
251260

252261
unsigned PPCTTIImpl::getPrefetchDistance() {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; RUN: llc < %s -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 -enable-ppc-prefetching=true | FileCheck %s
2+
; RUN: llc < %s -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 -enable-ppc-prefetching=true -ppc-loop-prefetch-cache-line=64 | FileCheck %s -check-prefix=CHECK-DCBT
3+
; RUN: llc < %s -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 -enable-ppc-prefetching=true | FileCheck %s
4+
; RUN: llc < %s -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr8 -enable-ppc-prefetching=true -ppc-loop-prefetch-cache-line=64 | FileCheck %s -check-prefix=CHECK-DCBT
5+
; RUN: llc < %s -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr9 -enable-ppc-prefetching=true | FileCheck %s
6+
; RUN: llc < %s -mtriple=powerpc64le-unknown-linux-gnu -mcpu=pwr9 -enable-ppc-prefetching=true -ppc-loop-prefetch-cache-line=64 | FileCheck %s -check-prefix=CHECK-DCBT
7+
; RUN: llc < %s -march=ppc64 -mcpu=a2 -enable-ppc-prefetching=true | FileCheck %s -check-prefix=CHECK-DCBT
8+
9+
; Function Attrs: nounwind
10+
define signext i32 @check_cache_line() local_unnamed_addr {
11+
entry:
12+
%call = tail call i32* bitcast (i32* (...)* @magici to i32* ()*)()
13+
%call115 = tail call signext i32 bitcast (i32 (...)* @iter to i32 ()*)()
14+
%cmp16 = icmp sgt i32 %call115, 0
15+
br i1 %cmp16, label %for.body, label %for.cond.cleanup
16+
17+
for.cond.cleanup: ; preds = %for.body, %entry
18+
%res.0.lcssa = phi i32 [ 0, %entry ], [ %add5, %for.body ]
19+
ret i32 %res.0.lcssa
20+
21+
for.body: ; preds = %entry, %for.body
22+
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
23+
%res.017 = phi i32 [ %add5, %for.body ], [ 0, %entry ]
24+
%arrayidx = getelementptr inbounds i32, i32* %call, i64 %indvars.iv
25+
%0 = load i32, i32* %arrayidx, align 4
26+
%add = add nsw i32 %0, %res.017
27+
%1 = add nuw nsw i64 %indvars.iv, 16
28+
%arrayidx4 = getelementptr inbounds i32, i32* %call, i64 %1
29+
%2 = load i32, i32* %arrayidx4, align 4
30+
%add5 = add nsw i32 %add, %2
31+
%indvars.iv.next = add nuw i64 %indvars.iv, 1
32+
%call1 = tail call signext i32 bitcast (i32 (...)* @iter to i32 ()*)()
33+
%3 = sext i32 %call1 to i64
34+
%cmp = icmp slt i64 %indvars.iv.next, %3
35+
br i1 %cmp, label %for.body, label %for.cond.cleanup
36+
; CHECK-LABEL: check_cache_line
37+
; CHECK: dcbt
38+
; CHECK-NOT: dcbt
39+
; CHECK: blr
40+
; CHECK-DCBT-LABEL: check_cache_line
41+
; CHECK-DCBT: dcbt
42+
; CHECK-DCBT: dcbt
43+
; CHECK-DCBT: blr
44+
}
45+
46+
declare i32* @magici(...) local_unnamed_addr
47+
48+
declare signext i32 @iter(...) local_unnamed_addr
49+

0 commit comments

Comments
 (0)