[InstCombine] add tests to show missing trunc optimizations
[oota-llvm.git] / test / Transforms / Mem2Reg / pr24179.ll
1 ; RUN: opt -mem2reg < %s -S | FileCheck %s
2
3 declare i32 @def(i32)
4 declare i1 @use(i32)
5
6 ; Special case of a single-BB alloca does not apply here since the load
7 ; is affected by the following store. Expect this case to be identified
8 ; and a PHI node to be created.
9 define void @test1() {
10 ; CHECK-LABEL: @test1(
11  entry:
12   %t = alloca i32
13   br label %loop
14
15  loop:
16   %v = load i32, i32* %t
17   %c = call i1 @use(i32 %v)
18 ; CHECK: [[PHI:%.*]] = phi i32 [ undef, %entry ], [ %n, %loop ]
19 ; CHECK: call i1 @use(i32 [[PHI]])
20   %n = call i32 @def(i32 7)
21   store i32 %n, i32* %t
22   br i1 %c, label %loop, label %exit
23
24  exit:
25   ret void
26 }
27
28 ; Same as above, except there is no following store. The alloca should just be
29 ; replaced with an undef
30 define void @test2() {
31 ; CHECK-LABEL: @test2(
32  entry:
33   %t = alloca i32
34   br label %loop
35
36  loop:
37   %v = load i32, i32* %t
38   %c = call i1 @use(i32 %v)
39 ; CHECK: %c = call i1 @use(i32 undef)
40   br i1 %c, label %loop, label %exit
41
42  exit:
43   ret void
44 }