File: hoist-pr28606.ll

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (57 lines) | stat: -rw-r--r-- 2,053 bytes parent folder | download | duplicates (4)
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
53
54
55
56
57
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=gvn-hoist -S < %s | FileCheck %s

target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
target triple = "i686-pc-windows-msvc18.0.0"

%struct.S = type { ptr, ptr }

declare void @f(ptr inalloca(<{ %struct.S }>))


; Check that we don't clone the %x alloca and insert it in the live range of
; %argmem, which would break the inalloca contract.
define void @test(i1 %b) {
; CHECK-LABEL: @test(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[X:%.*]] = alloca i8, align 1
; CHECK-NEXT:    [[INALLOCA_SAVE:%.*]] = call ptr @llvm.stacksave()
; CHECK-NEXT:    [[ARGMEM:%.*]] = alloca inalloca <{ [[STRUCT_S:%.*]] }>, align 4
; CHECK-NEXT:    [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[ARGMEM]], i32 0, i32 1
; CHECK-NEXT:    store ptr [[X]], ptr [[TMP1]], align 4
; CHECK-NEXT:    br i1 [[B:%.*]], label [[TRUE:%.*]], label [[FALSE:%.*]]
; CHECK:       true:
; CHECK-NEXT:    [[P:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[ARGMEM]], i32 0, i32 1
; CHECK-NEXT:    br label [[EXIT:%.*]]
; CHECK:       false:
; CHECK-NEXT:    [[P2:%.*]] = getelementptr inbounds [[STRUCT_S]], ptr [[ARGMEM]], i32 0, i32 1
; CHECK-NEXT:    br label [[EXIT]]
; CHECK:       exit:
; CHECK-NEXT:    call void @f(ptr inalloca(<{ [[STRUCT_S]] }>) [[ARGMEM]])
; CHECK-NEXT:    call void @llvm.stackrestore(ptr [[INALLOCA_SAVE]])
; CHECK-NEXT:    ret void
;
entry:
  %x = alloca i8
  %inalloca.save = call ptr @llvm.stacksave()
  %argmem = alloca inalloca <{ %struct.S }>, align 4
  br i1 %b, label %true, label %false

true:
  %p = getelementptr inbounds %struct.S, ptr %argmem, i32 0, i32 1
  store ptr %x, ptr %p, align 4
  br label %exit

false:
  %p2 = getelementptr inbounds %struct.S, ptr %argmem, i32 0, i32 1
  store ptr %x, ptr %p2, align 4
  br label %exit

exit:
  call void @f(ptr inalloca(<{ %struct.S }>) %argmem)
  call void @llvm.stackrestore(ptr %inalloca.save)
  ret void
}

declare ptr @llvm.stacksave()
declare void @llvm.stackrestore(ptr)