File: pre-compare.ll

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; cs: 573
file content (68 lines) | stat: -rw-r--r-- 2,101 bytes parent folder | download | duplicates (10)
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
; RUN: opt -passes=gvn -S < %s | FileCheck %s

; C source:
;
;   void f(int x) {
;     if (x != 1)
;       puts (x == 2 ? "a" : "b");
;     for (;;) {
;       puts("step 1");
;       if (x == 2)
;         continue;
;       printf("step 2: %d\n", x);
;     }
;   }
;
; If we PRE %cmp3, CodeGenPrepare won't be able to sink the compare down to its
; uses, and we are forced to keep both %x and %cmp3 in registers in the loop.
;
; It is just as cheap to recompute the icmp against %x as it is to compare a
; GPR against 0. On x86-64, the br i1 %cmp3 becomes:
;
;   testb %r12b, %r12b
;   jne	LBB0_3
;
; The sunk icmp is:
;
;   cmpl $2, %ebx
;   je	LBB0_3
;
; This is just as good, and it doesn't require a separate register.
;
; CHECK-NOT: phi i1

@.str = private unnamed_addr constant [2 x i8] c"a\00", align 1
@.str1 = private unnamed_addr constant [2 x i8] c"b\00", align 1
@.str2 = private unnamed_addr constant [7 x i8] c"step 1\00", align 1
@.str3 = private unnamed_addr constant [12 x i8] c"step 2: %d\0A\00", align 1

define void @f(i32 %x) noreturn nounwind uwtable ssp {
entry:
  %cmp = icmp eq i32 %x, 1
  br i1 %cmp, label %for.cond.preheader, label %if.then

if.then:                                          ; preds = %entry
  %cmp1 = icmp eq i32 %x, 2
  %cond = select i1 %cmp1, ptr @.str, ptr @.str1
  %call = tail call i32 @puts(ptr %cond) nounwind
  br label %for.cond.preheader

for.cond.preheader:                               ; preds = %entry, %if.then
  %cmp3 = icmp eq i32 %x, 2
  br label %for.cond

for.cond:                                         ; preds = %for.cond.backedge, %for.cond.preheader
  %call2 = tail call i32 @puts(ptr @.str2) nounwind
  br i1 %cmp3, label %for.cond.backedge, label %if.end5

if.end5:                                          ; preds = %for.cond
  %call6 = tail call i32 (ptr, ...) @printf(ptr @.str3, i32 %x) nounwind
  br label %for.cond.backedge

for.cond.backedge:                                ; preds = %if.end5, %for.cond
  br label %for.cond
}

declare i32 @puts(ptr nocapture) nounwind

declare i32 @printf(ptr nocapture, ...) nounwind