blob: 497e024e2489c6dde54092bc96d0c097199e092a [file] [log] [blame]
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +00001; RUN: opt -simplifycfg -S < %s | FileCheck %s
2
Sanjay Patel342f7c72016-03-26 23:09:25 +00003define void @ifconvertstore(i32* %A, i32 %B, i32 %C, i32 %D) {
4; CHECK-LABEL: @ifconvertstore(
5; CHECK: store i32 %B, i32* %A
6; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 %D, 42
Sanjay Patel796db352016-03-26 23:30:50 +00007; CHECK-NEXT: [[C_B:%.*]] = select i1 [[CMP]], i32 %C, i32 %B, !prof !0
Sanjay Patel342f7c72016-03-26 23:09:25 +00008; CHECK-NEXT: store i32 [[C_B]], i32* %A
9; CHECK-NEXT: ret void
10;
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000011entry:
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000012; First store to the location.
Sanjay Patel342f7c72016-03-26 23:09:25 +000013 store i32 %B, i32* %A
14 %cmp = icmp sgt i32 %D, 42
Sanjay Patel796db352016-03-26 23:30:50 +000015 br i1 %cmp, label %if.then, label %ret.end, !prof !0
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000016
17; Make sure we speculate stores like the following one. It is cheap compared to
18; a mispredicated branch.
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000019if.then:
Sanjay Patel342f7c72016-03-26 23:09:25 +000020 store i32 %C, i32* %A
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000021 br label %ret.end
22
23ret.end:
24 ret void
25}
26
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000027; Store to a different location.
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000028
Sanjay Patel342f7c72016-03-26 23:09:25 +000029define void @noifconvertstore1(i32* %A1, i32* %A2, i32 %B, i32 %C, i32 %D) {
Stephen Linc1c7a132013-07-14 01:42:54 +000030; CHECK-LABEL: @noifconvertstore1(
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000031; CHECK-NOT: select
Sanjay Patel342f7c72016-03-26 23:09:25 +000032;
33entry:
34 store i32 %B, i32* %A1
35 %cmp = icmp sgt i32 %D, 42
36 br i1 %cmp, label %if.then, label %ret.end
37
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000038if.then:
Sanjay Patel342f7c72016-03-26 23:09:25 +000039 store i32 %C, i32* %A2
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000040 br label %ret.end
41
42ret.end:
43 ret void
44}
45
Sanjay Patel342f7c72016-03-26 23:09:25 +000046; This function could store to our address, so we can't repeat the first store a second time.
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000047declare void @unknown_fun()
48
Sanjay Patel342f7c72016-03-26 23:09:25 +000049define void @noifconvertstore2(i32* %A, i32 %B, i32 %C, i32 %D) {
Stephen Linc1c7a132013-07-14 01:42:54 +000050; CHECK-LABEL: @noifconvertstore2(
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000051; CHECK-NOT: select
Sanjay Patel342f7c72016-03-26 23:09:25 +000052;
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000053entry:
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000054; First store to the location.
Sanjay Patel342f7c72016-03-26 23:09:25 +000055 store i32 %B, i32* %A
56 call void @unknown_fun()
57 %cmp6 = icmp sgt i32 %D, 42
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000058 br i1 %cmp6, label %if.then, label %ret.end
59
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000060if.then:
Sanjay Patel342f7c72016-03-26 23:09:25 +000061 store i32 %C, i32* %A
Arnold Schwaighofer474df6d2013-04-29 21:28:24 +000062 br label %ret.end
63
64ret.end:
65 ret void
66}
Sanjay Patel342f7c72016-03-26 23:09:25 +000067
68; Make sure we don't speculate volatile stores.
69
70define void @noifconvertstore_volatile(i32* %A, i32 %B, i32 %C, i32 %D) {
71; CHECK-LABEL: @noifconvertstore_volatile(
72; CHECK-NOT: select
73;
74entry:
75; First store to the location.
76 store i32 %B, i32* %A
77 %cmp6 = icmp sgt i32 %D, 42
78 br i1 %cmp6, label %if.then, label %ret.end
79
80if.then:
81 store volatile i32 %C, i32* %A
82 br label %ret.end
83
84ret.end:
85 ret void
86}
87
Sanjay Patel796db352016-03-26 23:30:50 +000088; CHECK: !0 = !{!"branch_weights", i32 3, i32 5}
89!0 = !{!"branch_weights", i32 3, i32 5}
90