1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt -passes=mldst-motion -S < %s | FileCheck %s
3 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
5 ; Test to make sure that a function call that needs to be a barrier to sinking stores is indeed a barrier.
6 ; Stores sunks into the footer.
8 %struct.node = type { i32, ptr, ptr, ptr, i32, i32, i32, i32 }
10 declare i32 @foo(i32 %x)
12 define void @sink_store(ptr nocapture %r, i32 %index) {
13 ; CHECK-LABEL: define void @sink_store
14 ; CHECK-SAME: (ptr nocapture [[R:%.*]], i32 [[INDEX:%.*]]) {
16 ; CHECK-NEXT: [[NODE_0_IN16:%.*]] = getelementptr inbounds [[STRUCT_NODE:%.*]], ptr [[R]], i64 0, i32 2
17 ; CHECK-NEXT: [[NODE_017:%.*]] = load ptr, ptr [[NODE_0_IN16]], align 8
18 ; CHECK-NEXT: [[INDEX_ADDR:%.*]] = alloca i32, align 4
19 ; CHECK-NEXT: store i32 [[INDEX]], ptr [[INDEX_ADDR]], align 4
20 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[INDEX_ADDR]], align 4
21 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[TMP0]], 0
22 ; CHECK-NEXT: br i1 [[CMP]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
24 ; CHECK-NEXT: [[TMP1:%.*]] = load i32, ptr [[INDEX_ADDR]], align 4
25 ; CHECK-NEXT: [[P1:%.*]] = getelementptr inbounds [[STRUCT_NODE]], ptr [[NODE_017]], i32 0, i32 6
26 ; CHECK-NEXT: store i32 [[TMP1]], ptr [[P1]], align 4
27 ; CHECK-NEXT: br label [[IF_END:%.*]]
29 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr [[INDEX_ADDR]], align 4
30 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP2]], 1
31 ; CHECK-NEXT: [[P3:%.*]] = getelementptr inbounds [[STRUCT_NODE]], ptr [[NODE_017]], i32 0, i32 6
32 ; CHECK-NEXT: store i32 [[ADD]], ptr [[P3]], align 4
33 ; CHECK-NEXT: [[TMP3:%.*]] = call i32 @foo(i32 5)
34 ; CHECK-NEXT: br label [[IF_END]]
36 ; CHECK-NEXT: ret void
39 %node.0.in16 = getelementptr inbounds %struct.node, ptr %r, i64 0, i32 2
40 %node.017 = load ptr, ptr %node.0.in16, align 8
41 %index.addr = alloca i32, align 4
42 store i32 %index, ptr %index.addr, align 4
43 %0 = load i32, ptr %index.addr, align 4
44 %cmp = icmp slt i32 %0, 0
45 br i1 %cmp, label %if.then, label %if.else
47 if.then: ; preds = %entry
48 %1 = load i32, ptr %index.addr, align 4
49 %p1 = getelementptr inbounds %struct.node, ptr %node.017, i32 0, i32 6
50 store i32 %1, ptr %p1, align 4
53 if.else: ; preds = %entry
54 %2 = load i32, ptr %index.addr, align 4
55 %add = add nsw i32 %2, 1
56 %p3 = getelementptr inbounds %struct.node, ptr %node.017, i32 0, i32 6
57 store i32 %add, ptr %p3, align 4
58 call i32 @foo(i32 5) ;barrier
61 if.end: ; preds = %if.else, %if.then