[PowerPC] Recommit r314244 with refactoring and off by default
[llvm-core.git] / test / CodeGen / X86 / i386-shrink-wrapping.ll
blobd4e099ac6558e9a0de43702d2fe85eb9e757d1eb
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
3 target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
4 target triple = "i386-apple-macosx10.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
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.
19 ; CHECK-LABEL: eflagsLiveInPrologue:
21 ; DISABLE: pushl
22 ; DISABLE-NEXT: pushl
23 ; DISABLE-NEXT: subl $20, %esp
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_]+]]
29 ; CHECK: movb $1, _d
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_]+]]
37 ; Skip the loop.
38 ; [...]
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: movb _d, [[D:%[a-z]+]]
44 ; [...]
45 ; CHECK: jne [[CALL_LABEL:LBB[0-9_]+]]
47 ; CHECK: movb $6, [[D]]
49 ; CHECK: [[CALL_LABEL]]
51 ; ENABLE-NEXT: pushl
52 ; ENABLE-NEXT: pushl
53 ; We must not use sub here otherwise we will clobber the eflags.
54 ; ENABLE-NEXT: leal -20(%esp), %esp
56 ; CHECK-NEXT: L_e$non_lazy_ptr, [[E:%[a-z]+]]
57 ; CHECK-NEXT: movb [[D]], ([[E]])
58 ; CHECK-NEXT: movsbl ([[E]]), [[CONV:%[a-z]+]]
59 ; CHECK-NEXT: movl $6, [[CONV:%[a-z]+]]
60 ; The eflags is used in the next instruction.
61 ; If that instruction disappear, we are not exercising the bug
62 ; anymore.
63 ; CHECK-NEXT: cmovnel {{%[a-z]+}}, [[CONV]]
65 ; Skip all the crust of vaarg lowering.
66 ; CHECK: calll _varfunc
67 ; Set the return value to 0.
68 ; CHECK-NEXT: xorl %eax, %eax
69 ; CHECK-NEXT: addl $20, %esp
70 ; CHECK-NEXT: popl
71 ; CHECK-NEXT: popl
72 ; CHECK-NEXT: retl
73 define i32 @eflagsLiveInPrologue() #0 {
74 entry:
75   %tmp = load i32, i32* @a, align 4
76   %tobool = icmp eq i32 %tmp, 0
77   br i1 %tobool, label %for.cond.preheader, label %if.then
79 if.then:                                          ; preds = %entry
80   store i1 true, i1* @d, align 1
81   br label %for.cond.preheader
83 for.cond.preheader:                               ; preds = %if.then, %entry
84   %tmp1 = load i32, i32* @b, align 4
85   %tobool14 = icmp eq i32 %tmp1, 0
86   br i1 %tobool14, label %for.end, label %for.body.preheader
88 for.body.preheader:                               ; preds = %for.cond.preheader
89   br label %for.body
91 for.body:                                         ; preds = %for.body, %for.body.preheader
92   br label %for.body
94 for.end:                                          ; preds = %for.cond.preheader
95   %.b3 = load i1, i1* @d, align 1
96   %tmp2 = select i1 %.b3, i8 0, i8 6
97   store i8 %tmp2, i8* @e, align 1
98   %tmp3 = load i8, i8* @e, align 1
99   %conv = sext i8 %tmp3 to i32
100   %add = add nsw i32 %conv, 1
101   %rem = srem i32 %tmp1, %add
102   store i32 %rem, i32* @c, align 4
103   %conv2 = select i1 %.b3, i32 0, i32 6
104   %call = tail call i32 (i8*, ...) @varfunc(i8* nonnull getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %conv2) #1
105   ret i32 0
108 ; Function Attrs: nounwind
109 declare i32 @varfunc(i8* nocapture readonly, ...) #0
111 attributes #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" }
112 attributes #1 = { nounwind }