File: scalarize-store-with-predication.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 1,998,492 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (54 lines) | stat: -rw-r--r-- 2,052 bytes parent folder | download | duplicates (12)
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
; RUN: opt -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 \
; RUN:   -prefer-predicate-over-epilogue=scalar-epilogue -S -o - < %s | FileCheck %s
; RUN: opt -mattr=+sve -passes=loop-vectorize -force-vector-width=1 -force-vector-interleave=2 \
; RUN:   -prefer-predicate-over-epilogue=scalar-epilogue -S -o - < %s | FileCheck %s

target triple = "aarch64-unknown-linux-gnu"

; This test is defending against a bug that appeared when we have a target
; configuration where masked loads/stores are legal -- e.g. AArch64 with SVE.
; Predication would not be applied during interleaving, enabling the
; possibility of superfluous loads/stores which could result in miscompiles.
; This test checks that, when we disable vectorisation and force interleaving,
; stores are predicated properly.
;
; This is _not_ an SVE-specific test. The same bug could manifest on any
; architecture with masked loads/stores, but we use SVE for testing purposes
; here.

define void @foo(ptr %data1, ptr %data2) {
; CHECK-LABEL: @foo(
; CHECK:       vector.body:
; CHECK:         br i1 {{%.*}}, label %pred.store.if, label %pred.store.continue
; CHECK:       pred.store.if:
; CHECK-NEXT:    store i32 {{%.*}}, ptr {{%.*}}
; CHECK-NEXT:    br label %pred.store.continue
; CHECK:       pred.store.continue:
; CHECK-NEXT:    br i1 {{%.*}}, label %pred.store.if1, label %pred.store.continue2
; CHECK:       pred.store.if1:
; CHECK-NEXT:    store i32 {{%.*}}, ptr {{%.*}}
; CHECK-NEXT:    br label %pred.store.continue2
; CHECK:       pred.store.continue2:

entry:
  br label %while.body

while.body:
  %i = phi i64 [ 1023, %entry ], [ %i.next, %if.end ]
  %arrayidx = getelementptr inbounds i32, ptr %data1, i64 %i
  %ld = load i32, ptr %arrayidx, align 4
  %cmp = icmp sgt i32 %ld, %ld
  br i1 %cmp, label %if.then, label %if.end

if.then:
  store i32 %ld, ptr %arrayidx, align 4
  br label %if.end

if.end:
  %i.next = add nsw i64 %i, -1
  %tobool.not = icmp eq i64 %i, 0
  br i1 %tobool.not, label %while.end, label %while.body

while.end:
  ret void
}