1 ; RUN: opt -simplifycfg -S < %s | FileCheck %s
3 define void @ifconvertstore(i32 %m, i32* %A, i32* %B, i32 %C, i32 %D) {
5 %arrayidx = getelementptr inbounds i32, i32* %B, i64 0
6 %0 = load i32, i32* %arrayidx, align 4
7 %add = add nsw i32 %0, %C
8 %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 0
10 ; First store to the location.
11 store i32 %add, i32* %arrayidx2, align 4
12 %arrayidx4 = getelementptr inbounds i32, i32* %B, i64 1
13 %1 = load i32, i32* %arrayidx4, align 4
14 %add5 = add nsw i32 %1, %D
15 %cmp6 = icmp sgt i32 %add5, %C
16 br i1 %cmp6, label %if.then, label %ret.end
18 ; Make sure we speculate stores like the following one. It is cheap compared to
19 ; a mispredicated branch.
20 ; CHECK-LABEL: @ifconvertstore(
21 ; CHECK: %add5.add = select i1 %cmp6, i32 %add5, i32 %add
22 ; CHECK: store i32 %add5.add, i32* %arrayidx2, align 4
24 store i32 %add5, i32* %arrayidx2, align 4
31 define void @noifconvertstore1(i32 %m, i32* %A, i32* %B, i32 %C, i32 %D) {
33 %arrayidx = getelementptr inbounds i32, i32* %B, i64 0
34 %0 = load i32, i32* %arrayidx, align 4
35 %add = add nsw i32 %0, %C
36 %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 0
38 ; Store to a different location.
39 store i32 %add, i32* %arrayidx, align 4
40 %arrayidx4 = getelementptr inbounds i32, i32* %B, i64 1
41 %1 = load i32, i32* %arrayidx4, align 4
42 %add5 = add nsw i32 %1, %D
43 %cmp6 = icmp sgt i32 %add5, %C
44 br i1 %cmp6, label %if.then, label %ret.end
46 ; CHECK-LABEL: @noifconvertstore1(
49 store i32 %add5, i32* %arrayidx2, align 4
56 declare void @unknown_fun()
58 define void @noifconvertstore2(i32 %m, i32* %A, i32* %B, i32 %C, i32 %D) {
60 %arrayidx = getelementptr inbounds i32, i32* %B, i64 0
61 %0 = load i32, i32* %arrayidx, align 4
62 %add = add nsw i32 %0, %C
63 %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 0
65 ; First store to the location.
66 store i32 %add, i32* %arrayidx2, align 4
67 call void @unknown_fun()
68 %arrayidx4 = getelementptr inbounds i32, i32* %B, i64 1
69 %1 = load i32, i32* %arrayidx4, align 4
70 %add5 = add nsw i32 %1, %D
71 %cmp6 = icmp sgt i32 %add5, %C
72 br i1 %cmp6, label %if.then, label %ret.end
74 ; CHECK-LABEL: @noifconvertstore2(
77 store i32 %add5, i32* %arrayidx2, align 4
84 define void @noifconvertstore_volatile(i32 %m, i32* %A, i32* %B, i32 %C, i32 %D) {
86 %arrayidx = getelementptr inbounds i32, i32* %B, i64 0
87 %0 = load i32, i32* %arrayidx, align 4
88 %add = add nsw i32 %0, %C
89 %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 0
91 ; First store to the location.
92 store i32 %add, i32* %arrayidx2, align 4
93 %arrayidx4 = getelementptr inbounds i32, i32* %B, i64 1
94 %1 = load i32, i32* %arrayidx4, align 4
95 %add5 = add nsw i32 %1, %D
96 %cmp6 = icmp sgt i32 %add5, %C
97 br i1 %cmp6, label %if.then, label %ret.end
99 ; Make sure we don't speculate volatile stores.
100 ; CHECK-LABEL: @noifconvertstore_volatile(
103 store volatile i32 %add5, i32* %arrayidx2, align 4