File: const_cond.d

package info (click to toggle)
ldc 1%3A1.24.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 53,728 kB
  • sloc: cpp: 55,939; ansic: 10,599; sh: 958; makefile: 801; asm: 507; objc: 122; exp: 30; python: 12
file content (78 lines) | stat: -rw-r--r-- 1,417 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Make sure that the dead code of an `if` (and `else if`) is elminated when the condition is constant.
// If the condition value is constant, there are two cases:
// 1) It is 0 (false)    -> Generate the else block (if it exists) with no branching.
// 2) It is non-0 (true) -> Generate the if block with no branching.
// Also, verify it _does_ generate correct code when it is not constant.

// RUN: %ldc -O0 -output-ll -of=%t.ll %s && FileCheck %s < %t.ll

extern(C):  //to avoid name mangling.

// CHECK-LABEL: @foo
void foo()
{
    // CHECK-NOT: %a = alloca
    // CHECK: %b = alloca
    // CHECK-NOT: br
    // CHECK-NOT: store i32 1, i32* %a
    // CHECK: store i32 2, i32* %b
    if (0)
    {
        int a = 1;
    }
    else
    {
        int b = 2;
    }
}

// CHECK-LABEL: @bar
void bar()
{
    // CHECK-NOT: %a = alloca
    // CHECK: store i32 2, i32* %b
    if (0)
    {
        int a = 1;
    }
    else if(1)
    {
        int b = 2;
    }
}

// CHECK-LABEL: @only_ret
void only_ret()
{
    // CHECK-NEXT: ret void
    // CHECK-NEXT: }
    if (1 && (2 - 2))
    {
        int a = 1;
    }
}

// CHECK-LABEL: @only_ret2
void only_ret2()
{
    // CHECK-NEXT: ret void
    // CHECK-NEXT: }
    if (0)
    {
        int a = 1;
    }
    else if(0)
    {
        int b = 2;
    }
}

// CHECK-LABEL: @gen_br
void gen_br(immutable int a)
{
    // CHECK-COUNT-1: br
    if (a)
    {
        int b = 1;
    }
}