xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/branch-target-layout.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -O3 -emit-llvm -o - | FileCheck %s
2*f4a2713aSLionel Sambuc //
3*f4a2713aSLionel Sambuc // PR13214
4*f4a2713aSLionel Sambuc // No assumption may be made about the order that a frontend emits branch
5*f4a2713aSLionel Sambuc // targets (basic blocks). However, the backend's basic block layout makes an
6*f4a2713aSLionel Sambuc // attempt to preserve source order of control flow, and any bias toward source
7*f4a2713aSLionel Sambuc // order must start with the frontend.
8*f4a2713aSLionel Sambuc //
9*f4a2713aSLionel Sambuc // Note that the frontend inverts branches to simplify the condition, so the
10*f4a2713aSLionel Sambuc // order of a branch instruction's labels cannot be used as a source order bias.
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc void calla();
13*f4a2713aSLionel Sambuc void callb();
14*f4a2713aSLionel Sambuc void callc();
15*f4a2713aSLionel Sambuc 
16*f4a2713aSLionel Sambuc // CHECK: @test1
17*f4a2713aSLionel Sambuc // CHECK: @calla
18*f4a2713aSLionel Sambuc // CHECK: @callb
19*f4a2713aSLionel Sambuc // CHECK: @callc
20*f4a2713aSLionel Sambuc // CHECK: ret void
test1(int a)21*f4a2713aSLionel Sambuc void test1(int a) {
22*f4a2713aSLionel Sambuc   if (a)
23*f4a2713aSLionel Sambuc     calla();
24*f4a2713aSLionel Sambuc   else
25*f4a2713aSLionel Sambuc     callb();
26*f4a2713aSLionel Sambuc   callc();
27*f4a2713aSLionel Sambuc }
28*f4a2713aSLionel Sambuc 
29*f4a2713aSLionel Sambuc // CHECK: @test2
30*f4a2713aSLionel Sambuc // CHECK: @callb
31*f4a2713aSLionel Sambuc // CHECK: @calla
32*f4a2713aSLionel Sambuc // CHECK: @callc
33*f4a2713aSLionel Sambuc // CHECK: ret void
test2(int a)34*f4a2713aSLionel Sambuc void test2(int a) {
35*f4a2713aSLionel Sambuc   if (!a)
36*f4a2713aSLionel Sambuc     callb();
37*f4a2713aSLionel Sambuc   else
38*f4a2713aSLionel Sambuc     calla();
39*f4a2713aSLionel Sambuc   callc();
40*f4a2713aSLionel Sambuc }
41