[X86, Win64] Use a frame pointer if pushf is emitted
[oota-llvm.git] / test / CodeGen / X86 / x86-win64-shrink-wrapping.ll
1 ; RUN: llc %s -o - -enable-shrink-wrap=true | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE
2 ; RUN: llc %s -o - -enable-shrink-wrap=false | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE
3
4 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
5 target triple = "x86_64--windows-gnu"
6
7 ; The output of this function with or without shrink-wrapping
8 ; shouldn't change.
9 ; Indeed, the epilogue block would have been if.else, meaning
10 ; after the pops, we will have additional instruction (jump, mov,
11 ; etc.) prior to the return and this is forbidden for Win64.
12 ; CHECK-LABEL: loopInfoSaveOutsideLoop:
13 ; CHECK: push
14 ; CHECK: push
15 ; CHECK-NOT: popq
16 ; CHECK: popq
17 ; CHECK: popq
18 ; CHECK-NOT: popq
19 ; CHECK-NEXT: retq
20 define i32 @loopInfoSaveOutsideLoop(i32 %cond, i32 %N) #0 {
21 entry:
22   %tobool = icmp eq i32 %cond, 0
23   br i1 %tobool, label %if.else, label %for.preheader
24
25 for.preheader:                                    ; preds = %entry
26   tail call void asm "nop", ""()
27   br label %for.body
28
29 for.body:                                         ; preds = %for.body, %for.preheader
30   %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.preheader ]
31   %sum.04 = phi i32 [ %add, %for.body ], [ 0, %for.preheader ]
32   %call = tail call i32 asm "movl $$1, $0", "=r,~{ebx}"()
33   %add = add nsw i32 %call, %sum.04
34   %inc = add nuw nsw i32 %i.05, 1
35   %exitcond = icmp eq i32 %inc, 10
36   br i1 %exitcond, label %for.end, label %for.body
37
38 for.end:                                          ; preds = %for.body
39   tail call void asm "nop", "~{ebx}"()
40   %shl = shl i32 %add, 3
41   br label %if.end
42
43 if.else:                                          ; preds = %entry
44   %mul = shl nsw i32 %N, 1
45   br label %if.end
46
47 if.end:                                           ; preds = %if.else, %for.end
48   %sum.1 = phi i32 [ %shl, %for.end ], [ %mul, %if.else ]
49   ret i32 %sum.1
50 }
51
52 ; When we can sink the epilogue of the function into an existing exit block,
53 ; this is Ok for shrink-wrapping to kicks in.
54 ; CHECK-LABEL: loopInfoSaveOutsideLoop2:
55 ; ENABLE: testl %ecx, %ecx
56 ; ENABLE-NEXT: je [[ELSE_LABEL:.LBB[0-9_]+]]
57 ;
58 ; Prologue code.
59 ; Make sure we save the CSR used in the inline asm: rbx.
60 ; CHECK: pushq %rbp
61 ; CHECK: pushq %rbx
62 ;
63 ; DISABLE: testl %ecx, %ecx
64 ; DISABLE-NEXT: je [[ELSE_LABEL:.LBB[0-9_]+]]
65 ;
66 ; CHECK: nop
67 ; CHECK: xorl [[SUM:%eax]], [[SUM]]
68 ; CHECK-NEXT: movl $10, [[IV:%e[a-z]+]]
69 ;
70 ; CHECK: [[LOOP_LABEL:.LBB[0-9_]+]]: # %for.body
71 ; CHECK: movl $1, [[TMP:%e[a-z]+]]
72 ; CHECK: addl [[TMP]], [[SUM]]
73 ; CHECK-NEXT: decl [[IV]]
74 ; CHECK-NEXT: jne [[LOOP_LABEL]]
75 ; Next BB.
76 ; CHECK: nop
77 ; CHECK: shll $3, [[SUM]]
78 ;
79 ; DISABLE: jmp [[EPILOG_BB:.LBB[0-9_]+]]
80 ;
81 ; ENABLE-NEXT: popq %rbx
82 ; ENABLE-NEXT: popq %rbp
83 ; ENABLE-NEXT: retq
84 ;
85 ; CHECK: [[ELSE_LABEL]]: # %if.else
86 ; Shift second argument by one and store into returned register.
87 ; CHECK: addl %edx, %edx
88 ; CHECK: movl %edx, %eax
89 ;
90 ; DISABLE: [[EPILOG_BB]]: # %if.end
91 ; DISABLE-NEXT: popq %rbx
92 ;
93 ; CHECK: retq
94 ;
95 define i32 @loopInfoSaveOutsideLoop2(i32 %cond, i32 %N) #0 {
96 entry:
97   %tobool = icmp eq i32 %cond, 0
98   br i1 %tobool, label %if.else, label %for.preheader
99
100 for.preheader:                                    ; preds = %entry
101   tail call void asm "nop", ""()
102   br label %for.body
103
104 for.body:                                         ; preds = %for.body, %for.preheader
105   %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.preheader ]
106   %sum.04 = phi i32 [ %add, %for.body ], [ 0, %for.preheader ]
107   %call = tail call i32 asm "movl $$1, $0", "=r,~{ebx}"()
108   %add = add nsw i32 %call, %sum.04
109   %inc = add nuw nsw i32 %i.05, 1
110   %exitcond = icmp eq i32 %inc, 10
111   br i1 %exitcond, label %for.end, label %for.body
112
113 for.end:                                          ; preds = %for.body
114   tail call void asm "nop", "~{ebx}"()
115   %shl = shl i32 %add, 3
116   ret i32 %shl
117
118 if.else:                                          ; preds = %entry
119   %mul = shl nsw i32 %N, 1
120   br label %if.end
121
122 if.end:                                           ; preds = %if.else, %for.end
123   ret i32 %mul
124 }
125
126 attributes #0 = { uwtable }