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
4 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
5 target triple = "x86_64--windows-gnu"
7 ; The output of this function with or without shrink-wrapping
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:
20 define i32 @loopInfoSaveOutsideLoop(i32 %cond, i32 %N) #0 {
22 %tobool = icmp eq i32 %cond, 0
23 br i1 %tobool, label %if.else, label %for.preheader
25 for.preheader: ; preds = %entry
26 tail call void asm "nop", ""()
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
38 for.end: ; preds = %for.body
39 tail call void asm "nop", "~{ebx}"()
40 %shl = shl i32 %add, 3
43 if.else: ; preds = %entry
44 %mul = shl nsw i32 %N, 1
47 if.end: ; preds = %if.else, %for.end
48 %sum.1 = phi i32 [ %shl, %for.end ], [ %mul, %if.else ]
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_]+]]
59 ; Make sure we save the CSR used in the inline asm: rbx.
63 ; DISABLE: testl %ecx, %ecx
64 ; DISABLE-NEXT: je [[ELSE_LABEL:.LBB[0-9_]+]]
67 ; CHECK: xorl [[SUM:%eax]], [[SUM]]
68 ; CHECK-NEXT: movl $10, [[IV:%e[a-z]+]]
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]]
77 ; CHECK: shll $3, [[SUM]]
79 ; DISABLE: jmp [[EPILOG_BB:.LBB[0-9_]+]]
81 ; ENABLE-NEXT: popq %rbx
82 ; ENABLE-NEXT: popq %rbp
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
90 ; DISABLE: [[EPILOG_BB]]: # %if.end
91 ; DISABLE-NEXT: popq %rbx
95 define i32 @loopInfoSaveOutsideLoop2(i32 %cond, i32 %N) #0 {
97 %tobool = icmp eq i32 %cond, 0
98 br i1 %tobool, label %if.else, label %for.preheader
100 for.preheader: ; preds = %entry
101 tail call void asm "nop", ""()
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
113 for.end: ; preds = %for.body
114 tail call void asm "nop", "~{ebx}"()
115 %shl = shl i32 %add, 3
118 if.else: ; preds = %entry
119 %mul = shl nsw i32 %N, 1
122 if.end: ; preds = %if.else, %for.end
126 attributes #0 = { uwtable }