1 ; RUN: opt -passes=gvn -S < %s | FileCheck %s
7 ; puts (x == 2 ? "a" : "b");
12 ; printf("step 2: %d\n", x);
16 ; If we PRE %cmp3, CodeGenPrepare won't be able to sink the compare down to its
17 ; uses, and we are forced to keep both %x and %cmp3 in registers in the loop.
19 ; It is just as cheap to recompute the icmp against %x as it is to compare a
20 ; GPR against 0. On x86-64, the br i1 %cmp3 becomes:
30 ; This is just as good, and it doesn't require a separate register.
34 @.str = private unnamed_addr constant [2 x i8] c"a\00", align 1
35 @.str1 = private unnamed_addr constant [2 x i8] c"b\00", align 1
36 @.str2 = private unnamed_addr constant [7 x i8] c"step 1\00", align 1
37 @.str3 = private unnamed_addr constant [12 x i8] c"step 2: %d\0A\00", align 1
39 define void @f(i32 %x) noreturn nounwind uwtable ssp {
41 %cmp = icmp eq i32 %x, 1
42 br i1 %cmp, label %for.cond.preheader, label %if.then
44 if.then: ; preds = %entry
45 %cmp1 = icmp eq i32 %x, 2
46 %cond = select i1 %cmp1, ptr @.str, ptr @.str1
47 %call = tail call i32 @puts(ptr %cond) nounwind
48 br label %for.cond.preheader
50 for.cond.preheader: ; preds = %entry, %if.then
51 %cmp3 = icmp eq i32 %x, 2
54 for.cond: ; preds = %for.cond.backedge, %for.cond.preheader
55 %call2 = tail call i32 @puts(ptr @.str2) nounwind
56 br i1 %cmp3, label %for.cond.backedge, label %if.end5
58 if.end5: ; preds = %for.cond
59 %call6 = tail call i32 (ptr, ...) @printf(ptr @.str3, i32 %x) nounwind
60 br label %for.cond.backedge
62 for.cond.backedge: ; preds = %if.end5, %for.cond
66 declare i32 @puts(ptr nocapture) nounwind
68 declare i32 @printf(ptr nocapture, ...) nounwind