File: cond_br.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (55 lines) | stat: -rw-r--r-- 1,586 bytes parent folder | download | duplicates (9)
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
; RUN: opt -basic-aa -gvn -S < %s | FileCheck %s
@y = external global i32
@z = external global i32

; Function Attrs: nounwind ssp uwtable
define void @foo(i32 %x) {
; CHECK: @foo(i32 %x)
; CHECK: %.pre = load i32, i32* @y
; CHECK: call void @bar(i32 %.pre)

  %t = sub i32 %x, %x
  %.pre = load i32, i32* @y, align 4
  %cmp = icmp sgt i32 %t, 2
  br i1 %cmp, label %if.then, label %entry.if.end_crit_edge

entry.if.end_crit_edge:                           ; preds = %entry
  br label %if.end

if.then:                                          ; preds = %entry
  %add = add nsw i32 %x, 3
  store i32 %add, i32* @y, align 4
  br label %if.end

if.end:                                           ; preds = %entry.if.end_crit_edge, %if.then
  %1 = phi i32 [ %.pre, %entry.if.end_crit_edge ], [ %add, %if.then ]
  tail call void @bar(i32 %1)
  ret void
}

define void @foo2(i32 %x) {
; CHECK: @foo2(i32 %x)
; CHECK: %.pre = load i32, i32* @y
; CHECK: tail call void @bar(i32 %.pre)
entry:
  %t = sub i32 %x, %x
  %.pre = load i32, i32* @y, align 4
  %cmp = icmp sgt i32 %t, 2
  br i1 %cmp, label %if.then, label %if.else

if.then:                                          ; preds = %entry
  %add = add nsw i32 %x, 3
  store i32 %add, i32* @y, align 4
  br label %if.end

if.else:                                          ; preds = %entry
  store i32 1, i32* @z, align 4
  br label %if.end

if.end:                                           ; preds = %if.else, %if.then
  %0 = phi i32 [ %.pre, %if.else ], [ %add, %if.then ]
  tail call void @bar(i32 %0)
  ret void
}

declare void @bar(i32)