1*9880d681SAndroid Build Coastguard Worker; RUN: llc %s -o - -enable-shrink-wrap=true | FileCheck %s --check-prefix=CHECK --check-prefix=ENABLE 2*9880d681SAndroid Build Coastguard Worker; RUN: llc %s -o - -enable-shrink-wrap=false | FileCheck %s --check-prefix=CHECK --check-prefix=DISABLE 3*9880d681SAndroid Build Coastguard Worker; 4*9880d681SAndroid Build Coastguard Worker; Note: Lots of tests use inline asm instead of regular calls. 5*9880d681SAndroid Build Coastguard Worker; This allows to have a better control on what the allocation will do. 6*9880d681SAndroid Build Coastguard Worker; Otherwise, we may have spill right in the entry block, defeating 7*9880d681SAndroid Build Coastguard Worker; shrink-wrapping. Moreover, some of the inline asm statement (nop) 8*9880d681SAndroid Build Coastguard Worker; are here to ensure that the related paths do not end up as critical 9*9880d681SAndroid Build Coastguard Worker; edges. 10*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" 11*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-apple-macosx" 12*9880d681SAndroid Build Coastguard Worker 13*9880d681SAndroid Build Coastguard Worker 14*9880d681SAndroid Build Coastguard Worker; Initial motivating example: Simple diamond with a call just on one side. 15*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: foo: 16*9880d681SAndroid Build Coastguard Worker; 17*9880d681SAndroid Build Coastguard Worker; Compare the arguments and jump to exit. 18*9880d681SAndroid Build Coastguard Worker; No prologue needed. 19*9880d681SAndroid Build Coastguard Worker; ENABLE: movl %edi, [[ARG0CPY:%e[a-z]+]] 20*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: cmpl %esi, [[ARG0CPY]] 21*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: jge [[EXIT_LABEL:LBB[0-9_]+]] 22*9880d681SAndroid Build Coastguard Worker; 23*9880d681SAndroid Build Coastguard Worker; Prologue code. 24*9880d681SAndroid Build Coastguard Worker; (What we push does not matter. It should be some random sratch register.) 25*9880d681SAndroid Build Coastguard Worker; CHECK: pushq 26*9880d681SAndroid Build Coastguard Worker; 27*9880d681SAndroid Build Coastguard Worker; Compare the arguments and jump to exit. 28*9880d681SAndroid Build Coastguard Worker; After the prologue is set. 29*9880d681SAndroid Build Coastguard Worker; DISABLE: movl %edi, [[ARG0CPY:%e[a-z]+]] 30*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: cmpl %esi, [[ARG0CPY]] 31*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: jge [[EXIT_LABEL:LBB[0-9_]+]] 32*9880d681SAndroid Build Coastguard Worker; 33*9880d681SAndroid Build Coastguard Worker; Store %a in the alloca. 34*9880d681SAndroid Build Coastguard Worker; CHECK: movl [[ARG0CPY]], 4(%rsp) 35*9880d681SAndroid Build Coastguard Worker; Set the alloca address in the second argument. 36*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: leaq 4(%rsp), %rsi 37*9880d681SAndroid Build Coastguard Worker; Set the first argument to zero. 38*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: xorl %edi, %edi 39*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: callq _doSomething 40*9880d681SAndroid Build Coastguard Worker; 41*9880d681SAndroid Build Coastguard Worker; With shrink-wrapping, epilogue is just after the call. 42*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: addq $8, %rsp 43*9880d681SAndroid Build Coastguard Worker; 44*9880d681SAndroid Build Coastguard Worker; CHECK: [[EXIT_LABEL]]: 45*9880d681SAndroid Build Coastguard Worker; 46*9880d681SAndroid Build Coastguard Worker; Without shrink-wrapping, epilogue is in the exit block. 47*9880d681SAndroid Build Coastguard Worker; Epilogue code. (What we pop does not matter.) 48*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: popq 49*9880d681SAndroid Build Coastguard Worker; 50*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: retq 51*9880d681SAndroid Build Coastguard Workerdefine i32 @foo(i32 %a, i32 %b) { 52*9880d681SAndroid Build Coastguard Worker %tmp = alloca i32, align 4 53*9880d681SAndroid Build Coastguard Worker %tmp2 = icmp slt i32 %a, %b 54*9880d681SAndroid Build Coastguard Worker br i1 %tmp2, label %true, label %false 55*9880d681SAndroid Build Coastguard Worker 56*9880d681SAndroid Build Coastguard Workertrue: 57*9880d681SAndroid Build Coastguard Worker store i32 %a, i32* %tmp, align 4 58*9880d681SAndroid Build Coastguard Worker %tmp4 = call i32 @doSomething(i32 0, i32* %tmp) 59*9880d681SAndroid Build Coastguard Worker br label %false 60*9880d681SAndroid Build Coastguard Worker 61*9880d681SAndroid Build Coastguard Workerfalse: 62*9880d681SAndroid Build Coastguard Worker %tmp.0 = phi i32 [ %tmp4, %true ], [ %a, %0 ] 63*9880d681SAndroid Build Coastguard Worker ret i32 %tmp.0 64*9880d681SAndroid Build Coastguard Worker} 65*9880d681SAndroid Build Coastguard Worker 66*9880d681SAndroid Build Coastguard Worker; Function Attrs: optsize 67*9880d681SAndroid Build Coastguard Workerdeclare i32 @doSomething(i32, i32*) 68*9880d681SAndroid Build Coastguard Worker 69*9880d681SAndroid Build Coastguard Worker 70*9880d681SAndroid Build Coastguard Worker; Check that we do not perform the restore inside the loop whereas the save 71*9880d681SAndroid Build Coastguard Worker; is outside. 72*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: freqSaveAndRestoreOutsideLoop: 73*9880d681SAndroid Build Coastguard Worker; 74*9880d681SAndroid Build Coastguard Worker; Shrink-wrapping allows to skip the prologue in the else case. 75*9880d681SAndroid Build Coastguard Worker; ENABLE: testl %edi, %edi 76*9880d681SAndroid Build Coastguard Worker; ENABLE: je [[ELSE_LABEL:LBB[0-9_]+]] 77*9880d681SAndroid Build Coastguard Worker; 78*9880d681SAndroid Build Coastguard Worker; Prologue code. 79*9880d681SAndroid Build Coastguard Worker; Make sure we save the CSR used in the inline asm: rbx. 80*9880d681SAndroid Build Coastguard Worker; CHECK: pushq %rbx 81*9880d681SAndroid Build Coastguard Worker; 82*9880d681SAndroid Build Coastguard Worker; DISABLE: testl %edi, %edi 83*9880d681SAndroid Build Coastguard Worker; DISABLE: je [[ELSE_LABEL:LBB[0-9_]+]] 84*9880d681SAndroid Build Coastguard Worker; 85*9880d681SAndroid Build Coastguard Worker; SUM is in %esi because it is coalesced with the second 86*9880d681SAndroid Build Coastguard Worker; argument on the else path. 87*9880d681SAndroid Build Coastguard Worker; CHECK: xorl [[SUM:%esi]], [[SUM]] 88*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movl $10, [[IV:%e[a-z]+]] 89*9880d681SAndroid Build Coastguard Worker; 90*9880d681SAndroid Build Coastguard Worker; Next BB. 91*9880d681SAndroid Build Coastguard Worker; CHECK: [[LOOP:LBB[0-9_]+]]: ## %for.body 92*9880d681SAndroid Build Coastguard Worker; CHECK: movl $1, [[TMP:%e[a-z]+]] 93*9880d681SAndroid Build Coastguard Worker; CHECK: addl [[TMP]], [[SUM]] 94*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: decl [[IV]] 95*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: jne [[LOOP]] 96*9880d681SAndroid Build Coastguard Worker; 97*9880d681SAndroid Build Coastguard Worker; Next BB. 98*9880d681SAndroid Build Coastguard Worker; SUM << 3. 99*9880d681SAndroid Build Coastguard Worker; CHECK: shll $3, [[SUM]] 100*9880d681SAndroid Build Coastguard Worker; 101*9880d681SAndroid Build Coastguard Worker; Jump to epilogue. 102*9880d681SAndroid Build Coastguard Worker; DISABLE: jmp [[EPILOG_BB:LBB[0-9_]+]] 103*9880d681SAndroid Build Coastguard Worker; 104*9880d681SAndroid Build Coastguard Worker; DISABLE: [[ELSE_LABEL]]: ## %if.else 105*9880d681SAndroid Build Coastguard Worker; Shift second argument by one and store into returned register. 106*9880d681SAndroid Build Coastguard Worker; DISABLE: addl %esi, %esi 107*9880d681SAndroid Build Coastguard Worker; DISABLE: [[EPILOG_BB]]: ## %if.end 108*9880d681SAndroid Build Coastguard Worker; 109*9880d681SAndroid Build Coastguard Worker; Epilogue code. 110*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: popq %rbx 111*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: movl %esi, %eax 112*9880d681SAndroid Build Coastguard Worker; CHECK: retq 113*9880d681SAndroid Build Coastguard Worker; 114*9880d681SAndroid Build Coastguard Worker; ENABLE: [[ELSE_LABEL]]: ## %if.else 115*9880d681SAndroid Build Coastguard Worker; Shift second argument by one and store into returned register. 116*9880d681SAndroid Build Coastguard Worker; ENABLE: addl %esi, %esi 117*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: movl %esi, %eax 118*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: retq 119*9880d681SAndroid Build Coastguard Workerdefine i32 @freqSaveAndRestoreOutsideLoop(i32 %cond, i32 %N) { 120*9880d681SAndroid Build Coastguard Workerentry: 121*9880d681SAndroid Build Coastguard Worker %tobool = icmp eq i32 %cond, 0 122*9880d681SAndroid Build Coastguard Worker br i1 %tobool, label %if.else, label %for.preheader 123*9880d681SAndroid Build Coastguard Worker 124*9880d681SAndroid Build Coastguard Workerfor.preheader: 125*9880d681SAndroid Build Coastguard Worker tail call void asm "nop", ""() 126*9880d681SAndroid Build Coastguard Worker br label %for.body 127*9880d681SAndroid Build Coastguard Worker 128*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %entry, %for.body 129*9880d681SAndroid Build Coastguard Worker %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.preheader ] 130*9880d681SAndroid Build Coastguard Worker %sum.04 = phi i32 [ %add, %for.body ], [ 0, %for.preheader ] 131*9880d681SAndroid Build Coastguard Worker %call = tail call i32 asm "movl $$1, $0", "=r,~{ebx}"() 132*9880d681SAndroid Build Coastguard Worker %add = add nsw i32 %call, %sum.04 133*9880d681SAndroid Build Coastguard Worker %inc = add nuw nsw i32 %i.05, 1 134*9880d681SAndroid Build Coastguard Worker %exitcond = icmp eq i32 %inc, 10 135*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %for.end, label %for.body 136*9880d681SAndroid Build Coastguard Worker 137*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %for.body 138*9880d681SAndroid Build Coastguard Worker %shl = shl i32 %add, 3 139*9880d681SAndroid Build Coastguard Worker br label %if.end 140*9880d681SAndroid Build Coastguard Worker 141*9880d681SAndroid Build Coastguard Workerif.else: ; preds = %entry 142*9880d681SAndroid Build Coastguard Worker %mul = shl nsw i32 %N, 1 143*9880d681SAndroid Build Coastguard Worker br label %if.end 144*9880d681SAndroid Build Coastguard Worker 145*9880d681SAndroid Build Coastguard Workerif.end: ; preds = %if.else, %for.end 146*9880d681SAndroid Build Coastguard Worker %sum.1 = phi i32 [ %shl, %for.end ], [ %mul, %if.else ] 147*9880d681SAndroid Build Coastguard Worker ret i32 %sum.1 148*9880d681SAndroid Build Coastguard Worker} 149*9880d681SAndroid Build Coastguard Worker 150*9880d681SAndroid Build Coastguard Workerdeclare i32 @something(...) 151*9880d681SAndroid Build Coastguard Worker 152*9880d681SAndroid Build Coastguard Worker; Check that we do not perform the shrink-wrapping inside the loop even 153*9880d681SAndroid Build Coastguard Worker; though that would be legal. The cost model must prevent that. 154*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: freqSaveAndRestoreOutsideLoop2: 155*9880d681SAndroid Build Coastguard Worker; Prologue code. 156*9880d681SAndroid Build Coastguard Worker; Make sure we save the CSR used in the inline asm: rbx. 157*9880d681SAndroid Build Coastguard Worker; CHECK: pushq %rbx 158*9880d681SAndroid Build Coastguard Worker; CHECK: nop 159*9880d681SAndroid Build Coastguard Worker; CHECK: xorl [[SUM:%e[a-z]+]], [[SUM]] 160*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movl $10, [[IV:%e[a-z]+]] 161*9880d681SAndroid Build Coastguard Worker; Next BB. 162*9880d681SAndroid Build Coastguard Worker; CHECK: [[LOOP_LABEL:LBB[0-9_]+]]: ## %for.body 163*9880d681SAndroid Build Coastguard Worker; CHECK: movl $1, [[TMP:%e[a-z]+]] 164*9880d681SAndroid Build Coastguard Worker; CHECK: addl [[TMP]], [[SUM]] 165*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: decl [[IV]] 166*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: jne [[LOOP_LABEL]] 167*9880d681SAndroid Build Coastguard Worker; Next BB. 168*9880d681SAndroid Build Coastguard Worker; CHECK: ## %for.exit 169*9880d681SAndroid Build Coastguard Worker; CHECK: nop 170*9880d681SAndroid Build Coastguard Worker; CHECK: popq %rbx 171*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: retq 172*9880d681SAndroid Build Coastguard Workerdefine i32 @freqSaveAndRestoreOutsideLoop2(i32 %cond) { 173*9880d681SAndroid Build Coastguard Workerentry: 174*9880d681SAndroid Build Coastguard Worker br label %for.preheader 175*9880d681SAndroid Build Coastguard Worker 176*9880d681SAndroid Build Coastguard Workerfor.preheader: 177*9880d681SAndroid Build Coastguard Worker tail call void asm "nop", ""() 178*9880d681SAndroid Build Coastguard Worker br label %for.body 179*9880d681SAndroid Build Coastguard Worker 180*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %for.body, %entry 181*9880d681SAndroid Build Coastguard Worker %i.04 = phi i32 [ 0, %for.preheader ], [ %inc, %for.body ] 182*9880d681SAndroid Build Coastguard Worker %sum.03 = phi i32 [ 0, %for.preheader ], [ %add, %for.body ] 183*9880d681SAndroid Build Coastguard Worker %call = tail call i32 asm "movl $$1, $0", "=r,~{ebx}"() 184*9880d681SAndroid Build Coastguard Worker %add = add nsw i32 %call, %sum.03 185*9880d681SAndroid Build Coastguard Worker %inc = add nuw nsw i32 %i.04, 1 186*9880d681SAndroid Build Coastguard Worker %exitcond = icmp eq i32 %inc, 10 187*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %for.exit, label %for.body 188*9880d681SAndroid Build Coastguard Worker 189*9880d681SAndroid Build Coastguard Workerfor.exit: 190*9880d681SAndroid Build Coastguard Worker tail call void asm "nop", ""() 191*9880d681SAndroid Build Coastguard Worker br label %for.end 192*9880d681SAndroid Build Coastguard Worker 193*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %for.body 194*9880d681SAndroid Build Coastguard Worker ret i32 %add 195*9880d681SAndroid Build Coastguard Worker} 196*9880d681SAndroid Build Coastguard Worker 197*9880d681SAndroid Build Coastguard Worker; Check with a more complex case that we do not have save within the loop and 198*9880d681SAndroid Build Coastguard Worker; restore outside. 199*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: loopInfoSaveOutsideLoop: 200*9880d681SAndroid Build Coastguard Worker; 201*9880d681SAndroid Build Coastguard Worker; ENABLE: testl %edi, %edi 202*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: je [[ELSE_LABEL:LBB[0-9_]+]] 203*9880d681SAndroid Build Coastguard Worker; 204*9880d681SAndroid Build Coastguard Worker; Prologue code. 205*9880d681SAndroid Build Coastguard Worker; Make sure we save the CSR used in the inline asm: rbx. 206*9880d681SAndroid Build Coastguard Worker; CHECK: pushq %rbx 207*9880d681SAndroid Build Coastguard Worker; 208*9880d681SAndroid Build Coastguard Worker; DISABLE: testl %edi, %edi 209*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: je [[ELSE_LABEL:LBB[0-9_]+]] 210*9880d681SAndroid Build Coastguard Worker; 211*9880d681SAndroid Build Coastguard Worker; CHECK: nop 212*9880d681SAndroid Build Coastguard Worker; CHECK: xorl [[SUM:%esi]], [[SUM]] 213*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movl $10, [[IV:%e[a-z]+]] 214*9880d681SAndroid Build Coastguard Worker; 215*9880d681SAndroid Build Coastguard Worker; CHECK: [[LOOP_LABEL:LBB[0-9_]+]]: ## %for.body 216*9880d681SAndroid Build Coastguard Worker; CHECK: movl $1, [[TMP:%e[a-z]+]] 217*9880d681SAndroid Build Coastguard Worker; CHECK: addl [[TMP]], [[SUM]] 218*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: decl [[IV]] 219*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: jne [[LOOP_LABEL]] 220*9880d681SAndroid Build Coastguard Worker; Next BB. 221*9880d681SAndroid Build Coastguard Worker; CHECK: nop 222*9880d681SAndroid Build Coastguard Worker; CHECK: shll $3, [[SUM]] 223*9880d681SAndroid Build Coastguard Worker; 224*9880d681SAndroid Build Coastguard Worker; DISABLE: jmp [[EPILOG_BB:LBB[0-9_]+]] 225*9880d681SAndroid Build Coastguard Worker; 226*9880d681SAndroid Build Coastguard Worker; DISABLE: [[ELSE_LABEL]]: ## %if.else 227*9880d681SAndroid Build Coastguard Worker; Shift second argument by one and store into returned register. 228*9880d681SAndroid Build Coastguard Worker; DISABLE: addl %esi, %esi 229*9880d681SAndroid Build Coastguard Worker; DISABLE: [[EPILOG_BB]]: ## %if.end 230*9880d681SAndroid Build Coastguard Worker; 231*9880d681SAndroid Build Coastguard Worker; Epilogue code. 232*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: popq %rbx 233*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: movl %esi, %eax 234*9880d681SAndroid Build Coastguard Worker; CHECK: retq 235*9880d681SAndroid Build Coastguard Worker; 236*9880d681SAndroid Build Coastguard Worker; ENABLE: [[ELSE_LABEL]]: ## %if.else 237*9880d681SAndroid Build Coastguard Worker; Shift second argument by one and store into returned register. 238*9880d681SAndroid Build Coastguard Worker; ENABLE: addl %esi, %esi 239*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: movl %esi, %eax 240*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: retq 241*9880d681SAndroid Build Coastguard Workerdefine i32 @loopInfoSaveOutsideLoop(i32 %cond, i32 %N) { 242*9880d681SAndroid Build Coastguard Workerentry: 243*9880d681SAndroid Build Coastguard Worker %tobool = icmp eq i32 %cond, 0 244*9880d681SAndroid Build Coastguard Worker br i1 %tobool, label %if.else, label %for.preheader 245*9880d681SAndroid Build Coastguard Worker 246*9880d681SAndroid Build Coastguard Workerfor.preheader: 247*9880d681SAndroid Build Coastguard Worker tail call void asm "nop", ""() 248*9880d681SAndroid Build Coastguard Worker br label %for.body 249*9880d681SAndroid Build Coastguard Worker 250*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %entry, %for.body 251*9880d681SAndroid Build Coastguard Worker %i.05 = phi i32 [ %inc, %for.body ], [ 0, %for.preheader ] 252*9880d681SAndroid Build Coastguard Worker %sum.04 = phi i32 [ %add, %for.body ], [ 0, %for.preheader ] 253*9880d681SAndroid Build Coastguard Worker %call = tail call i32 asm "movl $$1, $0", "=r,~{ebx}"() 254*9880d681SAndroid Build Coastguard Worker %add = add nsw i32 %call, %sum.04 255*9880d681SAndroid Build Coastguard Worker %inc = add nuw nsw i32 %i.05, 1 256*9880d681SAndroid Build Coastguard Worker %exitcond = icmp eq i32 %inc, 10 257*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %for.end, label %for.body 258*9880d681SAndroid Build Coastguard Worker 259*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %for.body 260*9880d681SAndroid Build Coastguard Worker tail call void asm "nop", "~{ebx}"() 261*9880d681SAndroid Build Coastguard Worker %shl = shl i32 %add, 3 262*9880d681SAndroid Build Coastguard Worker br label %if.end 263*9880d681SAndroid Build Coastguard Worker 264*9880d681SAndroid Build Coastguard Workerif.else: ; preds = %entry 265*9880d681SAndroid Build Coastguard Worker %mul = shl nsw i32 %N, 1 266*9880d681SAndroid Build Coastguard Worker br label %if.end 267*9880d681SAndroid Build Coastguard Worker 268*9880d681SAndroid Build Coastguard Workerif.end: ; preds = %if.else, %for.end 269*9880d681SAndroid Build Coastguard Worker %sum.1 = phi i32 [ %shl, %for.end ], [ %mul, %if.else ] 270*9880d681SAndroid Build Coastguard Worker ret i32 %sum.1 271*9880d681SAndroid Build Coastguard Worker} 272*9880d681SAndroid Build Coastguard Worker 273*9880d681SAndroid Build Coastguard Workerdeclare void @somethingElse(...) 274*9880d681SAndroid Build Coastguard Worker 275*9880d681SAndroid Build Coastguard Worker; Check with a more complex case that we do not have restore within the loop and 276*9880d681SAndroid Build Coastguard Worker; save outside. 277*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: loopInfoRestoreOutsideLoop: 278*9880d681SAndroid Build Coastguard Worker; 279*9880d681SAndroid Build Coastguard Worker; ENABLE: testl %edi, %edi 280*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: je [[ELSE_LABEL:LBB[0-9_]+]] 281*9880d681SAndroid Build Coastguard Worker; 282*9880d681SAndroid Build Coastguard Worker; Prologue code. 283*9880d681SAndroid Build Coastguard Worker; Make sure we save the CSR used in the inline asm: rbx. 284*9880d681SAndroid Build Coastguard Worker; CHECK: pushq %rbx 285*9880d681SAndroid Build Coastguard Worker; 286*9880d681SAndroid Build Coastguard Worker; DISABLE: testl %edi, %edi 287*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: je [[ELSE_LABEL:LBB[0-9_]+]] 288*9880d681SAndroid Build Coastguard Worker; 289*9880d681SAndroid Build Coastguard Worker; CHECK: nop 290*9880d681SAndroid Build Coastguard Worker; CHECK: xorl [[SUM:%esi]], [[SUM]] 291*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movl $10, [[IV:%e[a-z]+]] 292*9880d681SAndroid Build Coastguard Worker; 293*9880d681SAndroid Build Coastguard Worker; CHECK: [[LOOP_LABEL:LBB[0-9_]+]]: ## %for.body 294*9880d681SAndroid Build Coastguard Worker; CHECK: movl $1, [[TMP:%e[a-z]+]] 295*9880d681SAndroid Build Coastguard Worker; CHECK: addl [[TMP]], [[SUM]] 296*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: decl [[IV]] 297*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: jne [[LOOP_LABEL]] 298*9880d681SAndroid Build Coastguard Worker; Next BB. 299*9880d681SAndroid Build Coastguard Worker; CHECK: shll $3, [[SUM]] 300*9880d681SAndroid Build Coastguard Worker; 301*9880d681SAndroid Build Coastguard Worker; DISABLE: jmp [[EPILOG_BB:LBB[0-9_]+]] 302*9880d681SAndroid Build Coastguard Worker; 303*9880d681SAndroid Build Coastguard Worker; DISABLE: [[ELSE_LABEL]]: ## %if.else 304*9880d681SAndroid Build Coastguard Worker 305*9880d681SAndroid Build Coastguard Worker; Shift second argument by one and store into returned register. 306*9880d681SAndroid Build Coastguard Worker; DISABLE: addl %esi, %esi 307*9880d681SAndroid Build Coastguard Worker; DISABLE: [[EPILOG_BB]]: ## %if.end 308*9880d681SAndroid Build Coastguard Worker; 309*9880d681SAndroid Build Coastguard Worker; Epilogue code. 310*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: popq %rbx 311*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: movl %esi, %eax 312*9880d681SAndroid Build Coastguard Worker; CHECK: retq 313*9880d681SAndroid Build Coastguard Worker; 314*9880d681SAndroid Build Coastguard Worker; ENABLE: [[ELSE_LABEL]]: ## %if.else 315*9880d681SAndroid Build Coastguard Worker; Shift second argument by one and store into returned register. 316*9880d681SAndroid Build Coastguard Worker; ENABLE: addl %esi, %esi 317*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: movl %esi, %eax 318*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: retq 319*9880d681SAndroid Build Coastguard Workerdefine i32 @loopInfoRestoreOutsideLoop(i32 %cond, i32 %N) #0 { 320*9880d681SAndroid Build Coastguard Workerentry: 321*9880d681SAndroid Build Coastguard Worker %tobool = icmp eq i32 %cond, 0 322*9880d681SAndroid Build Coastguard Worker br i1 %tobool, label %if.else, label %if.then 323*9880d681SAndroid Build Coastguard Worker 324*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %entry 325*9880d681SAndroid Build Coastguard Worker tail call void asm "nop", "~{ebx}"() 326*9880d681SAndroid Build Coastguard Worker br label %for.body 327*9880d681SAndroid Build Coastguard Worker 328*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %for.body, %if.then 329*9880d681SAndroid Build Coastguard Worker %i.05 = phi i32 [ 0, %if.then ], [ %inc, %for.body ] 330*9880d681SAndroid Build Coastguard Worker %sum.04 = phi i32 [ 0, %if.then ], [ %add, %for.body ] 331*9880d681SAndroid Build Coastguard Worker %call = tail call i32 asm "movl $$1, $0", "=r,~{ebx}"() 332*9880d681SAndroid Build Coastguard Worker %add = add nsw i32 %call, %sum.04 333*9880d681SAndroid Build Coastguard Worker %inc = add nuw nsw i32 %i.05, 1 334*9880d681SAndroid Build Coastguard Worker %exitcond = icmp eq i32 %inc, 10 335*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %for.end, label %for.body 336*9880d681SAndroid Build Coastguard Worker 337*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %for.body 338*9880d681SAndroid Build Coastguard Worker %shl = shl i32 %add, 3 339*9880d681SAndroid Build Coastguard Worker br label %if.end 340*9880d681SAndroid Build Coastguard Worker 341*9880d681SAndroid Build Coastguard Workerif.else: ; preds = %entry 342*9880d681SAndroid Build Coastguard Worker %mul = shl nsw i32 %N, 1 343*9880d681SAndroid Build Coastguard Worker br label %if.end 344*9880d681SAndroid Build Coastguard Worker 345*9880d681SAndroid Build Coastguard Workerif.end: ; preds = %if.else, %for.end 346*9880d681SAndroid Build Coastguard Worker %sum.1 = phi i32 [ %shl, %for.end ], [ %mul, %if.else ] 347*9880d681SAndroid Build Coastguard Worker ret i32 %sum.1 348*9880d681SAndroid Build Coastguard Worker} 349*9880d681SAndroid Build Coastguard Worker 350*9880d681SAndroid Build Coastguard Worker; Check that we handle function with no frame information correctly. 351*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: emptyFrame: 352*9880d681SAndroid Build Coastguard Worker; CHECK: ## %entry 353*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: xorl %eax, %eax 354*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: retq 355*9880d681SAndroid Build Coastguard Workerdefine i32 @emptyFrame() { 356*9880d681SAndroid Build Coastguard Workerentry: 357*9880d681SAndroid Build Coastguard Worker ret i32 0 358*9880d681SAndroid Build Coastguard Worker} 359*9880d681SAndroid Build Coastguard Worker 360*9880d681SAndroid Build Coastguard Worker; Check that we handle inline asm correctly. 361*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: inlineAsm: 362*9880d681SAndroid Build Coastguard Worker; 363*9880d681SAndroid Build Coastguard Worker; ENABLE: testl %edi, %edi 364*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: je [[ELSE_LABEL:LBB[0-9_]+]] 365*9880d681SAndroid Build Coastguard Worker; 366*9880d681SAndroid Build Coastguard Worker; Prologue code. 367*9880d681SAndroid Build Coastguard Worker; Make sure we save the CSR used in the inline asm: rbx. 368*9880d681SAndroid Build Coastguard Worker; CHECK: pushq %rbx 369*9880d681SAndroid Build Coastguard Worker; 370*9880d681SAndroid Build Coastguard Worker; DISABLE: testl %edi, %edi 371*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: je [[ELSE_LABEL:LBB[0-9_]+]] 372*9880d681SAndroid Build Coastguard Worker; 373*9880d681SAndroid Build Coastguard Worker; CHECK: nop 374*9880d681SAndroid Build Coastguard Worker; CHECK: movl $10, [[IV:%e[a-z]+]] 375*9880d681SAndroid Build Coastguard Worker; 376*9880d681SAndroid Build Coastguard Worker; CHECK: [[LOOP_LABEL:LBB[0-9_]+]]: ## %for.body 377*9880d681SAndroid Build Coastguard Worker; Inline asm statement. 378*9880d681SAndroid Build Coastguard Worker; CHECK: addl $1, %ebx 379*9880d681SAndroid Build Coastguard Worker; CHECK: decl [[IV]] 380*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: jne [[LOOP_LABEL]] 381*9880d681SAndroid Build Coastguard Worker; Next BB. 382*9880d681SAndroid Build Coastguard Worker; CHECK: nop 383*9880d681SAndroid Build Coastguard Worker; CHECK: xorl %esi, %esi 384*9880d681SAndroid Build Coastguard Worker; 385*9880d681SAndroid Build Coastguard Worker; DISABLE: jmp [[EPILOG_BB:LBB[0-9_]+]] 386*9880d681SAndroid Build Coastguard Worker; 387*9880d681SAndroid Build Coastguard Worker; DISABLE: [[ELSE_LABEL]]: ## %if.else 388*9880d681SAndroid Build Coastguard Worker; Shift second argument by one and store into returned register. 389*9880d681SAndroid Build Coastguard Worker; DISABLE: addl %esi, %esi 390*9880d681SAndroid Build Coastguard Worker; DISABLE: [[EPILOG_BB]]: ## %if.end 391*9880d681SAndroid Build Coastguard Worker; 392*9880d681SAndroid Build Coastguard Worker; Epilogue code. 393*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: popq %rbx 394*9880d681SAndroid Build Coastguard Worker; CHECK-DAG: movl %esi, %eax 395*9880d681SAndroid Build Coastguard Worker; CHECK: retq 396*9880d681SAndroid Build Coastguard Worker; 397*9880d681SAndroid Build Coastguard Worker; ENABLE: [[ELSE_LABEL]]: ## %if.else 398*9880d681SAndroid Build Coastguard Worker; Shift second argument by one and store into returned register. 399*9880d681SAndroid Build Coastguard Worker; ENABLE: addl %esi, %esi 400*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: movl %esi, %eax 401*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: retq 402*9880d681SAndroid Build Coastguard Workerdefine i32 @inlineAsm(i32 %cond, i32 %N) { 403*9880d681SAndroid Build Coastguard Workerentry: 404*9880d681SAndroid Build Coastguard Worker %tobool = icmp eq i32 %cond, 0 405*9880d681SAndroid Build Coastguard Worker br i1 %tobool, label %if.else, label %for.preheader 406*9880d681SAndroid Build Coastguard Worker 407*9880d681SAndroid Build Coastguard Workerfor.preheader: 408*9880d681SAndroid Build Coastguard Worker tail call void asm "nop", ""() 409*9880d681SAndroid Build Coastguard Worker br label %for.body 410*9880d681SAndroid Build Coastguard Worker 411*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %entry, %for.body 412*9880d681SAndroid Build Coastguard Worker %i.03 = phi i32 [ %inc, %for.body ], [ 0, %for.preheader ] 413*9880d681SAndroid Build Coastguard Worker tail call void asm "addl $$1, %ebx", "~{ebx}"() 414*9880d681SAndroid Build Coastguard Worker %inc = add nuw nsw i32 %i.03, 1 415*9880d681SAndroid Build Coastguard Worker %exitcond = icmp eq i32 %inc, 10 416*9880d681SAndroid Build Coastguard Worker br i1 %exitcond, label %for.exit, label %for.body 417*9880d681SAndroid Build Coastguard Worker 418*9880d681SAndroid Build Coastguard Workerfor.exit: 419*9880d681SAndroid Build Coastguard Worker tail call void asm "nop", ""() 420*9880d681SAndroid Build Coastguard Worker br label %if.end 421*9880d681SAndroid Build Coastguard Worker 422*9880d681SAndroid Build Coastguard Workerif.else: ; preds = %entry 423*9880d681SAndroid Build Coastguard Worker %mul = shl nsw i32 %N, 1 424*9880d681SAndroid Build Coastguard Worker br label %if.end 425*9880d681SAndroid Build Coastguard Worker 426*9880d681SAndroid Build Coastguard Workerif.end: ; preds = %for.body, %if.else 427*9880d681SAndroid Build Coastguard Worker %sum.0 = phi i32 [ %mul, %if.else ], [ 0, %for.exit ] 428*9880d681SAndroid Build Coastguard Worker ret i32 %sum.0 429*9880d681SAndroid Build Coastguard Worker} 430*9880d681SAndroid Build Coastguard Worker 431*9880d681SAndroid Build Coastguard Worker; Check that we handle calls to variadic functions correctly. 432*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: callVariadicFunc: 433*9880d681SAndroid Build Coastguard Worker; 434*9880d681SAndroid Build Coastguard Worker; ENABLE: testl %edi, %edi 435*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: je [[ELSE_LABEL:LBB[0-9_]+]] 436*9880d681SAndroid Build Coastguard Worker; 437*9880d681SAndroid Build Coastguard Worker; Prologue code. 438*9880d681SAndroid Build Coastguard Worker; CHECK: pushq 439*9880d681SAndroid Build Coastguard Worker; 440*9880d681SAndroid Build Coastguard Worker; DISABLE: testl %edi, %edi 441*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: je [[ELSE_LABEL:LBB[0-9_]+]] 442*9880d681SAndroid Build Coastguard Worker; 443*9880d681SAndroid Build Coastguard Worker; Setup of the varags. 444*9880d681SAndroid Build Coastguard Worker; CHECK: movl %esi, (%rsp) 445*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: xorl %eax, %eax 446*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %esi, %edi 447*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %esi, %edx 448*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %esi, %ecx 449*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %esi, %r8d 450*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: %esi, %r9d 451*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: callq _someVariadicFunc 452*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movl %eax, %esi 453*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: shll $3, %esi 454*9880d681SAndroid Build Coastguard Worker; 455*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: addq $8, %rsp 456*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: movl %esi, %eax 457*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: retq 458*9880d681SAndroid Build Coastguard Worker; 459*9880d681SAndroid Build Coastguard Worker; DISABLE: jmp [[IFEND_LABEL:LBB[0-9_]+]] 460*9880d681SAndroid Build Coastguard Worker; 461*9880d681SAndroid Build Coastguard Worker; CHECK: [[ELSE_LABEL]]: ## %if.else 462*9880d681SAndroid Build Coastguard Worker; Shift second argument by one and store into returned register. 463*9880d681SAndroid Build Coastguard Worker; CHECK: addl %esi, %esi 464*9880d681SAndroid Build Coastguard Worker; 465*9880d681SAndroid Build Coastguard Worker; DISABLE: [[IFEND_LABEL]]: ## %if.end 466*9880d681SAndroid Build Coastguard Worker; 467*9880d681SAndroid Build Coastguard Worker; Epilogue code. 468*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movl %esi, %eax 469*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: popq 470*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: retq 471*9880d681SAndroid Build Coastguard Workerdefine i32 @callVariadicFunc(i32 %cond, i32 %N) { 472*9880d681SAndroid Build Coastguard Workerentry: 473*9880d681SAndroid Build Coastguard Worker %tobool = icmp eq i32 %cond, 0 474*9880d681SAndroid Build Coastguard Worker br i1 %tobool, label %if.else, label %if.then 475*9880d681SAndroid Build Coastguard Worker 476*9880d681SAndroid Build Coastguard Workerif.then: ; preds = %entry 477*9880d681SAndroid Build Coastguard Worker %call = tail call i32 (i32, ...) @someVariadicFunc(i32 %N, i32 %N, i32 %N, i32 %N, i32 %N, i32 %N, i32 %N) 478*9880d681SAndroid Build Coastguard Worker %shl = shl i32 %call, 3 479*9880d681SAndroid Build Coastguard Worker br label %if.end 480*9880d681SAndroid Build Coastguard Worker 481*9880d681SAndroid Build Coastguard Workerif.else: ; preds = %entry 482*9880d681SAndroid Build Coastguard Worker %mul = shl nsw i32 %N, 1 483*9880d681SAndroid Build Coastguard Worker br label %if.end 484*9880d681SAndroid Build Coastguard Worker 485*9880d681SAndroid Build Coastguard Workerif.end: ; preds = %if.else, %if.then 486*9880d681SAndroid Build Coastguard Worker %sum.0 = phi i32 [ %shl, %if.then ], [ %mul, %if.else ] 487*9880d681SAndroid Build Coastguard Worker ret i32 %sum.0 488*9880d681SAndroid Build Coastguard Worker} 489*9880d681SAndroid Build Coastguard Worker 490*9880d681SAndroid Build Coastguard Workerdeclare i32 @someVariadicFunc(i32, ...) 491*9880d681SAndroid Build Coastguard Worker 492*9880d681SAndroid Build Coastguard Worker; Check that we use LEA not to clobber EFLAGS. 493*9880d681SAndroid Build Coastguard Worker%struct.temp_slot = type { %struct.temp_slot*, %struct.rtx_def*, %struct.rtx_def*, i32, i64, %union.tree_node*, %union.tree_node*, i8, i8, i32, i32, i64, i64 } 494*9880d681SAndroid Build Coastguard Worker%union.tree_node = type { %struct.tree_decl } 495*9880d681SAndroid Build Coastguard Worker%struct.tree_decl = type { %struct.tree_common, i8*, i32, i32, %union.tree_node*, i48, %union.anon, %union.tree_node*, %union.tree_node*, %union.tree_node*, %union.tree_node*, %union.tree_node*, %union.tree_node*, %union.tree_node*, %union.tree_node*, %union.tree_node*, %union.tree_node*, %struct.rtx_def*, %struct.rtx_def*, %union.anon.1, %union.tree_node*, %union.tree_node*, %union.tree_node*, i64, %struct.lang_decl* } 496*9880d681SAndroid Build Coastguard Worker%struct.tree_common = type { %union.tree_node*, %union.tree_node*, i32 } 497*9880d681SAndroid Build Coastguard Worker%union.anon = type { i64 } 498*9880d681SAndroid Build Coastguard Worker%union.anon.1 = type { %struct.function* } 499*9880d681SAndroid Build Coastguard Worker%struct.function = type { %struct.eh_status*, %struct.stmt_status*, %struct.expr_status*, %struct.emit_status*, %struct.varasm_status*, i8*, %union.tree_node*, %struct.function*, i32, i32, i32, i32, %struct.rtx_def*, %struct.ix86_args, %struct.rtx_def*, %struct.rtx_def*, i8*, %struct.initial_value_struct*, i32, %union.tree_node*, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def*, %union.tree_node*, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def*, i64, %union.tree_node*, %union.tree_node*, %struct.rtx_def*, %struct.rtx_def*, i32, %struct.rtx_def**, %struct.temp_slot*, i32, i32, i32, %struct.var_refs_queue*, i32, i32, i8*, %union.tree_node*, %struct.rtx_def*, i32, i32, %struct.machine_function*, i32, i32, %struct.language_function*, %struct.rtx_def*, i24 } 500*9880d681SAndroid Build Coastguard Worker%struct.eh_status = type opaque 501*9880d681SAndroid Build Coastguard Worker%struct.stmt_status = type opaque 502*9880d681SAndroid Build Coastguard Worker%struct.expr_status = type { i32, i32, i32, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def*, %struct.rtx_def* } 503*9880d681SAndroid Build Coastguard Worker%struct.emit_status = type { i32, i32, %struct.rtx_def*, %struct.rtx_def*, %union.tree_node*, %struct.sequence_stack*, i32, i32, i8*, i32, i8*, %union.tree_node**, %struct.rtx_def** } 504*9880d681SAndroid Build Coastguard Worker%struct.sequence_stack = type { %struct.rtx_def*, %struct.rtx_def*, %union.tree_node*, %struct.sequence_stack* } 505*9880d681SAndroid Build Coastguard Worker%struct.varasm_status = type opaque 506*9880d681SAndroid Build Coastguard Worker%struct.ix86_args = type { i32, i32, i32, i32, i32, i32, i32 } 507*9880d681SAndroid Build Coastguard Worker%struct.initial_value_struct = type opaque 508*9880d681SAndroid Build Coastguard Worker%struct.var_refs_queue = type { %struct.rtx_def*, i32, i32, %struct.var_refs_queue* } 509*9880d681SAndroid Build Coastguard Worker%struct.machine_function = type opaque 510*9880d681SAndroid Build Coastguard Worker%struct.language_function = type opaque 511*9880d681SAndroid Build Coastguard Worker%struct.lang_decl = type opaque 512*9880d681SAndroid Build Coastguard Worker%struct.rtx_def = type { i32, [1 x %union.rtunion_def] } 513*9880d681SAndroid Build Coastguard Worker%union.rtunion_def = type { i64 } 514*9880d681SAndroid Build Coastguard Worker 515*9880d681SAndroid Build Coastguard Workerdeclare hidden fastcc %struct.temp_slot* @find_temp_slot_from_address(%struct.rtx_def* readonly) 516*9880d681SAndroid Build Coastguard Worker 517*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: useLEA: 518*9880d681SAndroid Build Coastguard Worker; DISABLE: pushq 519*9880d681SAndroid Build Coastguard Worker; 520*9880d681SAndroid Build Coastguard Worker; CHECK: testq %rdi, %rdi 521*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: je [[CLEANUP:LBB[0-9_]+]] 522*9880d681SAndroid Build Coastguard Worker; 523*9880d681SAndroid Build Coastguard Worker; CHECK: movzwl (%rdi), [[BF_LOAD:%e[a-z]+]] 524*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: cmpl $66, [[BF_LOAD]] 525*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: jne [[CLEANUP]] 526*9880d681SAndroid Build Coastguard Worker; 527*9880d681SAndroid Build Coastguard Worker; CHECK: movq 8(%rdi), %rdi 528*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movzwl (%rdi), %e[[BF_LOAD2:[a-z]+]] 529*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: leal -54(%r[[BF_LOAD2]]), [[TMP:%e[a-z]+]] 530*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: cmpl $14, [[TMP]] 531*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: ja [[LOR_LHS_FALSE:LBB[0-9_]+]] 532*9880d681SAndroid Build Coastguard Worker; 533*9880d681SAndroid Build Coastguard Worker; CHECK: movl $24599, [[TMP2:%e[a-z]+]] 534*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: btl [[TMP]], [[TMP2]] 535*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: jae [[LOR_LHS_FALSE:LBB[0-9_]+]] 536*9880d681SAndroid Build Coastguard Worker; 537*9880d681SAndroid Build Coastguard Worker; CHECK: [[CLEANUP]]: ## %cleanup 538*9880d681SAndroid Build Coastguard Worker; DISABLE: popq 539*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: retq 540*9880d681SAndroid Build Coastguard Worker; 541*9880d681SAndroid Build Coastguard Worker; CHECK: [[LOR_LHS_FALSE]]: ## %lor.lhs.false 542*9880d681SAndroid Build Coastguard Worker; CHECK: cmpl $134, %e[[BF_LOAD2]] 543*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: je [[CLEANUP]] 544*9880d681SAndroid Build Coastguard Worker; 545*9880d681SAndroid Build Coastguard Worker; CHECK: cmpl $140, %e[[BF_LOAD2]] 546*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: je [[CLEANUP]] 547*9880d681SAndroid Build Coastguard Worker; 548*9880d681SAndroid Build Coastguard Worker; ENABLE: pushq 549*9880d681SAndroid Build Coastguard Worker; CHECK: callq _find_temp_slot_from_address 550*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: testq %rax, %rax 551*9880d681SAndroid Build Coastguard Worker; 552*9880d681SAndroid Build Coastguard Worker; The adjustment must use LEA here (or be moved above the test). 553*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: leaq 8(%rsp), %rsp 554*9880d681SAndroid Build Coastguard Worker; 555*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: je [[CLEANUP]] 556*9880d681SAndroid Build Coastguard Worker; 557*9880d681SAndroid Build Coastguard Worker; CHECK: movb $1, 57(%rax) 558*9880d681SAndroid Build Coastguard Workerdefine void @useLEA(%struct.rtx_def* readonly %x) { 559*9880d681SAndroid Build Coastguard Workerentry: 560*9880d681SAndroid Build Coastguard Worker %cmp = icmp eq %struct.rtx_def* %x, null 561*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %cleanup, label %if.end 562*9880d681SAndroid Build Coastguard Worker 563*9880d681SAndroid Build Coastguard Workerif.end: ; preds = %entry 564*9880d681SAndroid Build Coastguard Worker %tmp = getelementptr inbounds %struct.rtx_def, %struct.rtx_def* %x, i64 0, i32 0 565*9880d681SAndroid Build Coastguard Worker %bf.load = load i32, i32* %tmp, align 8 566*9880d681SAndroid Build Coastguard Worker %bf.clear = and i32 %bf.load, 65535 567*9880d681SAndroid Build Coastguard Worker %cmp1 = icmp eq i32 %bf.clear, 66 568*9880d681SAndroid Build Coastguard Worker br i1 %cmp1, label %lor.lhs.false, label %cleanup 569*9880d681SAndroid Build Coastguard Worker 570*9880d681SAndroid Build Coastguard Workerlor.lhs.false: ; preds = %if.end 571*9880d681SAndroid Build Coastguard Worker %arrayidx = getelementptr inbounds %struct.rtx_def, %struct.rtx_def* %x, i64 0, i32 1, i64 0 572*9880d681SAndroid Build Coastguard Worker %rtx = bitcast %union.rtunion_def* %arrayidx to %struct.rtx_def** 573*9880d681SAndroid Build Coastguard Worker %tmp1 = load %struct.rtx_def*, %struct.rtx_def** %rtx, align 8 574*9880d681SAndroid Build Coastguard Worker %tmp2 = getelementptr inbounds %struct.rtx_def, %struct.rtx_def* %tmp1, i64 0, i32 0 575*9880d681SAndroid Build Coastguard Worker %bf.load2 = load i32, i32* %tmp2, align 8 576*9880d681SAndroid Build Coastguard Worker %bf.clear3 = and i32 %bf.load2, 65535 577*9880d681SAndroid Build Coastguard Worker switch i32 %bf.clear3, label %if.end.55 [ 578*9880d681SAndroid Build Coastguard Worker i32 67, label %cleanup 579*9880d681SAndroid Build Coastguard Worker i32 68, label %cleanup 580*9880d681SAndroid Build Coastguard Worker i32 54, label %cleanup 581*9880d681SAndroid Build Coastguard Worker i32 55, label %cleanup 582*9880d681SAndroid Build Coastguard Worker i32 58, label %cleanup 583*9880d681SAndroid Build Coastguard Worker i32 134, label %cleanup 584*9880d681SAndroid Build Coastguard Worker i32 56, label %cleanup 585*9880d681SAndroid Build Coastguard Worker i32 140, label %cleanup 586*9880d681SAndroid Build Coastguard Worker ] 587*9880d681SAndroid Build Coastguard Worker 588*9880d681SAndroid Build Coastguard Workerif.end.55: ; preds = %lor.lhs.false 589*9880d681SAndroid Build Coastguard Worker %call = tail call fastcc %struct.temp_slot* @find_temp_slot_from_address(%struct.rtx_def* %tmp1) #2 590*9880d681SAndroid Build Coastguard Worker %cmp59 = icmp eq %struct.temp_slot* %call, null 591*9880d681SAndroid Build Coastguard Worker br i1 %cmp59, label %cleanup, label %if.then.60 592*9880d681SAndroid Build Coastguard Worker 593*9880d681SAndroid Build Coastguard Workerif.then.60: ; preds = %if.end.55 594*9880d681SAndroid Build Coastguard Worker %addr_taken = getelementptr inbounds %struct.temp_slot, %struct.temp_slot* %call, i64 0, i32 8 595*9880d681SAndroid Build Coastguard Worker store i8 1, i8* %addr_taken, align 1 596*9880d681SAndroid Build Coastguard Worker br label %cleanup 597*9880d681SAndroid Build Coastguard Worker 598*9880d681SAndroid Build Coastguard Workercleanup: ; preds = %if.then.60, %if.end.55, %lor.lhs.false, %lor.lhs.false, %lor.lhs.false, %lor.lhs.false, %lor.lhs.false, %lor.lhs.false, %lor.lhs.false, %lor.lhs.false, %if.end, %entry 599*9880d681SAndroid Build Coastguard Worker ret void 600*9880d681SAndroid Build Coastguard Worker} 601*9880d681SAndroid Build Coastguard Worker 602*9880d681SAndroid Build Coastguard Worker; Make sure we do not insert unreachable code after noreturn function. 603*9880d681SAndroid Build Coastguard Worker; Although this is not incorrect to insert such code, it is useless 604*9880d681SAndroid Build Coastguard Worker; and it hurts the binary size. 605*9880d681SAndroid Build Coastguard Worker; 606*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: noreturn: 607*9880d681SAndroid Build Coastguard Worker; DISABLE: pushq 608*9880d681SAndroid Build Coastguard Worker; 609*9880d681SAndroid Build Coastguard Worker; CHECK: testb %dil, %dil 610*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: jne [[ABORT:LBB[0-9_]+]] 611*9880d681SAndroid Build Coastguard Worker; 612*9880d681SAndroid Build Coastguard Worker; CHECK: movl $42, %eax 613*9880d681SAndroid Build Coastguard Worker; 614*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: popq 615*9880d681SAndroid Build Coastguard Worker; 616*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: retq 617*9880d681SAndroid Build Coastguard Worker; 618*9880d681SAndroid Build Coastguard Worker; CHECK: [[ABORT]]: ## %if.abort 619*9880d681SAndroid Build Coastguard Worker; 620*9880d681SAndroid Build Coastguard Worker; ENABLE: pushq 621*9880d681SAndroid Build Coastguard Worker; 622*9880d681SAndroid Build Coastguard Worker; CHECK: callq _abort 623*9880d681SAndroid Build Coastguard Worker; ENABLE-NOT: popq 624*9880d681SAndroid Build Coastguard Workerdefine i32 @noreturn(i8 signext %bad_thing) { 625*9880d681SAndroid Build Coastguard Workerentry: 626*9880d681SAndroid Build Coastguard Worker %tobool = icmp eq i8 %bad_thing, 0 627*9880d681SAndroid Build Coastguard Worker br i1 %tobool, label %if.end, label %if.abort 628*9880d681SAndroid Build Coastguard Worker 629*9880d681SAndroid Build Coastguard Workerif.abort: 630*9880d681SAndroid Build Coastguard Worker tail call void @abort() #0 631*9880d681SAndroid Build Coastguard Worker unreachable 632*9880d681SAndroid Build Coastguard Worker 633*9880d681SAndroid Build Coastguard Workerif.end: 634*9880d681SAndroid Build Coastguard Worker ret i32 42 635*9880d681SAndroid Build Coastguard Worker} 636*9880d681SAndroid Build Coastguard Worker 637*9880d681SAndroid Build Coastguard Workerdeclare void @abort() #0 638*9880d681SAndroid Build Coastguard Worker 639*9880d681SAndroid Build Coastguard Workerattributes #0 = { noreturn nounwind } 640*9880d681SAndroid Build Coastguard Worker 641*9880d681SAndroid Build Coastguard Worker 642*9880d681SAndroid Build Coastguard Worker; Make sure that we handle infinite loops properly When checking that the Save 643*9880d681SAndroid Build Coastguard Worker; and Restore blocks are control flow equivalent, the loop searches for the 644*9880d681SAndroid Build Coastguard Worker; immediate (post) dominator for the (restore) save blocks. When either the Save 645*9880d681SAndroid Build Coastguard Worker; or Restore block is located in an infinite loop the only immediate (post) 646*9880d681SAndroid Build Coastguard Worker; dominator is itself. In this case, we cannot perform shrink wrapping, but we 647*9880d681SAndroid Build Coastguard Worker; should return gracefully and continue compilation. 648*9880d681SAndroid Build Coastguard Worker; The only condition for this test is the compilation finishes correctly. 649*9880d681SAndroid Build Coastguard Worker; 650*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: infiniteloop 651*9880d681SAndroid Build Coastguard Worker; CHECK: retq 652*9880d681SAndroid Build Coastguard Workerdefine void @infiniteloop() { 653*9880d681SAndroid Build Coastguard Workerentry: 654*9880d681SAndroid Build Coastguard Worker br i1 undef, label %if.then, label %if.end 655*9880d681SAndroid Build Coastguard Worker 656*9880d681SAndroid Build Coastguard Workerif.then: 657*9880d681SAndroid Build Coastguard Worker %ptr = alloca i32, i32 4 658*9880d681SAndroid Build Coastguard Worker br label %for.body 659*9880d681SAndroid Build Coastguard Worker 660*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %for.body, %entry 661*9880d681SAndroid Build Coastguard Worker %sum.03 = phi i32 [ 0, %if.then ], [ %add, %for.body ] 662*9880d681SAndroid Build Coastguard Worker %call = tail call i32 asm "movl $$1, $0", "=r,~{ebx}"() 663*9880d681SAndroid Build Coastguard Worker %add = add nsw i32 %call, %sum.03 664*9880d681SAndroid Build Coastguard Worker store i32 %add, i32* %ptr 665*9880d681SAndroid Build Coastguard Worker br label %for.body 666*9880d681SAndroid Build Coastguard Worker 667*9880d681SAndroid Build Coastguard Workerif.end: 668*9880d681SAndroid Build Coastguard Worker ret void 669*9880d681SAndroid Build Coastguard Worker} 670*9880d681SAndroid Build Coastguard Worker 671*9880d681SAndroid Build Coastguard Worker; Another infinite loop test this time with a body bigger than just one block. 672*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: infiniteloop2 673*9880d681SAndroid Build Coastguard Worker; CHECK: retq 674*9880d681SAndroid Build Coastguard Workerdefine void @infiniteloop2() { 675*9880d681SAndroid Build Coastguard Workerentry: 676*9880d681SAndroid Build Coastguard Worker br i1 undef, label %if.then, label %if.end 677*9880d681SAndroid Build Coastguard Worker 678*9880d681SAndroid Build Coastguard Workerif.then: 679*9880d681SAndroid Build Coastguard Worker %ptr = alloca i32, i32 4 680*9880d681SAndroid Build Coastguard Worker br label %for.body 681*9880d681SAndroid Build Coastguard Worker 682*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %for.body, %entry 683*9880d681SAndroid Build Coastguard Worker %sum.03 = phi i32 [ 0, %if.then ], [ %add, %body1 ], [ 1, %body2] 684*9880d681SAndroid Build Coastguard Worker %call = tail call i32 asm "movl $$1, $0", "=r,~{ebx}"() 685*9880d681SAndroid Build Coastguard Worker %add = add nsw i32 %call, %sum.03 686*9880d681SAndroid Build Coastguard Worker store i32 %add, i32* %ptr 687*9880d681SAndroid Build Coastguard Worker br i1 undef, label %body1, label %body2 688*9880d681SAndroid Build Coastguard Worker 689*9880d681SAndroid Build Coastguard Workerbody1: 690*9880d681SAndroid Build Coastguard Worker tail call void asm sideeffect "nop", "~{ebx}"() 691*9880d681SAndroid Build Coastguard Worker br label %for.body 692*9880d681SAndroid Build Coastguard Worker 693*9880d681SAndroid Build Coastguard Workerbody2: 694*9880d681SAndroid Build Coastguard Worker tail call void asm sideeffect "nop", "~{ebx}"() 695*9880d681SAndroid Build Coastguard Worker br label %for.body 696*9880d681SAndroid Build Coastguard Worker 697*9880d681SAndroid Build Coastguard Workerif.end: 698*9880d681SAndroid Build Coastguard Worker ret void 699*9880d681SAndroid Build Coastguard Worker} 700*9880d681SAndroid Build Coastguard Worker 701*9880d681SAndroid Build Coastguard Worker; Another infinite loop test this time with two nested infinite loop. 702*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: infiniteloop3 703*9880d681SAndroid Build Coastguard Worker; CHECK: retq 704*9880d681SAndroid Build Coastguard Workerdefine void @infiniteloop3() { 705*9880d681SAndroid Build Coastguard Workerentry: 706*9880d681SAndroid Build Coastguard Worker br i1 undef, label %loop2a, label %body 707*9880d681SAndroid Build Coastguard Worker 708*9880d681SAndroid Build Coastguard Workerbody: ; preds = %entry 709*9880d681SAndroid Build Coastguard Worker br i1 undef, label %loop2a, label %end 710*9880d681SAndroid Build Coastguard Worker 711*9880d681SAndroid Build Coastguard Workerloop1: ; preds = %loop2a, %loop2b 712*9880d681SAndroid Build Coastguard Worker %var.phi = phi i32* [ %next.phi, %loop2b ], [ %var, %loop2a ] 713*9880d681SAndroid Build Coastguard Worker %next.phi = phi i32* [ %next.load, %loop2b ], [ %next.var, %loop2a ] 714*9880d681SAndroid Build Coastguard Worker %0 = icmp eq i32* %var, null 715*9880d681SAndroid Build Coastguard Worker %next.load = load i32*, i32** undef 716*9880d681SAndroid Build Coastguard Worker br i1 %0, label %loop2a, label %loop2b 717*9880d681SAndroid Build Coastguard Worker 718*9880d681SAndroid Build Coastguard Workerloop2a: ; preds = %loop1, %body, %entry 719*9880d681SAndroid Build Coastguard Worker %var = phi i32* [ null, %body ], [ null, %entry ], [ %next.phi, %loop1 ] 720*9880d681SAndroid Build Coastguard Worker %next.var = phi i32* [ undef, %body ], [ null, %entry ], [ %next.load, %loop1 ] 721*9880d681SAndroid Build Coastguard Worker br label %loop1 722*9880d681SAndroid Build Coastguard Worker 723*9880d681SAndroid Build Coastguard Workerloop2b: ; preds = %loop1 724*9880d681SAndroid Build Coastguard Worker %gep1 = bitcast i32* %var.phi to i32* 725*9880d681SAndroid Build Coastguard Worker %next.ptr = bitcast i32* %gep1 to i32** 726*9880d681SAndroid Build Coastguard Worker store i32* %next.phi, i32** %next.ptr 727*9880d681SAndroid Build Coastguard Worker br label %loop1 728*9880d681SAndroid Build Coastguard Worker 729*9880d681SAndroid Build Coastguard Workerend: 730*9880d681SAndroid Build Coastguard Worker ret void 731*9880d681SAndroid Build Coastguard Worker} 732*9880d681SAndroid Build Coastguard Worker 733*9880d681SAndroid Build Coastguard Worker; Check that we just don't bail out on RegMask. 734*9880d681SAndroid Build Coastguard Worker; In this case, the RegMask does not touch a CSR so we are good to go! 735*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: regmask: 736*9880d681SAndroid Build Coastguard Worker; 737*9880d681SAndroid Build Coastguard Worker; Compare the arguments and jump to exit. 738*9880d681SAndroid Build Coastguard Worker; No prologue needed. 739*9880d681SAndroid Build Coastguard Worker; ENABLE: cmpl %esi, %edi 740*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: jge [[EXIT_LABEL:LBB[0-9_]+]] 741*9880d681SAndroid Build Coastguard Worker; 742*9880d681SAndroid Build Coastguard Worker; Prologue code. 743*9880d681SAndroid Build Coastguard Worker; (What we push does not matter. It should be some random sratch register.) 744*9880d681SAndroid Build Coastguard Worker; CHECK: pushq 745*9880d681SAndroid Build Coastguard Worker; 746*9880d681SAndroid Build Coastguard Worker; Compare the arguments and jump to exit. 747*9880d681SAndroid Build Coastguard Worker; After the prologue is set. 748*9880d681SAndroid Build Coastguard Worker; DISABLE: cmpl %esi, %edi 749*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: jge [[EXIT_LABEL:LBB[0-9_]+]] 750*9880d681SAndroid Build Coastguard Worker; 751*9880d681SAndroid Build Coastguard Worker; CHECK: nop 752*9880d681SAndroid Build Coastguard Worker; Set the first argument to zero. 753*9880d681SAndroid Build Coastguard Worker; CHECK: xorl %edi, %edi 754*9880d681SAndroid Build Coastguard Worker; Set the second argument to addr. 755*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movq %rdx, %rsi 756*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: callq _doSomething 757*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: popq 758*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: retq 759*9880d681SAndroid Build Coastguard Worker; 760*9880d681SAndroid Build Coastguard Worker; CHECK: [[EXIT_LABEL]]: 761*9880d681SAndroid Build Coastguard Worker; Set the first argument to 6. 762*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movl $6, %edi 763*9880d681SAndroid Build Coastguard Worker; Set the second argument to addr. 764*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movq %rdx, %rsi 765*9880d681SAndroid Build Coastguard Worker; 766*9880d681SAndroid Build Coastguard Worker; Without shrink-wrapping, we need to restore the stack before 767*9880d681SAndroid Build Coastguard Worker; making the tail call. 768*9880d681SAndroid Build Coastguard Worker; Epilogue code. 769*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: popq 770*9880d681SAndroid Build Coastguard Worker; 771*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: jmp _doSomething 772*9880d681SAndroid Build Coastguard Workerdefine i32 @regmask(i32 %a, i32 %b, i32* %addr) { 773*9880d681SAndroid Build Coastguard Worker %tmp2 = icmp slt i32 %a, %b 774*9880d681SAndroid Build Coastguard Worker br i1 %tmp2, label %true, label %false 775*9880d681SAndroid Build Coastguard Worker 776*9880d681SAndroid Build Coastguard Workertrue: 777*9880d681SAndroid Build Coastguard Worker ; Clobber a CSR so that we check something on the regmask 778*9880d681SAndroid Build Coastguard Worker ; of the tail call. 779*9880d681SAndroid Build Coastguard Worker tail call void asm sideeffect "nop", "~{ebx}"() 780*9880d681SAndroid Build Coastguard Worker %tmp4 = call i32 @doSomething(i32 0, i32* %addr) 781*9880d681SAndroid Build Coastguard Worker br label %end 782*9880d681SAndroid Build Coastguard Worker 783*9880d681SAndroid Build Coastguard Workerfalse: 784*9880d681SAndroid Build Coastguard Worker %tmp5 = tail call i32 @doSomething(i32 6, i32* %addr) 785*9880d681SAndroid Build Coastguard Worker br label %end 786*9880d681SAndroid Build Coastguard Worker 787*9880d681SAndroid Build Coastguard Workerend: 788*9880d681SAndroid Build Coastguard Worker %tmp.0 = phi i32 [ %tmp4, %true ], [ %tmp5, %false ] 789*9880d681SAndroid Build Coastguard Worker ret i32 %tmp.0 790*9880d681SAndroid Build Coastguard Worker} 791*9880d681SAndroid Build Coastguard Worker 792*9880d681SAndroid Build Coastguard Worker@b = internal unnamed_addr global i1 false 793*9880d681SAndroid Build Coastguard Worker@c = internal unnamed_addr global i8 0, align 1 794*9880d681SAndroid Build Coastguard Worker@a = common global i32 0, align 4 795*9880d681SAndroid Build Coastguard Worker 796*9880d681SAndroid Build Coastguard Worker; Make sure the prologue does not clobber the EFLAGS when 797*9880d681SAndroid Build Coastguard Worker; it is live accross. 798*9880d681SAndroid Build Coastguard Worker; PR25629. 799*9880d681SAndroid Build Coastguard Worker; Note: The registers may change in the following patterns, but 800*9880d681SAndroid Build Coastguard Worker; because they imply register hierarchy (e.g., eax, al) this is 801*9880d681SAndroid Build Coastguard Worker; tricky to write robust patterns. 802*9880d681SAndroid Build Coastguard Worker; 803*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: useLEAForPrologue: 804*9880d681SAndroid Build Coastguard Worker; 805*9880d681SAndroid Build Coastguard Worker; Prologue is at the beginning of the function when shrink-wrapping 806*9880d681SAndroid Build Coastguard Worker; is disabled. 807*9880d681SAndroid Build Coastguard Worker; DISABLE: pushq 808*9880d681SAndroid Build Coastguard Worker; The stack adjustment can use SUB instr because we do not need to 809*9880d681SAndroid Build Coastguard Worker; preserve the EFLAGS at this point. 810*9880d681SAndroid Build Coastguard Worker; DISABLE-NEXT: subq $16, %rsp 811*9880d681SAndroid Build Coastguard Worker; 812*9880d681SAndroid Build Coastguard Worker; Load the value of b. 813*9880d681SAndroid Build Coastguard Worker; CHECK: movb _b(%rip), [[BOOL:%cl]] 814*9880d681SAndroid Build Coastguard Worker; Create the zero value for the select assignment. 815*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: xorl [[CMOVE_VAL:%eax]], [[CMOVE_VAL]] 816*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: testb [[BOOL]], [[BOOL]] 817*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: jne [[STOREC_LABEL:LBB[0-9_]+]] 818*9880d681SAndroid Build Coastguard Worker; 819*9880d681SAndroid Build Coastguard Worker; CHECK: movb $48, [[CMOVE_VAL:%al]] 820*9880d681SAndroid Build Coastguard Worker; 821*9880d681SAndroid Build Coastguard Worker; CHECK: [[STOREC_LABEL]]: 822*9880d681SAndroid Build Coastguard Worker; 823*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: pushq 824*9880d681SAndroid Build Coastguard Worker; For the stack adjustment, we need to preserve the EFLAGS. 825*9880d681SAndroid Build Coastguard Worker; ENABLE-NEXT: leaq -16(%rsp), %rsp 826*9880d681SAndroid Build Coastguard Worker; 827*9880d681SAndroid Build Coastguard Worker; Technically, we should use CMOVE_VAL here or its subregister. 828*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: movb %al, _c(%rip) 829*9880d681SAndroid Build Coastguard Worker; testb set the EFLAGS read here. 830*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: je [[VARFUNC_CALL:LBB[0-9_]+]] 831*9880d681SAndroid Build Coastguard Worker; 832*9880d681SAndroid Build Coastguard Worker; The code of the loop is not interesting. 833*9880d681SAndroid Build Coastguard Worker; [...] 834*9880d681SAndroid Build Coastguard Worker; 835*9880d681SAndroid Build Coastguard Worker; CHECK: [[VARFUNC_CALL]]: 836*9880d681SAndroid Build Coastguard Worker; Set the null parameter. 837*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: xorl %edi, %edi 838*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: callq _varfunc 839*9880d681SAndroid Build Coastguard Worker; 840*9880d681SAndroid Build Coastguard Worker; Set the return value. 841*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: xorl %eax, %eax 842*9880d681SAndroid Build Coastguard Worker; 843*9880d681SAndroid Build Coastguard Worker; Epilogue code. 844*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: addq $16, %rsp 845*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: popq 846*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: retq 847*9880d681SAndroid Build Coastguard Workerdefine i32 @useLEAForPrologue(i32 %d, i32 %a, i8 %c) #3 { 848*9880d681SAndroid Build Coastguard Workerentry: 849*9880d681SAndroid Build Coastguard Worker %tmp = alloca i3 850*9880d681SAndroid Build Coastguard Worker %.b = load i1, i1* @b, align 1 851*9880d681SAndroid Build Coastguard Worker %bool = select i1 %.b, i8 0, i8 48 852*9880d681SAndroid Build Coastguard Worker store i8 %bool, i8* @c, align 1 853*9880d681SAndroid Build Coastguard Worker br i1 %.b, label %for.body.lr.ph, label %for.end 854*9880d681SAndroid Build Coastguard Worker 855*9880d681SAndroid Build Coastguard Workerfor.body.lr.ph: ; preds = %entry 856*9880d681SAndroid Build Coastguard Worker tail call void asm sideeffect "nop", "~{ebx}"() 857*9880d681SAndroid Build Coastguard Worker br label %for.body 858*9880d681SAndroid Build Coastguard Worker 859*9880d681SAndroid Build Coastguard Workerfor.body: ; preds = %for.body.lr.ph, %for.body 860*9880d681SAndroid Build Coastguard Worker %inc6 = phi i8 [ %c, %for.body.lr.ph ], [ %inc, %for.body ] 861*9880d681SAndroid Build Coastguard Worker %cond5 = phi i32 [ %a, %for.body.lr.ph ], [ %conv3, %for.body ] 862*9880d681SAndroid Build Coastguard Worker %cmp2 = icmp slt i32 %d, %cond5 863*9880d681SAndroid Build Coastguard Worker %conv3 = zext i1 %cmp2 to i32 864*9880d681SAndroid Build Coastguard Worker %inc = add i8 %inc6, 1 865*9880d681SAndroid Build Coastguard Worker %cmp = icmp slt i8 %inc, 45 866*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge 867*9880d681SAndroid Build Coastguard Worker 868*9880d681SAndroid Build Coastguard Workerfor.cond.for.end_crit_edge: ; preds = %for.body 869*9880d681SAndroid Build Coastguard Worker store i32 %conv3, i32* @a, align 4 870*9880d681SAndroid Build Coastguard Worker br label %for.end 871*9880d681SAndroid Build Coastguard Worker 872*9880d681SAndroid Build Coastguard Workerfor.end: ; preds = %for.cond.for.end_crit_edge, %entry 873*9880d681SAndroid Build Coastguard Worker %call = tail call i32 (i8*) @varfunc(i8* null) 874*9880d681SAndroid Build Coastguard Worker ret i32 0 875*9880d681SAndroid Build Coastguard Worker} 876*9880d681SAndroid Build Coastguard Worker 877*9880d681SAndroid Build Coastguard Workerdeclare i32 @varfunc(i8* nocapture readonly) 878*9880d681SAndroid Build Coastguard Worker 879*9880d681SAndroid Build Coastguard Worker@sum1 = external hidden thread_local global i32, align 4 880*9880d681SAndroid Build Coastguard Worker 881*9880d681SAndroid Build Coastguard Worker 882*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind 883*9880d681SAndroid Build Coastguard Worker; Make sure the TLS call used to access @sum1 happens after the prologue 884*9880d681SAndroid Build Coastguard Worker; and before the epilogue. 885*9880d681SAndroid Build Coastguard Worker; TLS calls used to be wrongly model and shrink-wrapping would have inserted 886*9880d681SAndroid Build Coastguard Worker; the prologue and epilogue just around the call to doSomething. 887*9880d681SAndroid Build Coastguard Worker; PR25820. 888*9880d681SAndroid Build Coastguard Worker; 889*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: tlsCall: 890*9880d681SAndroid Build Coastguard Worker; CHECK: pushq 891*9880d681SAndroid Build Coastguard Worker; CHECK: testb $1, %dil 892*9880d681SAndroid Build Coastguard Worker; CHECK: je [[ELSE_LABEL:LBB[0-9_]+]] 893*9880d681SAndroid Build Coastguard Worker; 894*9880d681SAndroid Build Coastguard Worker; master bb 895*9880d681SAndroid Build Coastguard Worker; CHECK: movq _sum1@TLVP(%rip), %rdi 896*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: callq *(%rdi) 897*9880d681SAndroid Build Coastguard Worker; CHECK: jmp [[EXIT_LABEL:LBB[0-9_]+]] 898*9880d681SAndroid Build Coastguard Worker; 899*9880d681SAndroid Build Coastguard Worker; [[ELSE_LABEL]]: 900*9880d681SAndroid Build Coastguard Worker; CHECK: callq _doSomething 901*9880d681SAndroid Build Coastguard Worker; 902*9880d681SAndroid Build Coastguard Worker; [[EXIT_LABEL]]: 903*9880d681SAndroid Build Coastguard Worker; CHECK: popq 904*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: retq 905*9880d681SAndroid Build Coastguard Workerdefine i32 @tlsCall(i1 %bool1, i32 %arg, i32* readonly dereferenceable(4) %sum1) #3 { 906*9880d681SAndroid Build Coastguard Workerentry: 907*9880d681SAndroid Build Coastguard Worker br i1 %bool1, label %master, label %else 908*9880d681SAndroid Build Coastguard Worker 909*9880d681SAndroid Build Coastguard Workermaster: 910*9880d681SAndroid Build Coastguard Worker %tmp1 = load i32, i32* %sum1, align 4 911*9880d681SAndroid Build Coastguard Worker store i32 %tmp1, i32* @sum1, align 4 912*9880d681SAndroid Build Coastguard Worker br label %exit 913*9880d681SAndroid Build Coastguard Worker 914*9880d681SAndroid Build Coastguard Workerelse: 915*9880d681SAndroid Build Coastguard Worker %call = call i32 @doSomething(i32 0, i32* null) 916*9880d681SAndroid Build Coastguard Worker br label %exit 917*9880d681SAndroid Build Coastguard Worker 918*9880d681SAndroid Build Coastguard Workerexit: 919*9880d681SAndroid Build Coastguard Worker %res = phi i32 [ %arg, %master], [ %call, %else ] 920*9880d681SAndroid Build Coastguard Worker ret i32 %res 921*9880d681SAndroid Build Coastguard Worker} 922*9880d681SAndroid Build Coastguard Worker 923*9880d681SAndroid Build Coastguard Workerattributes #3 = { nounwind } 924*9880d681SAndroid Build Coastguard Worker 925*9880d681SAndroid Build Coastguard Worker@irreducibleCFGa = common global i32 0, align 4 926*9880d681SAndroid Build Coastguard Worker@irreducibleCFGf = common global i8 0, align 1 927*9880d681SAndroid Build Coastguard Worker@irreducibleCFGb = common global i32 0, align 4 928*9880d681SAndroid Build Coastguard Worker 929*9880d681SAndroid Build Coastguard Worker; Check that we do not run shrink-wrapping on irreducible CFGs until 930*9880d681SAndroid Build Coastguard Worker; it is actually supported. 931*9880d681SAndroid Build Coastguard Worker; At the moment, on those CFGs the loop information may be incorrect 932*9880d681SAndroid Build Coastguard Worker; and since we use that information to do the placement, we may end up 933*9880d681SAndroid Build Coastguard Worker; inserting the prologue/epilogue at incorrect places. 934*9880d681SAndroid Build Coastguard Worker; PR25988. 935*9880d681SAndroid Build Coastguard Worker; 936*9880d681SAndroid Build Coastguard Worker; CHECK-LABEL: irreducibleCFG: 937*9880d681SAndroid Build Coastguard Worker; CHECK: %entry 938*9880d681SAndroid Build Coastguard Worker; Make sure the prologue happens in the entry block. 939*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: pushq 940*9880d681SAndroid Build Coastguard Worker; ... 941*9880d681SAndroid Build Coastguard Worker; Make sure the epilogue happens in the exit block. 942*9880d681SAndroid Build Coastguard Worker; CHECK-NOT: popq 943*9880d681SAndroid Build Coastguard Worker; CHECK: popq 944*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: popq 945*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: retq 946*9880d681SAndroid Build Coastguard Workerdefine i32 @irreducibleCFG() #4 { 947*9880d681SAndroid Build Coastguard Workerentry: 948*9880d681SAndroid Build Coastguard Worker %i0 = load i32, i32* @irreducibleCFGa, align 4 949*9880d681SAndroid Build Coastguard Worker %.pr = load i8, i8* @irreducibleCFGf, align 1 950*9880d681SAndroid Build Coastguard Worker %bool = icmp eq i8 %.pr, 0 951*9880d681SAndroid Build Coastguard Worker br i1 %bool, label %split, label %preheader 952*9880d681SAndroid Build Coastguard Worker 953*9880d681SAndroid Build Coastguard Workerpreheader: 954*9880d681SAndroid Build Coastguard Worker br label %preheader 955*9880d681SAndroid Build Coastguard Worker 956*9880d681SAndroid Build Coastguard Workersplit: 957*9880d681SAndroid Build Coastguard Worker %i1 = load i32, i32* @irreducibleCFGb, align 4 958*9880d681SAndroid Build Coastguard Worker %tobool1.i = icmp ne i32 %i1, 0 959*9880d681SAndroid Build Coastguard Worker br i1 %tobool1.i, label %for.body4.i, label %for.cond8.i.preheader 960*9880d681SAndroid Build Coastguard Worker 961*9880d681SAndroid Build Coastguard Workerfor.body4.i: 962*9880d681SAndroid Build Coastguard Worker %call.i = tail call i32 (...) @something(i32 %i0) 963*9880d681SAndroid Build Coastguard Worker br label %for.cond8 964*9880d681SAndroid Build Coastguard Worker 965*9880d681SAndroid Build Coastguard Workerfor.cond8: 966*9880d681SAndroid Build Coastguard Worker %p1 = phi i32 [ %inc18.i, %for.inc ], [ 0, %for.body4.i ] 967*9880d681SAndroid Build Coastguard Worker %.pr1.pr = load i32, i32* @irreducibleCFGb, align 4 968*9880d681SAndroid Build Coastguard Worker br label %for.cond8.i.preheader 969*9880d681SAndroid Build Coastguard Worker 970*9880d681SAndroid Build Coastguard Workerfor.cond8.i.preheader: 971*9880d681SAndroid Build Coastguard Worker %.pr1 = phi i32 [ %.pr1.pr, %for.cond8 ], [ %i1, %split ] 972*9880d681SAndroid Build Coastguard Worker %p13 = phi i32 [ %p1, %for.cond8 ], [ 0, %split ] 973*9880d681SAndroid Build Coastguard Worker br label %for.inc 974*9880d681SAndroid Build Coastguard Worker 975*9880d681SAndroid Build Coastguard Workerfn1.exit: 976*9880d681SAndroid Build Coastguard Worker ret i32 0 977*9880d681SAndroid Build Coastguard Worker 978*9880d681SAndroid Build Coastguard Workerfor.inc: 979*9880d681SAndroid Build Coastguard Worker %inc18.i = add nuw nsw i32 %p13, 1 980*9880d681SAndroid Build Coastguard Worker %cmp = icmp slt i32 %inc18.i, 7 981*9880d681SAndroid Build Coastguard Worker br i1 %cmp, label %for.cond8, label %fn1.exit 982*9880d681SAndroid Build Coastguard Worker} 983*9880d681SAndroid Build Coastguard Worker 984*9880d681SAndroid Build Coastguard Workerattributes #4 = { "no-frame-pointer-elim"="true" } 985