• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -instcombine -S | FileCheck %s
2
3define void @test1(i32* %P) {
4        store i32 undef, i32* %P
5        store i32 123, i32* undef
6        store i32 124, i32* null
7        ret void
8; CHECK: @test1(
9; CHECK-NEXT: store i32 123, i32* undef
10; CHECK-NEXT: store i32 undef, i32* null
11; CHECK-NEXT: ret void
12}
13
14define void @test2(i32* %P) {
15        %X = load i32* %P               ; <i32> [#uses=1]
16        %Y = add i32 %X, 0              ; <i32> [#uses=1]
17        store i32 %Y, i32* %P
18        ret void
19; CHECK: @test2
20; CHECK-NEXT: ret void
21}
22
23;; Simple sinking tests
24
25; "if then else"
26define i32 @test3(i1 %C) {
27	%A = alloca i32
28        br i1 %C, label %Cond, label %Cond2
29
30Cond:
31        store i32 -987654321, i32* %A
32        br label %Cont
33
34Cond2:
35	store i32 47, i32* %A
36	br label %Cont
37
38Cont:
39	%V = load i32* %A
40	ret i32 %V
41; CHECK: @test3
42; CHECK-NOT: alloca
43; CHECK: Cont:
44; CHECK-NEXT:  %storemerge = phi i32 [ 47, %Cond2 ], [ -987654321, %Cond ]
45; CHECK-NEXT:  ret i32 %storemerge
46}
47
48; "if then"
49define i32 @test4(i1 %C) {
50	%A = alloca i32
51	store i32 47, i32* %A
52        br i1 %C, label %Cond, label %Cont
53
54Cond:
55        store i32 -987654321, i32* %A
56        br label %Cont
57
58Cont:
59	%V = load i32* %A
60	ret i32 %V
61; CHECK: @test4
62; CHECK-NOT: alloca
63; CHECK: Cont:
64; CHECK-NEXT:  %storemerge = phi i32 [ -987654321, %Cond ], [ 47, %0 ]
65; CHECK-NEXT:  ret i32 %storemerge
66}
67
68; "if then"
69define void @test5(i1 %C, i32* %P) {
70	store i32 47, i32* %P, align 1
71        br i1 %C, label %Cond, label %Cont
72
73Cond:
74        store i32 -987654321, i32* %P, align 1
75        br label %Cont
76
77Cont:
78	ret void
79; CHECK: @test5
80; CHECK: Cont:
81; CHECK-NEXT:  %storemerge = phi i32
82; CHECK-NEXT:  store i32 %storemerge, i32* %P, align 1
83; CHECK-NEXT:  ret void
84}
85
86