1 ; RUN: llvm-as < %s | llvm-dis > %t.orig
2 ; RUN: llvm-as < %s | llvm-c-test --echo > %t.echo
3 ; RUN: diff -w %t.orig %t.echo
5 source_filename = "/test/Bindings/echo.ll"
6 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
7 target triple = "x86_64-apple-macosx10.11.0"
9 module asm "classical GAS"
11 %S = type { i64, ptr }
14 @ext = external global ptr
15 @cst = constant %S { i64 1, ptr @cst }
16 @tl = thread_local global { i64, ptr } { i64 1, ptr @cst }
17 @arr = linkonce_odr global [5 x i8] [ i8 2, i8 3, i8 5, i8 7, i8 11 ]
18 @str = private unnamed_addr constant [13 x i8] c"hello world\0A\00"
19 @locStr = private local_unnamed_addr constant [13 x i8] c"hello world\0A\00"
20 @hidden = hidden global i32 7
21 @protected = protected global i32 23
22 @section = global i32 27, section ".custom"
23 @align = global i32 31, align 4
24 @nullptr = global ptr null
26 @const_gep = global ptr getelementptr (i32, ptr @var, i64 2)
27 @const_inbounds_gep = global ptr getelementptr inbounds (i32, ptr @var, i64 1)
29 @aliased1 = alias i32, ptr @var
30 @aliased2 = internal alias i32, ptr @var
31 @aliased3 = external alias i32, ptr @var
32 @aliased4 = weak alias i32, ptr @var
33 @aliased5 = weak_odr alias i32, ptr @var
35 @ifunc = ifunc i32 (i32), ptr @ifunc_resolver
37 define ptr @ifunc_resolver() {
42 define { i64, ptr } @unpackrepack(%S %s) {
43 %1 = extractvalue %S %s, 0
44 %2 = extractvalue %S %s, 1
45 %3 = insertvalue { i64, ptr } undef, ptr %2, 1
46 %4 = insertvalue { i64, ptr } %3, i64 %1, 0
52 ; TODO: label and metadata types
53 define void @types() {
54 %1 = alloca half, align 2
55 %2 = alloca float, align 4
56 %3 = alloca double, align 8
57 %4 = alloca x86_fp80, align 16
58 %5 = alloca fp128, align 16
59 %6 = alloca ppc_fp128, align 16
60 %7 = alloca i7, align 1
61 %8 = alloca ptr, align 8
62 %9 = alloca [3 x i22], align 4
63 %10 = alloca ptr addrspace(5), align 8
64 %11 = alloca <5 x ptr>, align 64
65 %12 = alloca x86_mmx, align 8
69 define i32 @iops(i32 %a, i32 %b) {
83 %14 = add nuw i32 %13, %a
84 %15 = add nsw i32 %14, %b
85 %16 = add nuw nsw i32 %15, %a
86 %17 = shl nuw i32 %16, %a
87 %18 = shl nsw i32 %17, %b
88 %19 = shl nuw nsw i32 %18, %a
89 %20 = udiv exact i32 %19, %1
90 %21 = sdiv exact i32 %20, %2
91 %22 = lshr exact i32 %21, %4
92 %23 = ashr exact i32 %22, %14
97 %1 = call i32 @iops(i32 23, i32 19)
101 define i32 @tailcall() {
102 %1 = tail call i32 @call()
106 define i32 @musttailcall() {
107 %1 = musttail call i32 @call()
111 define i32 @notailcall() {
112 %1 = notail call i32 @call()
116 define i32 @call_inline_asm(i32 %0) {
118 %2 = tail call i32 asm sideeffect inteldialect "mov $0, $1", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %0)
119 %3 = tail call i32 asm sideeffect inteldialect "lea $0, [$1+$2]", "=r,r,r,~{dirflag},~{fpsr},~{flags}"(i32 %0, i32 %2)
120 %4 = tail call i32 asm inteldialect "mov $0, $1", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %3)
121 %5 = tail call i32 asm inteldialect unwind "mov $0, $1", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %4)
122 %6 = tail call i32 asm alignstack inteldialect "mov $0, $1", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %5)
125 %7 = tail call i32 asm "mov $1, $0", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %6)
126 %8 = tail call i32 asm sideeffect "mov $1, $0", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %7)
127 %9 = tail call i32 asm alignstack "mov $1, $0", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %8)
128 %10 = tail call i32 asm alignstack unwind "mov $1, $0", "=r,r,~{dirflag},~{fpsr},~{flags}"(i32 %9)
132 define i32 @cond(i32 %a, i32 %b) {
137 %1 = icmp eq i32 %a, %b
138 br i1 %1, label %next0, label %unreachable
140 %2 = icmp ne i32 %a, %b
141 br i1 %2, label %next1, label %unreachable
143 %3 = icmp ugt i32 %a, %b
144 br i1 %3, label %next2, label %unreachable
146 %4 = icmp uge i32 %a, %b
147 br i1 %4, label %next3, label %unreachable
149 %5 = icmp ult i32 %a, %b
150 br i1 %5, label %next4, label %unreachable
152 %6 = icmp ule i32 %a, %b
153 br i1 %6, label %next5, label %unreachable
155 %7 = icmp sgt i32 %a, %b
156 br i1 %7, label %next6, label %unreachable
158 %8 = icmp sge i32 %a, %b
159 br i1 %8, label %next7, label %unreachable
161 %9 = icmp slt i32 %a, %b
162 br i1 %9, label %next8, label %unreachable
164 %10 = icmp sle i32 %a, %b
165 br i1 %10, label %next9, label %unreachable
170 define i32 @loop(i32 %i) {
173 %c = phi i32 [ %i, %0 ], [ %j, %do ]
174 %p = phi i32 [ %r, %do ], [ 789, %0 ]
175 %1 = icmp eq i32 %c, 0
176 br i1 %1, label %do, label %done
186 define void @memops(ptr %ptr) {
187 %a = load i8, ptr %ptr
188 %b = load volatile i8, ptr %ptr
189 %c = load i8, ptr %ptr, align 8
190 %d = load atomic i8, ptr %ptr acquire, align 32
192 store volatile i8 0, ptr %ptr
193 store i8 0, ptr %ptr, align 8
194 store atomic i8 0, ptr %ptr release, align 32
195 %e = atomicrmw add ptr %ptr, i8 0 monotonic, align 1
196 %f = atomicrmw volatile xchg ptr %ptr, i8 0 acq_rel, align 8
197 %g = cmpxchg ptr %ptr, i8 1, i8 2 seq_cst acquire, align 1
198 %h = cmpxchg weak ptr %ptr, i8 1, i8 2 seq_cst acquire, align 8
199 %i = cmpxchg volatile ptr %ptr, i8 1, i8 2 monotonic monotonic, align 16
203 define i32 @vectorops(i32, i32) {
204 %a = insertelement <4 x i32> undef, i32 %0, i32 0
205 %b = insertelement <4 x i32> %a, i32 %1, i32 2
206 %c = shufflevector <4 x i32> %b, <4 x i32> undef, <4 x i32> zeroinitializer
207 %d = shufflevector <4 x i32> %c, <4 x i32> %b, <4 x i32> <i32 1, i32 2, i32 3, i32 0>
208 %e = add <4 x i32> %d, %a
209 %f = mul <4 x i32> %e, %b
210 %g = xor <4 x i32> %f, %d
211 %h = or <4 x i32> %f, %e
212 %i = lshr <4 x i32> %h, <i32 2, i32 2, i32 2, i32 2>
213 %j = shl <4 x i32> %i, <i32 2, i32 3, i32 4, i32 5>
214 %k = shufflevector <4 x i32> %j, <4 x i32> %i, <4 x i32> <i32 2, i32 3, i32 undef, i32 undef>
215 %m = shufflevector <4 x i32> %k, <4 x i32> undef, <1 x i32> <i32 1>
216 %n = shufflevector <4 x i32> %j, <4 x i32> undef, <8 x i32> <i32 0, i32 0, i32 1, i32 2, i32 undef, i32 3, i32 undef, i32 undef>
217 %p = extractelement <8 x i32> %n, i32 5
221 define i32 @scalablevectorops(i32, <vscale x 4 x i32>) {
222 %a = insertelement <vscale x 4 x i32> undef, i32 %0, i32 0
223 %b = insertelement <vscale x 4 x i32> %a, i32 %0, i32 2
224 %c = shufflevector <vscale x 4 x i32> %b, <vscale x 4 x i32> undef, <vscale x 4 x i32> zeroinitializer
225 %e = add <vscale x 4 x i32> %a, %1
226 %f = mul <vscale x 4 x i32> %e, %b
227 %g = xor <vscale x 4 x i32> %f, %e
228 %h = or <vscale x 4 x i32> %g, %e
229 %i = lshr <vscale x 4 x i32> %h, undef
230 %j = extractelement <vscale x 4 x i32> %i, i32 3
234 declare void @personalityFn()
236 define void @exn() personality ptr @personalityFn {
239 to label %via.cleanup unwind label %exn.dispatch
242 to label %via.catchswitch unwind label %cleanup.inner
244 %cp.inner = cleanuppad within none []
245 cleanupret from %cp.inner unwind label %exn.dispatch
248 to label %exit unwind label %dispatch.inner
250 %cs.inner = catchswitch within none [label %pad.inner] unwind label %exn.dispatch
252 %catch.inner = catchpad within %cs.inner [i32 0]
253 catchret from %catch.inner to label %exit
255 %cs = catchswitch within none [label %pad1, label %pad2] unwind label %cleanup
257 catchpad within %cs [i32 1]
260 catchpad within %cs [i32 2]
263 %cp = cleanuppad within none []
264 cleanupret from %cp unwind to caller
269 define void @with_debuginfo() !dbg !4 {
273 declare ptr @llvm.stacksave()
274 declare void @llvm.stackrestore(ptr)
275 declare void @llvm.lifetime.start.p0(i64, ptr)
276 declare void @llvm.lifetime.end.p0(i64, ptr)
278 define void @test_intrinsics() {
280 %sp = call ptr @llvm.stacksave()
281 %0 = alloca i8, align 1
282 call void @llvm.lifetime.start.p0(i64 1, ptr %0)
283 call void @llvm.lifetime.end.p0(i64 1, ptr %0)
284 call void @llvm.stackrestore(ptr %sp)
288 !llvm.dbg.cu = !{!0, !2}
289 !llvm.module.flags = !{!3}
291 !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
292 !1 = !DIFile(filename: "echo.ll", directory: "/llvm/test/Bindings/llvm-c/echo.ll")
293 !2 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
294 !3 = !{i32 2, !"Debug Info Version", i32 3}
295 !4 = distinct !DISubprogram(name: "with_debuginfo", linkageName: "_with_debuginfo", scope: null, file: !1, line: 42, type: !5, isLocal: false, isDefinition: true, scopeLine: 1519, flags: DIFlagPrototyped, isOptimized: true, unit: !0, templateParams: !6, retainedNodes: !6)
296 !5 = !DISubroutineType(types: !6)
298 !7 = !DILocation(line: 42, scope: !8, inlinedAt: !11)
299 !8 = distinct !DILexicalBlock(scope: !9, file: !1, line: 42, column: 12)
300 !9 = distinct !DISubprogram(name: "fake_inlined_block", linkageName: "_fake_inlined_block", scope: null, file: !1, line: 82, type: !5, isLocal: false, isDefinition: true, scopeLine: 82, flags: DIFlagPrototyped, isOptimized: true, unit: !2, templateParams: !6, retainedNodes: !6)
301 !10 = distinct !DILocation(line: 84, scope: !8, inlinedAt: !11)
302 !11 = !DILocation(line: 42, scope: !4)