1; RUN: llc %s -o - -enable-shrink-wrap=true -no-x86-call-frame-opt | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
2; RUN: llc %s -o - -enable-shrink-wrap=false -no-x86-call-frame-opt | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
3target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
4target triple = "i386-apple-macosx10.5"
5
6@a = common global i32 0, align 4
7@d = internal unnamed_addr global i1 false
8@b = common global i32 0, align 4
9@e = common global i8 0, align 1
10@f = common global i8 0, align 1
11@c = common global i32 0, align 4
12@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1
13
14
15; Check that we are clobbering the flags when they are live-in of the
16; prologue block and the prologue needs to adjust the stack.
17; PR25607.
18;
19; CHECK-LABEL: eflagsLiveInPrologue:
20;
21; DISABLE: pushl
22; DISABLE-NEXT: pushl
23; DISABLE-NEXT: subl $20, %esp
24;
25; CHECK: movl L_a$non_lazy_ptr, [[A:%[a-z]+]]
26; CHECK-NEXT: cmpl $0, ([[A]])
27; CHECK-NEXT: je [[PREHEADER_LABEL:LBB[0-9_]+]]
28;
29; CHECK: movb $1, _d
30;
31; CHECK: [[PREHEADER_LABEL]]:
32; CHECK-NEXT: movl L_b$non_lazy_ptr, [[B:%[a-z]+]]
33; CHECK-NEXT: movl ([[B]]), [[TMP1:%[a-z]+]]
34; CHECK-NEXT: testl [[TMP1]], [[TMP1]]
35; CHECK-NEXT: je  [[FOREND_LABEL:LBB[0-9_]+]]
36;
37; Skip the loop.
38; [...]
39;
40; The for.end block is split to accomadate the different selects.
41; We are interested in the one with the call, so skip until the branch.
42; CHECK: [[FOREND_LABEL]]:
43; CHECK-NEXT: xorl
44; CHECK-NEXT: cmpb $0, _d
45; CHECK-NEXT: movl $0, %edx
46; CHECK-NEXT: jne [[CALL_LABEL:LBB[0-9_]+]]
47;
48; CHECK: movb $6, %dl
49;
50; CHECK: [[CALL_LABEL]]
51;
52; ENABLE-NEXT: pushl
53; ENABLE-NEXT: pushl
54; We must not use sub here otherwise we will clobber the eflags.
55; ENABLE-NEXT: leal -20(%esp), %esp
56;
57; CHECK-NEXT: L_e$non_lazy_ptr, [[E:%[a-z]+]]
58; CHECK-NEXT: movb %dl, ([[E]])
59; CHECK-NEXT: movzbl %dl, [[CONV:%[a-z]+]]
60; CHECK-NEXT: movl $6, [[CONV:%[a-z]+]]
61; The eflags is used in the next instruction.
62; If that instruction disappear, we are not exercising the bug
63; anymore.
64; CHECK-NEXT: cmovnel {{%[a-z]+}}, [[CONV]]
65;
66; Skip all the crust of vaarg lowering.
67; CHECK: calll _varfunc
68; Set the return value to 0.
69; CHECK-NEXT: xorl %eax, %eax
70; CHECK-NEXT: addl $20, %esp
71; CHECK-NEXT: popl
72; CHECK-NEXT: popl
73; CHECK-NEXT: retl
74define i32 @eflagsLiveInPrologue() #0 {
75entry:
76  %tmp = load i32, i32* @a, align 4
77  %tobool = icmp eq i32 %tmp, 0
78  br i1 %tobool, label %for.cond.preheader, label %if.then
79
80if.then:                                          ; preds = %entry
81  store i1 true, i1* @d, align 1
82  br label %for.cond.preheader
83
84for.cond.preheader:                               ; preds = %if.then, %entry
85  %tmp1 = load i32, i32* @b, align 4
86  %tobool14 = icmp eq i32 %tmp1, 0
87  br i1 %tobool14, label %for.end, label %for.body.preheader
88
89for.body.preheader:                               ; preds = %for.cond.preheader
90  br label %for.body
91
92for.body:                                         ; preds = %for.body, %for.body.preheader
93  br label %for.body
94
95for.end:                                          ; preds = %for.cond.preheader
96  %.b3 = load i1, i1* @d, align 1
97  %tmp2 = select i1 %.b3, i8 0, i8 6
98  store i8 %tmp2, i8* @e, align 1
99  %tmp3 = load i8, i8* @e, align 1
100  %conv = sext i8 %tmp3 to i32
101  %add = add nsw i32 %conv, 1
102  %rem = srem i32 %tmp1, %add
103  store i32 %rem, i32* @c, align 4
104  %conv2 = select i1 %.b3, i32 0, i32 6
105  %call = tail call i32 (i8*, ...) @varfunc(i8* nonnull getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %conv2) #1
106  ret i32 0
107}
108
109; Function Attrs: nounwind
110declare i32 @varfunc(i8* nocapture readonly, ...) #0
111
112attributes #0 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-features"="+mmx,+sse" "unsafe-fp-math"="false" "use-soft-float"="false" }
113attributes #1 = { nounwind }
114