File: insertion-point.ll

package info (click to toggle)
llvm-toolchain-16 1%3A16.0.6-15~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,634,792 kB
  • sloc: cpp: 6,179,261; ansic: 1,216,205; asm: 741,319; python: 196,614; objc: 75,325; f90: 49,640; lisp: 32,396; pascal: 12,286; sh: 9,394; perl: 7,442; ml: 5,494; awk: 3,523; makefile: 2,723; javascript: 1,206; xml: 886; fortran: 581; cs: 573
file content (118 lines) | stat: -rw-r--r-- 5,084 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
; RUN: opt -mtriple=amdgcn-amd-amdhsa -passes=load-store-vectorizer -S -o - %s | FileCheck %s
; RUN: opt -mtriple=amdgcn-amd-amdhsa -aa-pipeline=basic-aa -passes='function(load-store-vectorizer)' -S -o - %s | FileCheck %s

target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5"

; Check position of the inserted vector load/store.  Vectorized loads should be
; inserted at the position of the first load in the chain, and stores should be
; inserted at the position of the last store.

; CHECK-LABEL: @insert_load_point(
; CHECK: %z = add i32 %x, 4
; CHECK: load <2 x float>
; CHECK: %w = add i32 %y, 9
; CHECK: %foo = add i32 %z, %w
define amdgpu_kernel void @insert_load_point(ptr addrspace(1) nocapture %a, ptr addrspace(1) nocapture %b, ptr addrspace(1) nocapture readonly %c, i64 %idx, i32 %x, i32 %y) #0 {
entry:
  %a.idx.x = getelementptr inbounds float, ptr addrspace(1) %a, i64 %idx
  %c.idx.x = getelementptr inbounds float, ptr addrspace(1) %c, i64 %idx
  %a.idx.x.1 = getelementptr inbounds float, ptr addrspace(1) %a.idx.x, i64 1
  %c.idx.x.1 = getelementptr inbounds float, ptr addrspace(1) %c.idx.x, i64 1

  %z = add i32 %x, 4
  %ld.c = load float, ptr addrspace(1) %c.idx.x, align 4
  %w = add i32 %y, 9
  %ld.c.idx.1 = load float, ptr addrspace(1) %c.idx.x.1, align 4
  %foo = add i32 %z, %w

  store float 0.0, ptr addrspace(1) %a.idx.x, align 4
  store float 0.0, ptr addrspace(1) %a.idx.x.1, align 4

  %add = fadd float %ld.c, %ld.c.idx.1
  store float %add, ptr addrspace(1) %b, align 4
  store i32 %foo, ptr addrspace(3) null, align 4
  ret void
}

; CHECK-LABEL: @insert_store_point(
; CHECK: %z = add i32 %x, 4
; CHECK: %w = add i32 %y, 9
; CHECK: store <2 x float>
; CHECK: %foo = add i32 %z, %w
define amdgpu_kernel void @insert_store_point(ptr addrspace(1) nocapture %a, ptr addrspace(1) nocapture %b, ptr addrspace(1) nocapture readonly %c, i64 %idx, i32 %x, i32 %y) #0 {
entry:
  %a.idx.x = getelementptr inbounds float, ptr addrspace(1) %a, i64 %idx
  %c.idx.x = getelementptr inbounds float, ptr addrspace(1) %c, i64 %idx
  %a.idx.x.1 = getelementptr inbounds float, ptr addrspace(1) %a.idx.x, i64 1
  %c.idx.x.1 = getelementptr inbounds float, ptr addrspace(1) %c.idx.x, i64 1

  %ld.c = load float, ptr addrspace(1) %c.idx.x, align 4
  %ld.c.idx.1 = load float, ptr addrspace(1) %c.idx.x.1, align 4

  %z = add i32 %x, 4
  store float 0.0, ptr addrspace(1) %a.idx.x, align 4
  %w = add i32 %y, 9
  store float 0.0, ptr addrspace(1) %a.idx.x.1, align 4
  %foo = add i32 %z, %w

  %add = fadd float %ld.c, %ld.c.idx.1
  store float %add, ptr addrspace(1) %b, align 4
  store i32 %foo, ptr addrspace(3) null, align 4
  ret void
}

; Here we have four stores, with an aliasing load before the last one.  We can
; vectorize the first three stores as <3 x float>, but this vectorized store must
; be inserted at the location of the third scalar store, not the fourth one.
;
; CHECK-LABEL: @insert_store_point_alias
; CHECK: store <3 x float>
; CHECK: load float, ptr addrspace(1) %a.idx.2
; CHECK: store float
; CHECK-SAME: %a.idx.3
define float @insert_store_point_alias(ptr addrspace(1) nocapture %a, i64 %idx) {
  %a.idx = getelementptr inbounds float, ptr addrspace(1) %a, i64 %idx
  %a.idx.1 = getelementptr inbounds float, ptr addrspace(1) %a.idx, i64 1
  %a.idx.2 = getelementptr inbounds float, ptr addrspace(1) %a.idx.1, i64 1
  %a.idx.3 = getelementptr inbounds float, ptr addrspace(1) %a.idx.2, i64 1

  store float 0.0, ptr addrspace(1) %a.idx, align 4
  store float 0.0, ptr addrspace(1) %a.idx.1, align 4
  store float 0.0, ptr addrspace(1) %a.idx.2, align 4
  %x = load float, ptr addrspace(1) %a.idx.2, align 4
  store float 0.0, ptr addrspace(1) %a.idx.3, align 4

  ret float %x
}

; Here we have four stores, with an aliasing load before the last one.  We
; could vectorize two of the stores before the load (although we currently
; don't), but the important thing is that we *don't* sink the store to
; a[idx + 1] below the load.
;
; CHECK-LABEL: @insert_store_point_alias_ooo
; CHECK: store float
; CHECK-SAME: %a.idx.3
; CHECK: store float
; CHECK-SAME: %a.idx.1
; CHECK: store float
; CHECK-SAME: %a.idx.2
; CHECK: load float, ptr addrspace(1) %a.idx.2
; CHECK: store float
; CHECK-SAME: %a.idx
define float @insert_store_point_alias_ooo(ptr addrspace(1) nocapture %a, i64 %idx) {
  %a.idx = getelementptr inbounds float, ptr addrspace(1) %a, i64 %idx
  %a.idx.1 = getelementptr inbounds float, ptr addrspace(1) %a.idx, i64 1
  %a.idx.2 = getelementptr inbounds float, ptr addrspace(1) %a.idx.1, i64 1
  %a.idx.3 = getelementptr inbounds float, ptr addrspace(1) %a.idx.2, i64 1

  store float 0.0, ptr addrspace(1) %a.idx.3, align 4
  store float 0.0, ptr addrspace(1) %a.idx.1, align 4
  store float 0.0, ptr addrspace(1) %a.idx.2, align 4
  %x = load float, ptr addrspace(1) %a.idx.2, align 4
  store float 0.0, ptr addrspace(1) %a.idx, align 4

  ret float %x
}

attributes #0 = { nounwind }