1 ; RUN: opt < %s -S -early-cse | FileCheck %s
5 define void @test1(i8 %V, i32 *%P) {
6 %A = bitcast i64 42 to double ;; dead
7 %B = add i32 4, 19 ;; constant folds
9 ; CHECK-NEXT: store i32 23, i32* %P
11 %C = zext i8 %V to i32
12 %D = zext i8 %V to i32 ;; CSE
13 volatile store i32 %C, i32* %P
14 volatile store i32 %D, i32* %P
15 ; CHECK-NEXT: %C = zext i8 %V to i32
16 ; CHECK-NEXT: volatile store i32 %C
17 ; CHECK-NEXT: volatile store i32 %C
21 volatile store i32 %E, i32* %P
22 volatile store i32 %F, i32* %P
23 ; CHECK-NEXT: %E = add i32 %C, %C
24 ; CHECK-NEXT: volatile store i32 %E
25 ; CHECK-NEXT: volatile store i32 %E
27 %G = add nuw i32 %C, %C ;; not a CSE with E
28 volatile store i32 %G, i32* %P
29 ; CHECK-NEXT: %G = add nuw i32 %C, %C
30 ; CHECK-NEXT: volatile store i32 %G
35 ;; Simple load value numbering.
37 define i32 @test2(i32 *%P) {
40 %Diff = sub i32 %V1, %V2
45 ;; Cross block load value numbering.
47 define i32 @test3(i32 *%P, i1 %Cond) {
49 br i1 %Cond, label %T, label %F
55 %Diff = sub i32 %V1, %V2
61 ;; Cross block load value numbering stops when stores happen.
63 define i32 @test4(i32 *%P, i1 %Cond) {
65 br i1 %Cond, label %T, label %F
73 %Diff = sub i32 %V1, %V2
76 ; CHECK: ret i32 %Diff
79 declare i32 @func(i32 *%P) readonly
81 ;; Simple call CSE'ing.
83 define i32 @test5(i32 *%P) {
84 %V1 = call i32 @func(i32* %P)
85 %V2 = call i32 @func(i32* %P)
86 %Diff = sub i32 %V1, %V2
91 ;; Trivial Store->load forwarding
93 define i32 @test6(i32 *%P) {
100 ;; Trivial dead store elimination.
102 define void @test7(i32 *%P) {
103 store i32 42, i32* %P
104 store i32 45, i32* %P
106 ; CHECK-NEXT: store i32 45
107 ; CHECK-NEXT: ret void
110 ;; Readnone functions aren't invalidated by stores.
112 define i32 @test8(i32 *%P) {
113 %V1 = call i32 @func(i32* %P) readnone
115 %V2 = call i32 @func(i32* %P) readnone
116 %Diff = sub i32 %V1, %V2