File: sink-alloca.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (52 lines) | stat: -rw-r--r-- 1,631 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
; RUN: opt -instcombine -S < %s | FileCheck %s

target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
target triple = "i686-unknown-linux-gnu"

; Check that instcombine doesn't sink dynamic allocas across llvm.stacksave.

; Helper to generate branch conditions.
declare i1 @cond()

declare i32* @use_and_return(i32*)

declare i8* @llvm.stacksave() #0

declare void @llvm.stackrestore(i8*) #0

define void @foo(i32 %x) {
entry:
  %c1 = call i1 @cond()
  br i1 %c1, label %ret, label %nonentry

nonentry:                                         ; preds = %entry
  %argmem = alloca i32, i32 %x, align 4
  %sp = call i8* @llvm.stacksave()
  %c2 = call i1 @cond()
  br i1 %c2, label %ret, label %sinktarget

sinktarget:                                       ; preds = %nonentry
  ; Arrange for there to be a single use of %argmem by returning it.
  %p = call i32* @use_and_return(i32* nonnull %argmem)
  store i32 13, i32* %p, align 4
  call void @llvm.stackrestore(i8* %sp)
  %0 = call i32* @use_and_return(i32* %p)
  br label %ret

ret:                                              ; preds = %sinktarget, %nonentry, %entry
  ret void
}

; CHECK-LABEL: define void @foo(i32 %x)
; CHECK: nonentry:
; CHECK:   %argmem = alloca i32, i32 %x
; CHECK:   %sp = call i8* @llvm.stacksave()
; CHECK:   %c2 = call i1 @cond()
; CHECK:   br i1 %c2, label %ret, label %sinktarget
; CHECK: sinktarget:
; CHECK:   %p = call i32* @use_and_return(i32* nonnull %argmem)
; CHECK:   store i32 13, i32* %p
; CHECK:   call void @llvm.stackrestore(i8* %sp)
; CHECK:   %0 = call i32* @use_and_return(i32* nonnull %p)

attributes #0 = { nounwind }