1 ; RUN: opt -instcombine -S < %s | FileCheck %s
3 target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
4 target triple = "i686-unknown-linux-gnu"
6 ; Check that instcombine doesn't sink dynamic allocas across llvm.stacksave.
8 ; Helper to generate branch conditions.
11 declare i32* @use_and_return(i32*)
13 declare i8* @llvm.stacksave() #0
15 declare void @llvm.stackrestore(i8*) #0
17 define void @foo(i32 %x) {
20 br i1 %c1, label %ret, label %nonentry
22 nonentry: ; preds = %entry
23 %argmem = alloca i32, i32 %x, align 4
24 %sp = call i8* @llvm.stacksave()
26 br i1 %c2, label %ret, label %sinktarget
28 sinktarget: ; preds = %nonentry
29 ; Arrange for there to be a single use of %argmem by returning it.
30 %p = call i32* @use_and_return(i32* nonnull %argmem)
31 store i32 13, i32* %p, align 4
32 call void @llvm.stackrestore(i8* %sp)
33 %0 = call i32* @use_and_return(i32* %p)
36 ret: ; preds = %sinktarget, %nonentry, %entry
40 ; CHECK-LABEL: define void @foo(i32 %x)
42 ; CHECK: %argmem = alloca i32, i32 %x
43 ; CHECK: %sp = call i8* @llvm.stacksave()
44 ; CHECK: %c2 = call i1 @cond()
45 ; CHECK: br i1 %c2, label %ret, label %sinktarget
47 ; CHECK: %p = call i32* @use_and_return(i32* nonnull %argmem)
48 ; CHECK: store i32 13, i32* %p
49 ; CHECK: call void @llvm.stackrestore(i8* %sp)
50 ; CHECK: %0 = call i32* @use_and_return(i32* %p)
52 attributes #0 = { nounwind }