int %f(int %a) {
entry:
	%tmp = seteq int %a, 4		; <bool> [#uses=1]
	br bool %tmp, label %cond_false, label %cond_true

cond_true:		; preds = %entry
	br label %return

cond_false:		; preds = %entry
	br label %return

return:		; preds = %cond_false, %cond_true
	%retval.0 = phi int [ 2, %cond_true ], [ 3, %cond_false ]		; <int> [#uses=1]
	ret int %retval.0
}

Add a simple RUN line so this doesn't always fail. XFAIL this until Rafael can get a chance to fix it.

; RUN llvm-as %s -o /dev/null -f
; XFAIL: ALL
int %f(int %a) {
entry:
	%tmp = seteq int %a, 4		; <bool> [#uses=1]
	br bool %tmp, label %cond_false, label %cond_true

cond_true:		; preds = %entry
	br label %return

cond_false:		; preds = %entry
	br label %return

return:		; preds = %cond_false, %cond_true
	%retval.0 = phi int [ 2, %cond_true ], [ 3, %cond_false ]		; <int> [#uses=1]
	ret int %retval.0
}


%Hosp = type { int, int, int, { \2 *, { int, int, int, { [4 x \3], \2, \5, \6,
   int, int } * } *, \2 * }, { \2 *, { int, int, int, { [4 x \3], \2, \5, \6, int,
    int } * } *, \2 * }, { \2 *, { int, int, int, { [4 x \3], \2, \5, \6, int, int
    } * } *, \2 * }, { \2 *, { int, int, int, { [4 x \3], \2, \5, \6, int, int } * }
     *, \2 * } }

Fix bug in testcase: no implementatino section make it not legal input, so once the parser is fixed to handle the bug, it broke on the bad input. :)


; The output formater prints out 1.0e100 as Inf!
;
; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis

define float @test() {
        %tmp = mul float 0x7FF0000000000000, 1.000000e+01               ; <float> [#uses=1]
        ret float %tmp
}

Make this test slightly more strict.

; The output formater prints out 1.0e100 as Inf!
;
; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | grep 0x7FF0000000000000

define float @test() {
        %tmp = mul float 0x7FF0000000000000, 1.000000e+01               ; <float> [#uses=1]
        ret float %tmp
}


; Check that the backend doesn't crash.
; RUN: llc -mtriple=x86_64-pc-freebsd %s -o - | FileCheck %s

@__stack_chk_guard = internal global [8 x i64] zeroinitializer, align 16

define void @f() sspstrong {
  %tbl = alloca [4 x i64], align 16
  ret void
}

; CHECK:  .type __stack_chk_guard,@object
; CHECK:  .local  __stack_chk_guard
; CHECK:  .comm __stack_chk_guard,64,16

Improve r272262, check that __stack_chk_guard is used.

; Check that the backend doesn't crash.
; RUN: llc -mtriple=x86_64-pc-freebsd %s -o - | FileCheck %s

@__stack_chk_guard = internal global [8 x i64] zeroinitializer, align 16

define void @f() sspstrong {
  %tbl = alloca [4 x i64], align 16
  ret void
}

; CHECK:  movq  __stack_chk_guard(%rip), %rax
; CHECKL  movq  __stack_chk_guard(%rip), %rax
; CHECK:  .type __stack_chk_guard,@object
; CHECK:  .local  __stack_chk_guard
; CHECK:  .comm __stack_chk_guard,64,16


; RUN: llvm-as %s -o %t.bc
; RUN: llvm-lto2 run -r=%t.bc,foo,pxl -use-new-pm --print-before-all %t.bc -o - 2>&1 | FileCheck %s --check-prefix=CHECK-BEFORE
; RUN: llvm-lto2 run -r=%t.bc,foo,pxl -use-new-pm --print-after-all %t.bc -o - 2>&1 | FileCheck %s --check-prefix=CHECK-AFTER
; CHECK-BEFORE: *** IR Dump Before GlobalDCEPass ***
; CHECK-AFTER: *** IR Dump After GlobalDCEPass ***

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define i32 @foo() {
    ret i32 42
}

Fix test added in r369024.

; RUN: llvm-as %s -o %t.bc
; RUN: llvm-lto2 run -r=%t.bc,foo,pxl -use-new-pm --print-before-all %t.bc -o %t2 2>&1 | FileCheck %s --check-prefix=CHECK-BEFORE
; RUN: llvm-lto2 run -r=%t.bc,foo,pxl -use-new-pm --print-after-all %t.bc -o %t3 2>&1 | FileCheck %s --check-prefix=CHECK-AFTER
; CHECK-BEFORE: *** IR Dump Before GlobalDCEPass ***
; CHECK-AFTER: *** IR Dump After GlobalDCEPass ***

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define i32 @foo() {
    ret i32 42
}


; RUN: llvm-dis %s.bc-16 -o /dev/null -f &&
; RUN: llc %s.bc-16 -o /dev/null -f -march=c &&
; RUN: llvm-as < %s

void %test(int* %P, int* %Q) {
entry:
	%tmp.1 = cast int* %P to sbyte*		; <sbyte*> [#uses=2]
	%tmp.3 = cast int* %Q to sbyte*		; <sbyte*> [#uses=3]
	tail call void %llvm.memcpy( sbyte* %tmp.1, sbyte* %tmp.3, uint 100000, uint 1 )
	tail call void %llvm.memcpy( sbyte* %tmp.1, sbyte* %tmp.3, ulong 100000, uint 1 )
	tail call void %llvm.memset( sbyte* %tmp.3, ubyte 14, uint 10000, uint 0 )
	tail call void %llvm.memmove( sbyte* %tmp.1, sbyte* %tmp.3, uint 123124, uint 1 )
	ret void
}

declare void %llvm.memcpy(sbyte*, sbyte*, uint, uint)
declare void %llvm.memcpy(sbyte*, sbyte*, ulong, uint)

declare void %llvm.memset(sbyte*, ubyte, uint, uint)

declare void %llvm.memmove(sbyte*, sbyte*, uint, uint)

Upgrade old intrinsic function calls manually.

; RUN: llvm-upgrade < %s | llvm-as -o /dev/null -f

void %test(int* %P, int* %Q) {
entry:
	%tmp.1 = cast int* %P to sbyte*		; <sbyte*> [#uses=2]
	%tmp.3 = cast int* %Q to sbyte*		; <sbyte*> [#uses=3]
	tail call void %llvm.memcpy.i32( sbyte* %tmp.1, sbyte* %tmp.3, uint 100000, uint 1 )
	tail call void %llvm.memcpy.i64( sbyte* %tmp.1, sbyte* %tmp.3, ulong 100000, uint 1 )
	tail call void %llvm.memset.i32( sbyte* %tmp.3, ubyte 14, uint 10000, uint 0 )
	tail call void %llvm.memmove.i32( sbyte* %tmp.1, sbyte* %tmp.3, uint 123124, uint 1 )
	ret void
}

declare void %llvm.memcpy.i32(sbyte*, sbyte*, uint, uint)
declare void %llvm.memcpy.i64(sbyte*, sbyte*, ulong, uint)
declare void %llvm.memset.i32(sbyte*, ubyte, uint, uint)
declare void %llvm.memmove.i32(sbyte*, sbyte*, uint, uint)


; RUN: opt -S -globalopt < %s | FileCheck %s

; PR6112 - When globalopt does RAUW(@G, %G), the metadata reference should drop
; to null.  Function local metadata that references @G from a different function
; to that containing %G should likewise drop to null.
@G = internal global i8** null

define i32 @main(i32 %argc, i8** %argv) {
; CHECK: @main
; CHECK: %G = alloca
  store i8** %argv, i8*** @G
  ret i32 0
}

define void @foo(i32 %x) {
  call void @llvm.dbg.value(metadata !{i8*** @G, i32 %x}, i64 0, metadata !1)
; CHECK: call void @llvm.dbg.value(metadata !{null, i32 %x}, i64 0, metadata !1)
  ret void
}

declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone

!named = !{!0}

!0 = metadata !{i8*** @G}
; CHECK: !0 = metadata !{null}
!1 = metadata !{i8* null}

Use llvm.foo as the intrinsic, rather than llvm.dbg.value. Since the values passed to llvm.dbg.value were not valid for the intrinsic, it might have caused trouble one day if the verifier ever started checking for valid debug info.

; RUN: opt -S -globalopt < %s | FileCheck %s

; PR6112 - When globalopt does RAUW(@G, %G), the metadata reference should drop
; to null.  Function local metadata that references @G from a different function
; to that containing %G should likewise drop to null.
@G = internal global i8** null

define i32 @main(i32 %argc, i8** %argv) {
; CHECK: @main
; CHECK: %G = alloca
  store i8** %argv, i8*** @G
  ret i32 0
}

define void @foo(i32 %x) {
  call void @llvm.foo(metadata !{i8*** @G, i32 %x})
; CHECK: call void @llvm.foo(metadata !{null, i32 %x})
  ret void
}

declare void @llvm.foo(metadata) nounwind readnone

!named = !{!0}

!0 = metadata !{i8*** @G}
; CHECK: !0 = metadata !{null}


; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll

; RUN: llvm-as < %s | llvm-dis

%foo1 = uninitialized global <4 x float>;
%foo2 = uninitialized global <2 x int>;

implementation   ; Functions:

void %main()
{
        store <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0>, <4 x float>* %foo1
        store <2 x int> <int 4, int 4>, <2 x int>* %foo2
	%l1 = load <4 x float>* %foo1
        %l2 = load <2 x int>* %foo2
        ret void
}

Remove a redundant RUN: line.

; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll

%foo1 = uninitialized global <4 x float>;
%foo2 = uninitialized global <2 x int>;

implementation   ; Functions:

void %main()
{
        store <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0>, <4 x float>* %foo1
        store <2 x int> <int 4, int 4>, <2 x int>* %foo2
	%l1 = load <4 x float>* %foo1
        %l2 = load <2 x int>* %foo2
        ret void
}


; RUN: llc < %s -march=x86 | FileCheck %s

; CHECK: "iΔ",4,4
@"i\CE\94" = common global i32 0, align 4

Make the test for r154235 more platform-independent with a shorter string.

; RUN: llc < %s -march=x86 | FileCheck %s

; CHECK: iΔ
@"i\CE\94" = common global i32 0, align 4


; REQUIRES: shell
; RUN: rm -rf %t.dir
; RUN: mkdir -p %t.dir
; RUN: llc -filetype=obj %s -o %t.dir/foo.o
; RUN: wasm-ld --reproduce=%t.dir/repro.tar -o out.wasm %t.dir/foo.o

; RUN: cd %t.dir
; RUN: tar tf repro.tar | FileCheck --check-prefix=TAR %s

; TAR: repro/response.txt
; TAR: repro/version.txt
; TAR: repro/{{.*}}/foo.o

; RUN: tar xf repro.tar
; RUN: FileCheck --check-prefix=RSP %s < repro/response.txt

; RSP: -o out.wasm
; RSP: {{.*}}/foo.o

; RUN: FileCheck %s --check-prefix=VERSION < repro/version.txt
; VERSION: LLD

target triple = "wasm32-unknown-unknown"

define void @_start() {
  ret void
}

Fix test to put its outputs into the temp directory.

; REQUIRES: shell
; RUN: rm -rf %t.dir
; RUN: mkdir -p %t.dir
; RUN: llc -filetype=obj %s -o %t.dir/foo.o
; RUN: wasm-ld --reproduce=%t.dir/repro.tar -o %t.dir/out.wasm %t.dir/foo.o

; RUN: cd %t.dir
; RUN: tar tf repro.tar | FileCheck --check-prefix=TAR %s

; TAR: repro/response.txt
; TAR: repro/version.txt
; TAR: repro/{{.*}}/foo.o

; RUN: tar xf repro.tar
; RUN: FileCheck --check-prefix=RSP %s < repro/response.txt

; RSP: -o {{.*}}out.wasm
; RSP: {{.*}}/foo.o

; RUN: FileCheck %s --check-prefix=VERSION < repro/version.txt
; VERSION: LLD

target triple = "wasm32-unknown-unknown"

define void @_start() {
  ret void
}


; Test that the StrChrOptimizer works correctly
; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | not grep 'call.*strchr'

declare sbyte* %strchr(sbyte*,int)
declare int %puts(sbyte*)
%hello = constant [14 x sbyte] c"hello world\n\00"
%null = constant [1 x sbyte] c"\00"

implementation   ; Functions:

int %main () {
  %hello_p = getelementptr [14 x sbyte]* %hello, int 0, int 0
  %null_p = getelementptr [1 x sbyte]* %null, int 0, int 0

  %world  = call sbyte* %strchr(sbyte* %hello_p, int 119 )
  %ignore = call sbyte* %strchr(sbyte* %null_p, int 119 )
  %result = call int %puts(sbyte* %world)
  ret int %result
}

Fix this test to succeed even if "strchr" is on a call instruction.

; Test that the StrChrOptimizer works correctly
; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | not grep 'call.*%strchr'

declare sbyte* %strchr(sbyte*,int)
declare int %puts(sbyte*)
%hello = constant [14 x sbyte] c"hello world\n\00"
%null = constant [1 x sbyte] c"\00"

implementation   ; Functions:

int %main () {
  %hello_p = getelementptr [14 x sbyte]* %hello, int 0, int 0
  %null_p = getelementptr [1 x sbyte]* %null, int 0, int 0

  %world  = call sbyte* %strchr(sbyte* %hello_p, int 119 )
  %ignore = call sbyte* %strchr(sbyte* %null_p, int 119 )
  %len = call int %puts(sbyte* %world)
  %index = add int %len, 112
  %result = call sbyte* %strchr(sbyte* %hello_p, int %index)
  ret int %index
}


; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 | grep movss    | wc -l | grep 3 &&
; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 | grep unpckhps | wc -l | grep 1 &&
; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 | grep pshufd   | wc -l | grep 1

void %test1(<4 x float>* %F, float* %f) {
	%tmp = load <4 x float>* %F
	%tmp7 = add <4 x float> %tmp, %tmp
	%tmp2 = extractelement <4 x float> %tmp7, uint 0
	store float %tmp2, float* %f
	ret void
}

float %test2(<4 x float>* %F, float* %f) {
	%tmp = load <4 x float>* %F
	%tmp7 = add <4 x float> %tmp, %tmp
	%tmp2 = extractelement <4 x float> %tmp7, uint 2
        ret float %tmp2
}

void %test2(float* %R, <4 x float>* %P1) {
	%X = load <4 x float>* %P1
	%tmp = extractelement <4 x float> %X, uint 2
	store float %tmp, float* %R
	ret void
}

Update vector extract test cases.

; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 | grep movss    | wc -l | grep 3 &&
; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 | grep movhlps  | wc -l | grep 1 &&
; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 | grep pshufd   | wc -l | grep 1

void %test1(<4 x float>* %F, float* %f) {
	%tmp = load <4 x float>* %F
	%tmp7 = add <4 x float> %tmp, %tmp
	%tmp2 = extractelement <4 x float> %tmp7, uint 0
	store float %tmp2, float* %f
	ret void
}

float %test2(<4 x float>* %F, float* %f) {
	%tmp = load <4 x float>* %F
	%tmp7 = add <4 x float> %tmp, %tmp
	%tmp2 = extractelement <4 x float> %tmp7, uint 2
        ret float %tmp2
}

void %test2(float* %R, <4 x float>* %P1) {
	%X = load <4 x float>* %P1
	%tmp = extractelement <4 x float> %X, uint 3
	store float %tmp, float* %R
	ret void
}


; RUN: as < %s > Output/%s.out1.bc
; RUN: echo "%S = external global { int, opaque* }" | as > Output/%s.out2.bc
; RUN: link Output/%s.out[12].bc | dis | not grep opaque

; After linking this testcase, there should be no opaque types left.  The two
; S's should cause the opaque type to be resolved to 'int'.
%S = global { int, int* } { int 5, int* null }

Test functions as well as globals

; RUN: as < %s > Output/%s.out1.bc
; RUN: echo "%S = external global { int, opaque* } declare void %F(opaque*)" | as > Output/%s.out2.bc
; RUN: link Output/%s.out[12].bc | dis | not grep opaque

; After linking this testcase, there should be no opaque types left.  The two
; S's should cause the opaque type to be resolved to 'int'.
%S = global { int, int* } { int 5, int* null }

declare void %F(int*)


; RUN: opt < %s -instcombine -S | FileCheck %s

target datalayout = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:64:64-v128:128:128-a0:0:32-n32"

@a = constant [2 x i32] [i32 3, i32 6]            ; <[2 x i32]*> [#uses=2]

define arm_apcscc i32 @b(i32 %y) nounwind readonly {
; CHECK: @b
; CHECK-NOT: load
; CHECK: ret i32
entry:
  %0 = icmp eq i32 %y, 0                          ; <i1> [#uses=1]
  %storemerge = select i1 %0, i32* getelementptr inbounds ([2 x i32]* @a, i32 0, i32 1), i32* getelementptr inbounds ([2 x i32]* @a, i32 0, i32 0) ; <i32*> [#uses=1]
  %1 = load i32* %storemerge, align 4             ; <i32> [#uses=1]
  ret i32 %1
}

Remove ARM-specific calling convention from this test. Target data is needed for this test, but otherwise, there's nothing ARM-specific about it and no need to specify the calling convention.


declare i8* @malloc(i64)
declare void @free(i8*)
declare i64 @write(i32, i8*, i64)
declare i32 @asprintf(i8**, i8*, ...)
declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i32, i1)

%IBool = type { i64 (i8*, i1*)* }
%IBool.wrap = type { %IBool*, i8* }

%str = type { i1, i64, i8* }
%IStr = type { i64 (i8*, %str*)* }
%IStr.wrap = type { %IStr*, i8* }

define i8* @lang.malloc(i64 %sz) alwaysinline {
	%1 = call i8* @malloc(i64 %sz)
	ret i8* %1
}

define void @lang.free(i8* %ptr) alwaysinline {
	call void @free(i8* %ptr)
	ret void
}

Add some stuff to help debugging memory issues.

declare i8* @malloc(i64)
declare void @free(i8*)
declare i64 @write(i32, i8*, i64)
declare i32 @asprintf(i8**, i8*, ...)
declare i32 @printf(i8*, ...)
declare void @llvm.memcpy.p0i8.p0i8.i64(i8*, i8*, i64, i32, i1)

%IBool = type { i64 (i8*, i1*)* }
%IBool.wrap = type { %IBool*, i8* }

%str = type { i1, i64, i8* }
%IStr = type { i64 (i8*, %str*)* }
%IStr.wrap = type { %IStr*, i8* }

@fmt_MALLOC = constant [15 x i8] c"malloc(%ld) %p\0a"
@fmt_FREE = constant [9 x i8] c"free(%p)\0a"

define i8* @lang.malloc(i64 %sz) alwaysinline {
	%ptr = call i8* @malloc(i64 %sz)
	; %fmt = getelementptr inbounds [15 x i8]* @fmt_MALLOC, i32 0, i32 0
	; call i32 (i8*, ...)* @printf(i8* %fmt, i64 %sz, i8* %ptr)
	ret i8* %ptr
}

define void @lang.free(i8* %ptr) alwaysinline {
	; %fmt = getelementptr inbounds [9 x i8]* @fmt_FREE, i32 0, i32 0
	; call i32 (i8*, ...)* @printf(i8* %fmt, i8* %ptr)
	call void @free(i8* %ptr)
	ret void
}


; RUN: llc < %s -mtriple=x86_64-linux -march=x86 |  FileCheck %s

define void @t(<2 x i64>* %dst, <2 x i64> %src1, <2 x i64> %src2) nounwind readonly {
; CHECK: pandn
  %cmp1 = icmp ne <2 x i64> %src1, zeroinitializer
  %cmp2 = icmp ne <2 x i64> %src2, zeroinitializer
  %t1 = and <2 x i1> %cmp1, %cmp2
  %t2 = sext <2 x i1> %t1 to <2 x i64>
  store <2 x i64> %t2, <2 x i64>* %dst
  ret void
}

define void @t2(<3 x i64>* %dst, <3 x i64> %src1, <3 x i64> %src2) nounwind readonly {
; CHECK-NOT: pandn
  %cmp1 = icmp ne <3 x i64> %src1, zeroinitializer
  %cmp2 = icmp ne <3 x i64> %src2, zeroinitializer
  %t1 = and <3 x i1> %cmp1, %cmp2
  %t2 = sext <3 x i1> %t1 to <3 x i64>
  store <3 x i64> %t2, <3 x i64>* %dst
  ret void
}

Clean the triple, add check lines.

; RUN: llc < %s -mtriple=x86_64-linux |  FileCheck %s

define void @t0(<2 x i64>* %dst, <2 x i64> %src1, <2 x i64> %src2) nounwind readonly {
; CHECK: t0
; CHECK: pand
; CHECK: ret
  %cmp1 = icmp ne <2 x i64> %src1, zeroinitializer
  %cmp2 = icmp ne <2 x i64> %src2, zeroinitializer
  %t1 = and <2 x i1> %cmp1, %cmp2
  %t2 = sext <2 x i1> %t1 to <2 x i64>
  store <2 x i64> %t2, <2 x i64>* %dst
  ret void
}

define void @t2(<3 x i64>* %dst, <3 x i64> %src1, <3 x i64> %src2) nounwind readonly {
; CHECK: t2
; CHECK-NOT: pand
; CHECK: ret
  %cmp1 = icmp ne <3 x i64> %src1, zeroinitializer
  %cmp2 = icmp ne <3 x i64> %src2, zeroinitializer
  %t1 = and <3 x i1> %cmp1, %cmp2
  %t2 = sext <3 x i1> %t1 to <3 x i64>
  store <3 x i64> %t2, <3 x i64>* %dst
  ret void
}


; Test combined function index generation for ThinLTO via llvm-lto.
; RUN: llvm-as -function-summary %s -o %t.o
; RUN: llvm-as -function-summary %p/Inputs/thinlto.ll -o %t2.o
; RUN: llvm-lto -thinlto -o %t3 %t.o %t2.o
; RUN: llvm-bcanalyzer -dump %t3.thinlto.bc | FileCheck %s --check-prefix=COMBINED
; RUN: not test -e %t3

; COMBINED: <MODULE_STRTAB_BLOCK
; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}/thinlto.ll.tmp{{.*}}.o'
; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}/thinlto.ll.tmp{{.*}}.o'
; COMBINED-NEXT: </MODULE_STRTAB_BLOCK
; COMBINED-NEXT: <FUNCTION_SUMMARY_BLOCK
; COMBINED-NEXT: <COMBINED_ENTRY
; COMBINED-NEXT: <COMBINED_ENTRY
; COMBINED-NEXT: </FUNCTION_SUMMARY_BLOCK
; COMBINED-NEXT: <VALUE_SYMTAB
; COMBINED-NEXT: <COMBINED_FNENTRY {{.*}} record string = '{{f|g}}'
; COMBINED-NEXT: <COMBINED_FNENTRY {{.*}} record string = '{{f|g}}'
; COMBINED-NEXT: </VALUE_SYMTAB

define void @f() {
entry:
  ret void
}

Fix windows bot failures from r250699 by removing "/" from expected path in test output.

; Test combined function index generation for ThinLTO via llvm-lto.
; RUN: llvm-as -function-summary %s -o %t.o
; RUN: llvm-as -function-summary %p/Inputs/thinlto.ll -o %t2.o
; RUN: llvm-lto -thinlto -o %t3 %t.o %t2.o
; RUN: llvm-bcanalyzer -dump %t3.thinlto.bc | FileCheck %s --check-prefix=COMBINED
; RUN: not test -e %t3

; COMBINED: <MODULE_STRTAB_BLOCK
; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}thinlto.ll.tmp{{.*}}.o'
; COMBINED-NEXT: <ENTRY {{.*}} record string = '{{.*}}thinlto.ll.tmp{{.*}}.o'
; COMBINED-NEXT: </MODULE_STRTAB_BLOCK
; COMBINED-NEXT: <FUNCTION_SUMMARY_BLOCK
; COMBINED-NEXT: <COMBINED_ENTRY
; COMBINED-NEXT: <COMBINED_ENTRY
; COMBINED-NEXT: </FUNCTION_SUMMARY_BLOCK
; COMBINED-NEXT: <VALUE_SYMTAB
; COMBINED-NEXT: <COMBINED_FNENTRY {{.*}} record string = '{{f|g}}'
; COMBINED-NEXT: <COMBINED_FNENTRY {{.*}} record string = '{{f|g}}'
; COMBINED-NEXT: </VALUE_SYMTAB

define void @f() {
entry:
  ret void
}


; RUN: llvm-as < %s | llc -march=x86 | grep {movsbl  .al, .eax}

@X = global i32 0               ; <i32*> [#uses=1]

define i8 @_Z3fooi(i32 %x) signext  {
entry:
        store i32 %x, i32* @X, align 4
        %retval67 = trunc i32 %x to i8          ; <i8> [#uses=1]
        ret i8 %retval67
}

Fix test so it passes.

; RUN: llvm-as < %s | llc -march=x86 | grep {movsbl}

@X = global i32 0               ; <i32*> [#uses=1]

define i8 @_Z3fooi(i32 %x) signext  {
entry:
        store i32 %x, i32* @X, align 4
        %retval67 = trunc i32 %x to i8          ; <i8> [#uses=1]
        ret i8 %retval67
}


; RUN: llc -march=mips < %s | FileCheck %s

@p = external global i32
@q = external global i32
@r = external global i32

define void @f0() nounwind {
entry:
; CHECK: jalr
; CHECK-NOT: got({{.*}})($gp)
; CHECK: lw $gp
; CHECK: jalr
; CHECK-NOT: got({{.*}})($gp)
; CHECK: lw $gp
; CHECK: jalr
; CHECK-NOT: got({{.*}})($gp)
; CHECK: lw $gp
  tail call void (...)* @f1() nounwind
  %tmp = load i32* @p, align 4, !tbaa !0
  tail call void @f2(i32 %tmp) nounwind
  %tmp1 = load i32* @q, align 4, !tbaa !0
  %tmp2 = load i32* @r, align 4, !tbaa !0
  tail call void @f3(i32 %tmp1, i32 %tmp2) nounwind
  ret void
}

declare void @f1(...)

declare void @f2(i32)

declare void @f3(i32, i32)

!0 = metadata !{metadata !"int", metadata !1}
!1 = metadata !{metadata !"omnipotent char", metadata !2}
!2 = metadata !{metadata !"Simple C/C++ TBAA", null}

Remove LLVM IR metadata in test case committed in r130847.

; RUN: llc -march=mips < %s | FileCheck %s

@p = external global i32
@q = external global i32
@r = external global i32

define void @f0() nounwind {
entry:
; CHECK: jalr
; CHECK-NOT: got({{.*}})($gp)
; CHECK: lw $gp
; CHECK: jalr
; CHECK-NOT: got({{.*}})($gp)
; CHECK: lw $gp
; CHECK: jalr
; CHECK-NOT: got({{.*}})($gp)
; CHECK: lw $gp
  tail call void (...)* @f1() nounwind
  %tmp = load i32* @p, align 4
  tail call void @f2(i32 %tmp) nounwind
  %tmp1 = load i32* @q, align 4
  %tmp2 = load i32* @r, align 4
  tail call void @f3(i32 %tmp1, i32 %tmp2) nounwind
  ret void
}

declare void @f1(...)

declare void @f2(i32)

declare void @f3(i32, i32)


; RUN: %lli -code-model=small %s > /dev/null
; XFAIL: mips
;
; FIXME: Merge this file with non-extern-addend.ll once AArch64 supports PC-rel
;        relocations in ELF. (The code is identical, only the run line differs).
;
define i32 @foo(i32 %x, i32 %y, double %d) {
entry:
  %d.int64 = bitcast double %d to i64
  %d.top64 = lshr i64 %d.int64, 32
  %d.top   = trunc i64 %d.top64 to i32
  %d.bottom = trunc i64 %d.int64 to i32
  %topCorrect = icmp eq i32 %d.top, 3735928559
  %bottomCorrect = icmp eq i32 %d.bottom, 4277009102
  %right = and i1 %topCorrect, %bottomCorrect
  %nRight = xor i1 %right, true
  %retVal = zext i1 %nRight to i32
  ret i32 %retVal
}

define i32 @main() {
entry:
  %call = call i32 @foo(i32 0, i32 1, double 0xDEADBEEFFEEDFACE)
  ret i32 %call
}

Mark as explicit failing on x86-64 -- small memory model doesn't agree with default address selections.

; RUN: %lli -code-model=small %s > /dev/null
; XFAIL: mips
; XFAIL: x86_64
;
; FIXME: Merge this file with non-extern-addend.ll once AArch64 supports PC-rel
;        relocations in ELF. (The code is identical, only the run line differs).
;
define i32 @foo(i32 %x, i32 %y, double %d) {
entry:
  %d.int64 = bitcast double %d to i64
  %d.top64 = lshr i64 %d.int64, 32
  %d.top   = trunc i64 %d.top64 to i32
  %d.bottom = trunc i64 %d.int64 to i32
  %topCorrect = icmp eq i32 %d.top, 3735928559
  %bottomCorrect = icmp eq i32 %d.bottom, 4277009102
  %right = and i1 %topCorrect, %bottomCorrect
  %nRight = xor i1 %right, true
  %retVal = zext i1 %nRight to i32
  ret i32 %retVal
}

define i32 @main() {
entry:
  %call = call i32 @foo(i32 0, i32 1, double 0xDEADBEEFFEEDFACE)
  ret i32 %call
}


; @f and @g are lazily linked. @f requires @g - ensure @g is correctly linked.

; RUN: echo -e "declare i32 @f(i32)\ndefine i32 @h(i32 %x) {\n%1 = call i32 @f(i32 %x)\nret i32 %1\n}" | llvm-as >%t.1.bc
; RUN: llvm-as < %s > %t.2.bc
; RUN: llvm-link %t.1.bc %t.2.bc

define available_externally i32 @f(i32 %x) {
  %1 = call i32 @g(i32 %x)
  ret i32 %1
}

define available_externally i32 @g(i32 %x) {
  ret i32 5
}

Use multiple statements instead of 'echo -e', which is not part of BSD echo.

; @f and @g are lazily linked. @f requires @g - ensure @g is correctly linked.

; RUN: echo "declare i32 @f(i32)" > %t.1.ll
; RUN: echo "define i32 @h(i32 %x) {" >> %t.1.ll
; RUN: echo "  %1 = call i32 @f(i32 %x)" >> %t.1.ll
; RUN: echo "  ret i32 %1" >> %t.1.ll
; RUN: echo "}" >> %t.1.ll
; RUN: llvm-as < %t.1.ll > %t.1.bc
; RUN: llvm-as < %s > %t.2.bc
; RUN: llvm-link %t.1.bc %t.2.bc

define available_externally i32 @f(i32 %x) {
  %1 = call i32 @g(i32 %x)
  ret i32 %1
}

define available_externally i32 @g(i32 %x) {
  ret i32 5
}


; RUN: llvm-as %s | lli

; PR672

int %main(){
 %f   = cast int (int, int*, int)* %check_tail to int*
 %res = tail call fastcc int %check_tail( int 10, int* %f,int 10)
 ret int %res
}
fastcc int %check_tail(int %x, int* %f, int %g) {
	%tmp1 = setgt int %x, 0
	br bool %tmp1, label %if-then, label %if-else

if-then:
	%fun_ptr = cast int* %f to int(int, int*, int)*
	%arg1    = add int %x, -1
	%res = tail call fastcc int %fun_ptr( int %arg1, int * %f, int %g)
	ret int %res

if-else:
        ret int %x
}

Fix a bug in the testcase

; RUN: llvm-as < %s | lli

; PR672

int %main(){
 %f   = cast int (int, int*, int)* %check_tail to int*
 %res = tail call fastcc int %check_tail( int 10, int* %f,int 10)
 ret int %res
}
fastcc int %check_tail(int %x, int* %f, int %g) {
	%tmp1 = setgt int %x, 0
	br bool %tmp1, label %if-then, label %if-else

if-then:
	%fun_ptr = cast int* %f to int(int, int*, int)*
	%arg1    = add int %x, -1
	%res = tail call fastcc int %fun_ptr( int %arg1, int * %f, int %g)
	ret int %res

if-else:
        ret int %x
}


; PR28103
; Bail out if the two successors are not the header
; and another bb outside of the loop. This case is not
; properly handled by LoopUnroll, currently.

; RUN: opt -loop-unroll -verify-dom-info %s
; REQUIRE: asserts

define void @tinkywinky(i1 %patatino) {
entry:
  br label %header1
header1:
  %indvars.iv = phi i64 [ 1, %body2 ], [ 0, %entry ]
  %exitcond = icmp ne i64 %indvars.iv, 1
  br i1 %exitcond, label %body1, label %exit
body1:
  br i1 %patatino, label %body2, label %sink
body2:
  br i1 %patatino, label %header1, label %body3
body3:
  br label %sink
sink:
  br label %body2
exit:
  ret void
}

Fix a test. REQUIRE should be REQUIRES.

; PR28103
; Bail out if the two successors are not the header
; and another bb outside of the loop. This case is not
; properly handled by LoopUnroll, currently.

; RUN: opt -loop-unroll -verify-dom-info %s
; REQUIRES: asserts

define void @tinkywinky(i1 %patatino) {
entry:
  br label %header1
header1:
  %indvars.iv = phi i64 [ 1, %body2 ], [ 0, %entry ]
  %exitcond = icmp ne i64 %indvars.iv, 1
  br i1 %exitcond, label %body1, label %exit
body1:
  br i1 %patatino, label %body2, label %sink
body2:
  br i1 %patatino, label %header1, label %body3
body3:
  br label %sink
sink:
  br label %body2
exit:
  ret void
}


; The loop canonicalization pass should guarantee that there is one backedge
; for all loops.  This allows the -indvars pass to recognize the %IV
; induction variable in this testcase.

; RUN: opt < %s -indvars -S | grep indvar

define i32 @test(i1 %C) {
; <label>:0
	br label %Loop
Loop:		; preds = %BE2, %BE1, %0
	%IV = phi i32 [ 1, %0 ], [ %IV2, %BE1 ], [ %IV2, %BE2 ]		; <i32> [#uses=2]
	store i32 %IV, i32* null
	%IV2 = add i32 %IV, 2		; <i32> [#uses=2]
	br i1 %C, label %BE1, label %BE2
BE1:		; preds = %Loop
	br label %Loop
BE2:		; preds = %Loop
	br label %Loop
}

Generalize test case to handle multiple indvars modes.

; The loop canonicalization pass should guarantee that there is one backedge
; for all loops.  This allows the -indvars pass to recognize the %IV
; induction variable in this testcase.

; RUN: opt < %s -indvars -S | FileCheck %s
; CHECK: Loop.backedge:
; CHECK-NOT: br
; CHECK: br label %Loop

define i32 @test(i1 %C) {
; <label>:0
	br label %Loop
Loop:		; preds = %BE2, %BE1, %0
	%IV = phi i32 [ 1, %0 ], [ %IV2, %BE1 ], [ %IV2, %BE2 ]		; <i32> [#uses=2]
	store i32 %IV, i32* null
	%IV2 = add i32 %IV, 2		; <i32> [#uses=2]
	br i1 %C, label %BE1, label %BE2
BE1:		; preds = %Loop
	br label %Loop
BE2:		; preds = %Loop
	br label %Loop
}


; RUN: llc < %s -march=x86-64 -tailcallopt -fast-isel -fast-isel-abort | FileCheck %s

%0 = type { i64, i32, i8* }

define fastcc i8* @"visit_array_aux<`Reference>"(%0 %arg, i32 %arg1) nounwind {
fail:                                             ; preds = %entry
  %tmp20 = tail call fastcc i8* @"visit_array_aux<`Reference>"(%0 %arg, i32 undef) ; <i8*> [#uses=1]
; CHECK: jmp "_visit_array_aux<`Reference>" ## TAILCALL
  ret i8* %tmp20
}

define i32 @foo() nounwind {
entry:
 %0 = tail call i32 (...)* @bar() nounwind       ; <i32> [#uses=1]
 ret i32 %0
}

declare i32 @bar(...) nounwind

Add a triple to this test.

; RUN: llc < %s -mtriple=x86_64-apple-darwin -tailcallopt -fast-isel -fast-isel-abort | FileCheck %s

%0 = type { i64, i32, i8* }

define fastcc i8* @"visit_array_aux<`Reference>"(%0 %arg, i32 %arg1) nounwind {
fail:                                             ; preds = %entry
  %tmp20 = tail call fastcc i8* @"visit_array_aux<`Reference>"(%0 %arg, i32 undef) ; <i8*> [#uses=1]
; CHECK: jmp "_visit_array_aux<`Reference>" ## TAILCALL
  ret i8* %tmp20
}

define i32 @foo() nounwind {
entry:
 %0 = tail call i32 (...)* @bar() nounwind       ; <i32> [#uses=1]
 ret i32 %0
}

declare i32 @bar(...) nounwind


; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 -mattr=+read-tp-hard %s -o - | FileCheck %s -check-prefix=CHECK-HARD
; RUN: llc -mtriple=armeb-linux-gnueabihf -O2 %s -o - | FileCheck %s -check-prefix=CHECK-SOFT

; __thread int counter;
;  void foo() {
;    counter = 5;
;  }

@counter = thread_local local_unnamed_addr global i32 0, align 4

define void @foo() local_unnamed_addr #0 {
entry:
  store i32 5, i32* @counter, align 4
  ret void
}

; CHECK-LABEL: foo:
; CHECK-HARD:    mrc	p15, #0, {{r[0-9]+}}, c13, c0, #3
; CHECK-SOFT:    bl	__aeabi_read_tp

Add newline to end of test file. NFC.


; RUN: llc < %s -relocation-model=pic -disable-cfi -mtriple=x86_64-pc-solaris2.11 -disable-cgp-branch-opts | FileCheck %s -check-prefix=X64
; RUN: llc < %s -relocation-model=pic -disable-cfi -mtriple=i386-pc-solaris2.11 -disable-cgp-branch-opts | FileCheck %s -check-prefix=X32
; PR1632

define void @_Z1fv() {
entry:
  invoke void @_Z1gv()
          to label %return unwind label %unwind

unwind:                                           ; preds = %entry
  %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
            cleanup
  ret void

return:                                           ; preds = %eh_then, %entry
  ret void
}

declare void @_Z1gv()

declare i32 @__gxx_personality_v0(...)

; X64:      .size	DW.ref.__gxx_personality_v0, 8
; X64:      .quad	__gxx_personality_v0

; X32:      .size	DW.ref.__gxx_personality_v0, 4
; X32:      .long	__gxx_personality_v0

Remove unused options from test.

; RUN: llc < %s -relocation-model=pic -mtriple=x86_64-pc-solaris2.11 | FileCheck %s -check-prefix=X64
; RUN: llc < %s -relocation-model=pic -mtriple=i386-pc-solaris2.11 | FileCheck %s -check-prefix=X32
; PR1632

define void @_Z1fv() {
entry:
  invoke void @_Z1gv()
          to label %return unwind label %unwind

unwind:                                           ; preds = %entry
  %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0
            cleanup
  ret void

return:                                           ; preds = %eh_then, %entry
  ret void
}

declare void @_Z1gv()

declare i32 @__gxx_personality_v0(...)

; X64:      .size	DW.ref.__gxx_personality_v0, 8
; X64:      .quad	__gxx_personality_v0

; X32:      .size	DW.ref.__gxx_personality_v0, 4
; X32:      .long	__gxx_personality_v0


target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

; RUN: opt < %s -S -loop-vectorize -debug-only=loop-vectorize 2>&1 | FileCheck %s

; CHECK: LV: Can't vectorize due to memory conflicts

define void @test_loop_novect(double** %arr, i64 %n) {
for.body.lr.ph:
  %t = load double** %arr, align 8
  br label %for.body

for.body:                                      ; preds = %for.body, %for.body.lr.ph
  %i = phi i64 [ 0, %for.body.lr.ph ], [ %i.next, %for.body ]
  %a = getelementptr inbounds double* %t, i64 %i
  %i.next = add nuw nsw i64 %i, 1
  %a.next = getelementptr inbounds double* %t, i64 %i.next
  %t1 = load double* %a, align 8
  %t2 = load double* %a.next, align 8
  store double %t1, double* %a.next, align 8
  store double %t2, double* %a, align 8
  %c = icmp eq i64 %i, %n
  br i1 %c, label %final, label %for.body

final:                                   ; preds = %for.body
  ret void
}

Fix broken test from r225159.

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

; RUN: opt < %s -S -loop-vectorize -debug-only=loop-vectorize 2>&1 | FileCheck %s
; REQUIRES: asserts
; CHECK: LV: Can't vectorize due to memory conflicts

define void @test_loop_novect(double** %arr, i64 %n) {
for.body.lr.ph:
  %t = load double** %arr, align 8
  br label %for.body

for.body:                                      ; preds = %for.body, %for.body.lr.ph
  %i = phi i64 [ 0, %for.body.lr.ph ], [ %i.next, %for.body ]
  %a = getelementptr inbounds double* %t, i64 %i
  %i.next = add nuw nsw i64 %i, 1
  %a.next = getelementptr inbounds double* %t, i64 %i.next
  %t1 = load double* %a, align 8
  %t2 = load double* %a.next, align 8
  store double %t1, double* %a.next, align 8
  store double %t2, double* %a, align 8
  %c = icmp eq i64 %i, %n
  br i1 %c, label %final, label %for.body

final:                                   ; preds = %for.body
  ret void
}


; RUN: llc -march=mips < %s | FileCheck %s

; Check for the emission of appropriate assembler directives before and
; after the inline assembly code.
define void @f() nounwind {
entry:
; CHECK:      #APP
; CHECK-NEXT: .set  push
; CHECK-NEXT: .set  at
; CHECK-NEXT: .set  macro
; CHECK-NEXT: .set  reorder
; CHECK:      addi $9, ${{[2-9][0-9]?}}, 8
; CHECK:      subi ${{[2-9][0-9]?}}, $9, 6
; CHECK:      .set  pop
; CHECK-NEXT: #NO_APP
  %a = alloca i32, align 4
  %b = alloca i32, align 4
  store i32 20, i32* %a, align 4
  %0 = load i32, i32* %a, align 4
  %1 = call i32 asm sideeffect "addi $$9, $1, 8\0A\09subi $0, $$9, 6", "=r,r,~{$1}"(i32 %0)
  store i32 %1, i32* %b, align 4
  ret void
}

Replace invalid assembly insn in test since IAS parses inline assembly.

; RUN: llc -march=mips < %s | FileCheck %s

; Check for the emission of appropriate assembler directives before and
; after the inline assembly code.
define void @f() nounwind {
entry:
; CHECK:      #APP
; CHECK-NEXT: .set  push
; CHECK-NEXT: .set  at
; CHECK-NEXT: .set  macro
; CHECK-NEXT: .set  reorder
; CHECK:      addi $9, ${{[2-9][0-9]?}}, 8
; CHECK:      ori ${{[2-9][0-9]?}}, $9, 6
; CHECK:      .set  pop
; CHECK-NEXT: #NO_APP
  %a = alloca i32, align 4
  %b = alloca i32, align 4
  store i32 20, i32* %a, align 4
  %0 = load i32, i32* %a, align 4
  %1 = call i32 asm sideeffect "addi $$9, $1, 8\0A\09ori $0, $$9, 6", "=r,r,~{$1}"(i32 %0)
  store i32 %1, i32* %b, align 4
  ret void
}


; RUN: llc < %s -march=x86 | grep weak | count 2
@__gthrw_pthread_once = alias weak i32 (i32*, void ()*)* @pthread_once		; <i32 (i32*, void ()*)*> [#uses=0]

define weak i32 @pthread_once(i32*, void ()*) {
  ret i32 0
}

Add a triple and switch test to FileCheck.

; RUN: llc < %s -mtriple=i686-pc-linux-gnu | FileCheck %s

@__gthrw_pthread_once = alias weak i32 (i32*, void ()*)* @pthread_once		; <i32 (i32*, void ()*)*> [#uses=0]

define weak i32 @pthread_once(i32*, void ()*) {
  ret i32 0
}

; CHECK: .weak   pthread_once
; CHECK: pthread_once:

; CHECK: .weak   __gthrw_pthread_once
; CHECK: __gthrw_pthread_once = pthread_once


; RUN: llvm-as < %s | opt -indvars  | llvm-dis | %prcontext Loop: 1 | grep %indvar

; The indvar simplification code should ensure that the first PHI in the block
; is the canonical one!

define i32 @test() {
; <label>:0
        br label %Loop

Loop:           ; preds = %Loop, %0
        %NonIndvar = phi i32 [ 200, %0 ], [ %NonIndvarNext, %Loop ]             ; <i32> [#uses=1]
        %Canonical = phi i32 [ 0, %0 ], [ %CanonicalNext, %Loop ]               ; <i32> [#uses=1]
        %NonIndvarNext = sdiv i32 %NonIndvar, 2         ; <i32> [#uses=1]
        %CanonicalNext = add i32 %Canonical, 1          ; <i32> [#uses=1]
        br label %Loop
}

Make this testcase slightly less trivial, so that it doesn't fail if indvars happens to optimize away the unused primary induction variable.

; RUN: llvm-as < %s | opt -indvars  | llvm-dis | %prcontext Loop: 1 | grep %indvar

; The indvar simplification code should ensure that the first PHI in the block
; is the canonical one!

define i32 @test() {
; <label>:0
        br label %Loop

Loop:           ; preds = %Loop, %0
        %NonIndvar = phi i32 [ 200, %0 ], [ %NonIndvarNext, %Loop ]             ; <i32> [#uses=1]
        %Canonical = phi i32 [ 0, %0 ], [ %CanonicalNext, %Loop ]               ; <i32> [#uses=2]
        store i32 %Canonical, i32* null
        %NonIndvarNext = sdiv i32 %NonIndvar, 2         ; <i32> [#uses=1]
        %CanonicalNext = add i32 %Canonical, 1          ; <i32> [#uses=1]
        br label %Loop
}


; Test linking of a bc file to an archive via llvm-ld.
; PR1434
; RUN: rm %t.bar.a %t.foo.a
; RUN: llvm-as %s -o %t.bar.bc
; RUN: echo {define i32* @foo(i32 %x) \{ ret i32* @baz \} \
; RUN:   @baz = external global i32 } | llvm-as -o %t.foo.bc
; RUN: llvm-ar rcf %t.foo.a %t.foo.bc
; RUN: llvm-ar rcf %t.bar.a %t.bar.bc
; RUN: llvm-ld -disable-opt %t.bar.bc %t.foo.a -o %t.bc
; RUN: llvm-ld -disable-opt %t.foo.bc %t.bar.a -o %t.bc
declare i32* @foo(...)
define i32* @bar() {
	%ret = call i32* (...)* @foo( i32 123 )
	ret i32* %ret
}
@baz = global i32 0

Make everyone happy this time.

; Test linking of a bc file to an archive via llvm-ld.
; PR1434
; RUN: rm -f %t.bar.a %t.foo.a
; RUN: llvm-as %s -o %t.bar.bc
; RUN: echo {define i32* @foo(i32 %x) \{ ret i32* @baz \} \
; RUN:   @baz = external global i32 } | llvm-as -o %t.foo.bc
; RUN: llvm-ar rcf %t.foo.a %t.foo.bc
; RUN: llvm-ar rcf %t.bar.a %t.bar.bc
; RUN: llvm-ld -disable-opt %t.bar.bc %t.foo.a -o %t.bc
; RUN: llvm-ld -disable-opt %t.foo.bc %t.bar.a -o %t.bc
declare i32* @foo(...)
define i32* @bar() {
	%ret = call i32* (...)* @foo( i32 123 )
	ret i32* %ret
}
@baz = global i32 0


; RUN: llvm-as < %s | llc -march=x86 | FileCheck %s

@a = external global i96, align 4
@b = external global i64, align 8

define void @c() nounwind {
; CHECK: movl a+8, %eax
  %srcval1 = load i96* @a, align 4
  %sroa.store.elt2 = lshr i96 %srcval1, 64
  %tmp = trunc i96 %sroa.store.elt2 to i64
; CHECK: movl %eax, b
; CHECK: movl $0, b+4
  store i64 %tmp, i64* @b, align 8
  ret void
}

Make this test platform neutral.

; RUN: llvm-as < %s | llc -march=x86 -mtriple=i386-pc-linux | FileCheck %s

@a = external global i96, align 4
@b = external global i64, align 8

define void @c() nounwind {
; CHECK: movl a+8, %eax
  %srcval1 = load i96* @a, align 4
  %sroa.store.elt2 = lshr i96 %srcval1, 64
  %tmp = trunc i96 %sroa.store.elt2 to i64
; CHECK: movl %eax, b
; CHECK: movl $0, b+4
  store i64 %tmp, i64* @b, align 8
  ret void
}


; RUN: llvm-as < %s | llc -o %t
; RUN: not grep and %t
; RUN: not grep shr %t
; rdar://6661955

@hello = internal constant [7 x i8] c"hello\0A\00"
@world = internal constant [7 x i8] c"world\0A\00"

define void @func(i32* %b) nounwind {
bb1579.i.i:		; preds = %bb1514.i.i, %bb191.i.i
	%tmp176 = load i32* %b, align 4
	%tmp177 = and i32 %tmp176, 2
	%tmp178 = icmp eq i32 %tmp177, 0
        br i1 %tmp178, label %hello, label %world

hello:
	%h = tail call i32 (i8*, ...)* @printf( i8* getelementptr ([7 x i8]* @hello, i32 0, i32 0))
        ret void

world:
	%w = tail call i32 (i8*, ...)* @printf( i8* getelementptr ([7 x i8]* @world, i32 0, i32 0))
        ret void
}

declare i32 @printf(i8*, ...) nounwind

Add -f to RUN line.

; RUN: llvm-as < %s | llc -o %t -f
; RUN: not grep and %t
; RUN: not grep shr %t
; rdar://6661955

@hello = internal constant [7 x i8] c"hello\0A\00"
@world = internal constant [7 x i8] c"world\0A\00"

define void @func(i32* %b) nounwind {
bb1579.i.i:		; preds = %bb1514.i.i, %bb191.i.i
	%tmp176 = load i32* %b, align 4
	%tmp177 = and i32 %tmp176, 2
	%tmp178 = icmp eq i32 %tmp177, 0
        br i1 %tmp178, label %hello, label %world

hello:
	%h = tail call i32 (i8*, ...)* @printf( i8* getelementptr ([7 x i8]* @hello, i32 0, i32 0))
        ret void

world:
	%w = tail call i32 (i8*, ...)* @printf( i8* getelementptr ([7 x i8]* @world, i32 0, i32 0))
        ret void
}

declare i32 @printf(i8*, ...) nounwind


; Windows is not producing anything in the cache apparently, TBD
; XFAIL: win32

; RUN: opt -module-summary %s -o %t.bc
; RUN: opt -module-summary %p/Inputs/funcimport.ll -o %t2.bc

; Verify that enabling caching is working
; RUN: rm -Rf %t.cache && mkdir %t.cache
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc  %t.bc -thinlto-cache-dir %t.cache
; RUN: ls %t.cache/llvmcache.timestamp
; RUN: ls %t.cache | count 3

target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.11.0"

define void @globalfunc() #0 {
entry:
  ret void
}

Rework r269548, "XFAIL ThinLTO Caching test on Windows.", not to use XFAIL, for now.

; Windows is not producing anything in the cache apparently, TBD
; REQUIRES: shell

; RUN: opt -module-summary %s -o %t.bc
; RUN: opt -module-summary %p/Inputs/funcimport.ll -o %t2.bc

; Verify that enabling caching is working
; RUN: rm -Rf %t.cache && mkdir %t.cache
; RUN: llvm-lto -thinlto-action=run -exported-symbol=globalfunc %t2.bc  %t.bc -thinlto-cache-dir %t.cache
; RUN: ls %t.cache/llvmcache.timestamp
; RUN: ls %t.cache | count 3

target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.11.0"

define void @globalfunc() #0 {
entry:
  ret void
}


; RUN: llvm-as < %s | opt -indvars  | llvm-dis | grep -C1 Loop: | grep Canonical

; The indvar simplification code should ensure that the first PHI in the block
; is the canonical one!

int %test() {
	br label %Loop
Loop:
	%NonIndvar = phi int [200, %0], [%NonIndvarNext, %Loop]
	%Canonical = phi int [0, %0], [%CanonicalNext, %Loop]

	%NonIndvarNext = div int %NonIndvar, 2
	%CanonicalNext = add int %Canonical, 1
	br label %Loop
}

Tweak testcase to work with new indvars pass

; RUN: llvm-as < %s | opt -indvars  | llvm-dis | grep -C1 Loop: | grep %indvar

; The indvar simplification code should ensure that the first PHI in the block
; is the canonical one!

int %test() {
	br label %Loop
Loop:
	%NonIndvar = phi int [200, %0], [%NonIndvarNext, %Loop]
	%Canonical = phi int [0, %0], [%CanonicalNext, %Loop]

	%NonIndvarNext = div int %NonIndvar, 2
	%CanonicalNext = add int %Canonical, 1
	br label %Loop
}


; RUN: llvm-upgrade < %s | llvm-as | llvm-dis -o /dev/null &&
; RUN: llvm-upgrade < %s | llvm-as | llvm-dis | not grep bitcast

int %test1() {
   ret int bitcast(float 3.7 to int)
}

float %test2() {
  ret float bitcast(int 17 to float)
}

long %test3() {
  ret long bitcast (double 3.1415926 to long)
}

double %test4() {
  ret double bitcast (long 42 to double)
}

Fix a missing -f that the new llvm.exp found.

; RUN: llvm-upgrade < %s | llvm-as | llvm-dis -o /dev/null -f &&
; RUN: llvm-upgrade < %s | llvm-as | llvm-dis | not grep bitcast

int %test1() {
   ret int bitcast(float 3.7 to int)
}

float %test2() {
  ret float bitcast(int 17 to float)
}

long %test3() {
  ret long bitcast (double 3.1415926 to long)
}

double %test4() {
  ret double bitcast (long 42 to double)
}


; RUN: opt < %s -mtriple=x86_64-apple-macosx -pgo-instr-gen -instrprof -S | llc | FileCheck %s --check-prefix=MACHO-DIRECTIVE

target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"

; MACHO-DIRECTIVE: .weak_definition        ___llvm_profile_raw_version
define i32 @test_macho(i32 %i) {
entry:
  ret i32 %i
}

Fix buildbot failure from r268968.

; RUN: opt < %s -pgo-instr-gen -instrprof -S | llc | FileCheck %s --check-prefix=MACHO-DIRECTIVE

target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.11.0"

; MACHO-DIRECTIVE: .weak_definition        ___llvm_profile_raw_version
define i32 @test_macho(i32 %i) {
entry:
  ret i32 %i
}


; RUN: llc < %s -march=x86 -mattr=+sse | FileCheck %s
; RUN: llc < %s -march=x86 -mattr=+avx | FileCheck %s
; RUN: llc < %s -march=x86 -mattr=+prfchw | FileCheck %s -check-prefix=PRFCHW

; rdar://10538297

define void @t(i8* %ptr) nounwind  {
entry:
; CHECK: prefetcht2
; CHECK: prefetcht1
; CHECK: prefetcht0
; CHECK: prefetchnta
; PRFCHW: prefetchw
	tail call void @llvm.prefetch( i8* %ptr, i32 0, i32 1, i32 1 )
	tail call void @llvm.prefetch( i8* %ptr, i32 0, i32 2, i32 1 )
	tail call void @llvm.prefetch( i8* %ptr, i32 0, i32 3, i32 1 )
	tail call void @llvm.prefetch( i8* %ptr, i32 0, i32 0, i32 1 )
	tail call void @llvm.prefetch( i8* %ptr, i32 1, i32 3, i32 1 )
	ret void
}

declare void @llvm.prefetch(i8*, i32, i32, i32) nounwind

Fix PRFCHW test on non-x86 builds

; RUN: llc < %s -march=x86 -mattr=+sse | FileCheck %s
; RUN: llc < %s -march=x86 -mattr=+avx | FileCheck %s
; RUN: llc < %s -march=x86 -mattr=+sse -mattr=+prfchw | FileCheck %s -check-prefix=PRFCHW

; rdar://10538297

define void @t(i8* %ptr) nounwind  {
entry:
; CHECK: prefetcht2
; CHECK: prefetcht1
; CHECK: prefetcht0
; CHECK: prefetchnta
; PRFCHW: prefetchw
	tail call void @llvm.prefetch( i8* %ptr, i32 0, i32 1, i32 1 )
	tail call void @llvm.prefetch( i8* %ptr, i32 0, i32 2, i32 1 )
	tail call void @llvm.prefetch( i8* %ptr, i32 0, i32 3, i32 1 )
	tail call void @llvm.prefetch( i8* %ptr, i32 0, i32 0, i32 1 )
	tail call void @llvm.prefetch( i8* %ptr, i32 1, i32 3, i32 1 )
	ret void
}

declare void @llvm.prefetch(i8*, i32, i32, i32) nounwind


implementation

[[2 x int]] "test function"(int %i0, int %j0)
        %array = [[2 x int]] [
                   [2 x int] [ int 12, int 52 ]
                 ]
begin
	ret [[2x int]] %array
end

Add test of string constants

%somestr = [sbyte] c"hello world"
%somestr = [11x sbyte] c"hello world"

implementation

[[2 x int]] "test function"(int %i0, int %j0)
        %array = [[2 x int]] [
                   [2 x int] [ int 12, int 52 ]
                 ]
begin
	ret [[2x int]] %array
end

[sbyte] "other func"(int, double)
begin
	ret [sbyte] %somestr
end

[sbyte] "again"(float)
begin
	%cast = cast [11x sbyte] %somestr to [sbyte]
	ret [sbyte] %cast
end


; RUN: llc < %s -march=x86 -O0 | FileCheck %s
; PR7509
%asmtype = type { i32, i8*, i32, i32 }

; Arguments 1 and 4 must be the same. No other output arguments may be
; allocated %eax.

; CHECK: InlineAsm Start
; CHECK: arg1 %[[A1:...]]
; CHECK-NOT: ax
; CHECK: arg4 %[[A1]]
; CHECK: InlineAsm End

define i32 @func(i8* %s) nounwind ssp {
entry:
  %0 = tail call %asmtype asm "arg0 $0\0A\09arg1 $1\0A\09arg2 $2\0A\09arg3 $3\0A\09arg4 $4", "={ax},=r,=r,=r,1,~{dirflag},~{fpsr},~{flags}"(i8* %s) nounwind, !srcloc !0 ; <%0> [#uses=1]
  %asmresult = extractvalue %asmtype %0, 0              ; <i64> [#uses=1]
  ret i32 %asmresult
}

!0 = metadata !{i32 108}

Add a triple so test runs on Linux as well.

; RUN: llc < %s -march=x86 -O0 | FileCheck %s
; PR7509
target triple = "i386-apple-darwin10"
%asmtype = type { i32, i8*, i32, i32 }

; Arguments 1 and 4 must be the same. No other output arguments may be
; allocated %eax.

; CHECK: InlineAsm Start
; CHECK: arg1 %[[A1:...]]
; CHECK-NOT: ax
; CHECK: arg4 %[[A1]]
; CHECK: InlineAsm End

define i32 @func(i8* %s) nounwind ssp {
entry:
  %0 = tail call %asmtype asm "arg0 $0\0A\09arg1 $1\0A\09arg2 $2\0A\09arg3 $3\0A\09arg4 $4", "={ax},=r,=r,=r,1,~{dirflag},~{fpsr},~{flags}"(i8* %s) nounwind, !srcloc !0 ; <%0> [#uses=1]
  %asmresult = extractvalue %asmtype %0, 0              ; <i64> [#uses=1]
  ret i32 %asmresult
}

!0 = metadata !{i32 108}


; RUN: llc %s -mtriple=thumbv7-apple-darwin -mcpu=cortex-a9 -O0
; The following test is supposed to produce a VMOVQQQQ pseudo instruction.
; Make sure that it gets expanded; otherwise, the compile fails when trying
; to print the pseudo-instruction.

define void @test_vmovqqqq_pseudo() nounwind ssp {
entry:
  %vld3_lane = call { <8 x i16>, <8 x i16>, <8 x i16> } @llvm.arm.neon.vld3lane.v8i16(i8* undef, <8 x i16> undef, <8 x i16> undef, <8 x i16> zeroinitializer, i32 7, i32 2)
  store { <8 x i16>, <8 x i16>, <8 x i16> } %vld3_lane, { <8 x i16>, <8 x i16>, <8 x i16> }* undef
  ret void
}

declare { <8 x i16>, <8 x i16>, <8 x i16> } @llvm.arm.neon.vld3lane.v8i16(i8*, <8 x i16>, <8 x i16>, <8 x i16>, i32, i32) nounwind readonly

Fix this test to avoid leaving a temporary file behind.

; RUN: llc %s -mtriple=thumbv7-apple-darwin -mcpu=cortex-a9 -O0 -o -
; The following test is supposed to produce a VMOVQQQQ pseudo instruction.
; Make sure that it gets expanded; otherwise, the compile fails when trying
; to print the pseudo-instruction.

define void @test_vmovqqqq_pseudo() nounwind ssp {
entry:
  %vld3_lane = call { <8 x i16>, <8 x i16>, <8 x i16> } @llvm.arm.neon.vld3lane.v8i16(i8* undef, <8 x i16> undef, <8 x i16> undef, <8 x i16> zeroinitializer, i32 7, i32 2)
  store { <8 x i16>, <8 x i16>, <8 x i16> } %vld3_lane, { <8 x i16>, <8 x i16>, <8 x i16> }* undef
  ret void
}

declare { <8 x i16>, <8 x i16>, <8 x i16> } @llvm.arm.neon.vld3lane.v8i16(i8*, <8 x i16>, <8 x i16>, <8 x i16>, i32, i32) nounwind readonly


; RUN: llvm-as -o %t.bc %s
; RUN: llvm-lto -exported-symbol=foo -exported-symbol=bar -j2 -o %t.o %t.bc
; RUN: llvm-nm %t.o.0 | FileCheck --check-prefix=CHECK0 %s
; RUN: llvm-nm %t.o.1 | FileCheck --check-prefix=CHECK1 %s

; FIXME: Investigate test failures on these architecures.
; XFAIL: mips, mipsel, aarch64

target triple = "x86_64-unknown-linux-gnu"

; CHECK0-NOT: bar
; CHECK0: T foo
; CHECK0-NOT: bar
define void @foo() {
  call void @bar()
  ret void
}

; CHECK1-NOT: foo
; CHECK1: T bar
; CHECK1-NOT: foo
define void @bar() {
  call void @foo()
  ret void
}

Use UNSUPPORTED instead of XFAIL to disable this test, as it passes on one AArch64 bot.

; RUN: llvm-as -o %t.bc %s
; RUN: llvm-lto -exported-symbol=foo -exported-symbol=bar -j2 -o %t.o %t.bc
; RUN: llvm-nm %t.o.0 | FileCheck --check-prefix=CHECK0 %s
; RUN: llvm-nm %t.o.1 | FileCheck --check-prefix=CHECK1 %s

; FIXME: Investigate test failures on these architecures.
; UNSUPPORTED: mips, mipsel, aarch64

target triple = "x86_64-unknown-linux-gnu"

; CHECK0-NOT: bar
; CHECK0: T foo
; CHECK0-NOT: bar
define void @foo() {
  call void @bar()
  ret void
}

; CHECK1-NOT: foo
; CHECK1: T bar
; CHECK1-NOT: foo
define void @bar() {
  call void @foo()
  ret void
}


; Make sure this testcase codegens to the zapnot instruction
; RUN: llvm-as < %s | llc -march=alpha | grep 'zapnot'

implementation   ; Functions:

long %bar(long %x) {
entry:
	%tmp.1 = and long %x, 255  		; <long> [#uses=1]
	ret long %tmp.1
}

Change this regression so andi is not a valid codegen of it

; Make sure this testcase codegens to the zapnot instruction
; RUN: llvm-as < %s | llc -march=alpha | grep 'zapnot'

implementation   ; Functions:

long %bar(long %x) {
entry:
	%tmp.1 = and long %x, 16711935 		; <long> [#uses=1]
	ret long %tmp.1
}


; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 | grep shufps

void %test_v4sf(<4 x float>* %P, float %X, float %Y) {
	%tmp = insertelement <4 x float> zeroinitializer, float %X, uint 0
	%tmp2 = insertelement <4 x float> %tmp, float %X, uint 1
	%tmp4 = insertelement <4 x float> %tmp2, float %Y, uint 2
	%tmp6 = insertelement <4 x float> %tmp4, float %Y, uint 3
	store <4 x float> %tmp6, <4 x float>* %P
	ret void
}

Add a v2f64 shuffle case.

; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 | grep shufp | wc -l | grep 1
; RUN: llvm-as < %s | llc -march=x86 -mattr=+sse2 | grep movlhps

void %test_v4sf(<4 x float>* %P, float %X, float %Y) {
	%tmp = insertelement <4 x float> zeroinitializer, float %X, uint 0
	%tmp2 = insertelement <4 x float> %tmp, float %X, uint 1
	%tmp4 = insertelement <4 x float> %tmp2, float %Y, uint 2
	%tmp6 = insertelement <4 x float> %tmp4, float %Y, uint 3
	store <4 x float> %tmp6, <4 x float>* %P
	ret void
}

void %test_v2sd(<2 x double>* %P, double %X, double %Y) {
	%tmp = insertelement <2 x double> zeroinitializer, double %X, uint 0
	%tmp2 = insertelement <2 x double> %tmp, double %Y, uint 1
	store <2 x double> %tmp2, <2 x double>* %P
	ret void
}


; RUN: llvm-as < %s | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll

%ZFunTy = type i32(i8 zext)
%SFunTy = type i32(i8 sext)

declare i16 @"test"(i16 sext %arg) sext
declare i8 @"test2" (i16 zext %a2) zext

implementation

define i32 @main(i32 %argc, i8 **%argv) {
    %val = trunc i32 %argc to i16
    %res1 = call i16 (i16 sext) sext *@test(i16 %val)
    %two = add i16 %res1, %res1
    %res2 = call i8 @test2(i16 %two zext) zext
    %retVal = sext i16 %two to i32
    ret i32 %retVal
}

Add tests for nounwind and noreturn function attributes.

; RUN: llvm-as < %s | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll

%ZFunTy = type i32(i8 zext)
%SFunTy = type i32(i8 sext)

declare i16 @"test"(i16 sext %arg) sext
declare i8 @"test2" (i16 zext %a2) zext

declare void @exit(i32) noreturn nounwind

define i32 @main(i32 %argc, i8 **%argv) nounwind inreg {
    %val = trunc i32 %argc to i16
    %res1 = call i16 (i16 sext) sext *@test(i16 %val)
    %two = add i16 %res1, %res1
    %res2 = call i8 @test2(i16 %two zext) zext
    %retVal = sext i16 %two to i32
    ret i32 %retVal
}


; RUN: llvm-as < %s | llc -march=c | \
; RUN:   grep 'return ((((ltmp_2_2 == (signed int)ltmp_1_2)) ?  (1) : (0)))'
; For PR1099
; XFAIL: *

target datalayout = "e-p:32:32"
target triple = "i686-apple-darwin8"
        %struct.Connector = type { i16, i16, i8, i8, %struct.Connector*, i8* }

implementation   ; Functions:

define bool @prune_match_entry_2E_ce(%struct.Connector* %a, i16 %b.0.0.val) {
newFuncRoot:
        br label %entry.ce

cond_next.exitStub:             ; preds = %entry.ce
        ret bool true

entry.return_crit_edge.exitStub:                ; preds = %entry.ce
        ret bool false

entry.ce:               ; preds = %newFuncRoot
        %tmp = getelementptr %struct.Connector* %a, i32 0, i32 0                ; <i16*> [#uses=1]
        %tmp = load i16* %tmp           ; <i16> [#uses=1]
        %tmp = icmp eq i16 %tmp, %b.0.0.val             ; <bool> [#uses=1]
        br bool %tmp, label %cond_next.exitStub, label %entry.return_crit_edge.exitStub
}

Update this test to compile properly and check against the correct string generated by the CBE. This is no longer an XFAIL.

; For PR1099
; RUN: llvm-as < %s | llc -march=c | \
; RUN:   grep 'return ((((ltmp_2_2 == ltmp_1_2)) ? (1) : (0)))'

target datalayout = "e-p:32:32"
target triple = "i686-apple-darwin8"
        %struct.Connector = type { i16, i16, i8, i8, %struct.Connector*, i8* }

implementation   ; Functions:

define i1 @prune_match_entry_2E_ce(%struct.Connector* %a, i16 %b.0.0.val) {
newFuncRoot:
        br label %entry.ce

cond_next.exitStub:             ; preds = %entry.ce
        ret i1 true

entry.return_crit_edge.exitStub:                ; preds = %entry.ce
        ret i1 false

entry.ce:               ; preds = %newFuncRoot
        %tmp1 = getelementptr %struct.Connector* %a, i32 0, i32 0                ; <i16*> [#uses=1]
        %tmp2 = load i16* %tmp1           ; <i16> [#uses=1]
        %tmp3 = icmp eq i16 %tmp2, %b.0.0.val             ; <i1> [#uses=1]
        br i1 %tmp3, label %cond_next.exitStub, label %entry.return_crit_edge.exitStub
}


; RUN: llvm-as < %s | \
; RUN:   llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
; RUN: grep {call	__fixunsxfti@PLT} %t1

define i128 @f(x86_fp80 %a)  {
entry:
	%tmp78 = fptoui x86_fp80 %a to i128
	ret i128 %tmp78
}

Add nounwind to this test.

; RUN: llvm-as < %s | \
; RUN:   llc -mtriple=x86_64-pc-linux -relocation-model=pic -o %t1 -f
; RUN: grep {call	__fixunsxfti@PLT} %t1

define i128 @f(x86_fp80 %a) nounwind {
entry:
	%tmp78 = fptoui x86_fp80 %a to i128
	ret i128 %tmp78
}


; RUN: llvm-as < %s | llc -march=x86 -x86-asm-syntax=intel -enable-x86-fastcc  | grep 'add %ESP, 8'

declare fastcc void %func(int %X, long %Y)

fastcc void %caller(int, long) {
	tail call fastcc void %func(int 1234567890, long 0)
	ret void
}

Make sure this is not eligible for tail-call-elimination so that we test the correct thing.

; RUN: llvm-as < %s | llc -march=x86 -x86-asm-syntax=intel -enable-x86-fastcc  | grep 'add %ESP, 8'

declare fastcc void %func(int *%X, long %Y)

fastcc void %caller(int, long) {
	%X = alloca int
	call fastcc void %func(int* %X, long 0)   ;; not a tail call
	ret void
}


; RUN: llc -march=x86-64 -mcpu=core2 -enable-misched -misched=shuffle -misched-bottomup < %s
; REQUIRES: asserts
;
; Interesting MachineScheduler cases.
;
; FIXME: There should be an assert in the coalescer that we're not rematting
; "not-quite-dead" copies, but that breaks a lot of tests <rdar://problem/11148682>.

declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind

; From oggenc.
; After coalescing, we have a dead superreg (RAX) definition.
;
; CHECK: xorl %esi, %esi
; CHECK: movl $32, %ecx
; CHECK: rep;movsl
define fastcc void @_preextrapolate_helper() nounwind uwtable ssp {
entry:
  br i1 undef, label %for.cond.preheader, label %if.end

for.cond.preheader:                               ; preds = %entry
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* undef, i8* null, i64 128, i32 4, i1 false) nounwind
  unreachable

if.end:                                           ; preds = %entry
  ret void
}

Check output of the misched unit tests

; RUN: llc < %s -march=x86-64 -mcpu=core2 -enable-misched \
; RUN:          -misched=shuffle -misched-bottomup | FileCheck %s
; REQUIRES: asserts
;
; Interesting MachineScheduler cases.
;
; FIXME: There should be an assert in the coalescer that we're not rematting
; "not-quite-dead" copies, but that breaks a lot of tests <rdar://problem/11148682>.

declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind

; From oggenc.
; After coalescing, we have a dead superreg (RAX) definition.
;
; CHECK: xorl %esi, %esi
; CHECK: movl $32, %ecx
; CHECK: rep;movsl
define fastcc void @_preextrapolate_helper() nounwind uwtable ssp {
entry:
  br i1 undef, label %for.cond.preheader, label %if.end

for.cond.preheader:                               ; preds = %entry
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* undef, i8* null, i64 128, i32 4, i1 false) nounwind
  unreachable

if.end:                                           ; preds = %entry
  ret void
}


; Verify that auto-upgrading intrinsics works with Lazy loaded bitcode
; Do setup work for all below tests: generate bitcode and combined index
; RUN: opt -module-summary %s -o %t.bc

; We can't use llvm-dis here, because it would do the autoupgrade itself.

; RUN: llvm-link  -summary-index=%t3.bc \
; RUN:            -import=globalfunc1:%p/Inputs/autoupgrade.bc %t.bc \
; RUN:     | llvm-bcanalyzer -dump | FileCheck %s

; CHECK-NOT: 'llvm.invariant.start'
; CHECK: record string = 'llvm.invariant.start.p0i8'
; CHECK-NOT: 'llvm.invariant.start'

target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.11.0"

define i32 @main() #0 {
entry:
  call void (...) @globalfunc1()
  ret i32 0
}

declare void @globalfunc1(...) #1

Fix test change in r290736: restore index generation

; Verify that auto-upgrading intrinsics works with Lazy loaded bitcode
; Do setup work for all below tests: generate bitcode and combined index
; RUN: opt -module-summary %s -o %t.bc
; RUN: llvm-lto -thinlto-action=thinlink -o %t3.bc %t.bc %p/Inputs/autoupgrade.bc

; We can't use llvm-dis here, because it would do the autoupgrade itself.

; RUN: llvm-link  -summary-index=%t3.bc \
; RUN:            -import=globalfunc1:%p/Inputs/autoupgrade.bc %t.bc \
; RUN:     | llvm-bcanalyzer -dump | FileCheck %s

; CHECK-NOT: 'llvm.invariant.start'
; CHECK: record string = 'llvm.invariant.start.p0i8'
; CHECK-NOT: 'llvm.invariant.start'

target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.11.0"

define i32 @main() #0 {
entry:
  call void (...) @globalfunc1()
  ret i32 0
}

declare void @globalfunc1(...) #1


; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
; RUN: ld.lld -m elf_x86_64 %t.o -o %t -save-temps
; RUN: llvm-dis %t.0.4.opt.bc -o - | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

module asm ".weak patatino"
module asm ".equ patatino, foo"

declare void @patatino()

define void @foo() {
  ret void
}

define void @_start() {
  call void @patatino()
  ret void
}

; CHECK: @llvm.compiler.used = appending global [1 x i8*] [i8* bitcast (void ()* @foo to i8*)], section "llvm.metadata"
; CHECK: define internal void @foo

Mark undefined module asm symbols as used.

; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
; RUN: ld.lld -m elf_x86_64 %t.o -o %t -save-temps
; RUN: llvm-dis %t.0.4.opt.bc -o - | FileCheck %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

module asm ".weak patatino"
module asm ".equ patatino, foo"

declare void @patatino()

define void @foo() {
  ret void
}

define void @_start() {
  call void @patatino()
  ret void
}

; CHECK: define void @foo


; RUN: llvm-upgrade %s | llvm-as | llc

;;
;; Test the sequence:
;;	cast -> setle 0, %cast -> br %cond
;; This sequence should cause the cast value to be forwarded twice,
;; i.e., cast is forwarded to the setle and teh setle is forwarded
;; to the branch.
;; register argument of the "branch-on-register" instruction, i.e.,
;;
;; This produces the bogus output instruction:
;;	brlez   <NULL VALUE>, .L_SumArray_bb3.
;; This came from %bb1 of sumarrray.ll generated from sumarray.c.

int %SumArray(int %Num) {
        %Num = alloca int
        br label %Top
Top:
        store int %Num, int * %Num
        %reg108 = load int * %Num
        %cast1006 = cast int %reg108 to uint
        %cond1001 = setle uint %cast1006, 0
	br bool %cond1001, label %bb6, label %Top

bb6:
	ret int 42
}

Fix a typo in a comment.

; RUN: llvm-upgrade %s | llvm-as | llc

;;
;; Test the sequence:
;;	cast -> setle 0, %cast -> br %cond
;; This sequence should cause the cast value to be forwarded twice,
;; i.e., cast is forwarded to the setle and the setle is forwarded
;; to the branch.
;; register argument of the "branch-on-register" instruction, i.e.,
;;
;; This produces the bogus output instruction:
;;	brlez   <NULL VALUE>, .L_SumArray_bb3.
;; This came from %bb1 of sumarrray.ll generated from sumarray.c.

int %SumArray(int %Num) {
        %Num = alloca int
        br label %Top
Top:
        store int %Num, int * %Num
        %reg108 = load int * %Num
        %cast1006 = cast int %reg108 to uint
        %cond1001 = setle uint %cast1006, 0
	br bool %cond1001, label %bb6, label %Top

bb6:
	ret int 42
}


; RUN: llc < %s -mtriple=x86_64-linux-gnux32 -fast-isel -fast-isel-abort -regalloc=fast | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-nacl -fast-isel -fast-isel-abort -regalloc=fast | FileCheck %s

; Test that alloca addresses are materialized with the right size instruction.

declare void @bar(i32* %arg)

; CHECK-LABEL: @foo
define void @foo() {
  %a = alloca i32
; CHECK: leal {{.*}}, %edi
  call void @bar(i32* %a)
  ret void
}

Fix test breakage from r221386

; RUN: llc < %s -mtriple=x86_64-linux-gnux32 -fast-isel -fast-isel-abort | FileCheck %s
; RUN: llc < %s -mtriple=x86_64-nacl -fast-isel -fast-isel-abort | FileCheck %s

; Test that alloca addresses are materialized with the right size instruction.

declare void @bar(i32* %arg)

; CHECK-LABEL: @foo
define void @foo() {
  %a = alloca i32
; CHECK: leal {{.*}}, %edi
  call void @bar(i32* %a)
  ret void
}


; RUN: opt < %s -licm -disable-output
define void @foo (i8* %v)
{
  entry:
    br i1 undef, label %preheader, label %return

  preheader:
    br i1 undef, label %loop, label %return

  loop:
    indirectbr i8* undef, [label %preheader, label %stuff]

  stuff:
    %0 = load i8* undef, align 1
    br label %loop

  return:
    ret void

}

Add radar fixed in comment.

; Test for rdar://7452967
; RUN: opt < %s -licm -disable-output
define void @foo (i8* %v)
{
  entry:
    br i1 undef, label %preheader, label %return

  preheader:
    br i1 undef, label %loop, label %return

  loop:
    indirectbr i8* undef, [label %preheader, label %stuff]

  stuff:
    %0 = load i8* undef, align 1
    br label %loop

  return:
    ret void

}


; RUN: llc < %s -mcpu=cortex-a8 -march=arm -asm-verbose=false | FileCheck %s

define zeroext i1 @test0(i32 %x) nounwind {
; CHECK-LABEL: test0:
; CHECK-NEXT: .fnstart
; CHECK-NEXT: add [[REG:(r[0-9]+)|(lr)]], r0, #1
; CHECK-NEXT: mov r0, #0
; CHECK-NEXT: cmp [[REG]], #1
; CHECK-NEXT: movwhi r0, #1
; CHECK-NEXT: bx  lr
  %cmp1 = icmp ne i32 %x, -1
  %not.cmp = icmp ne i32 %x, 0
  %.cmp1 = and i1 %cmp1, %not.cmp
  ret i1 %.cmp1
}

Fix Darwin bots from EHABI change

; RUN: llc < %s -mcpu=cortex-a8 -march=arm -asm-verbose=false | FileCheck %s

define zeroext i1 @test0(i32 %x) nounwind {
; CHECK-LABEL: test0:
; CHECK: add [[REG:(r[0-9]+)|(lr)]], r0, #1
; CHECK-NEXT: mov r0, #0
; CHECK-NEXT: cmp [[REG]], #1
; CHECK-NEXT: movwhi r0, #1
; CHECK-NEXT: bx  lr
  %cmp1 = icmp ne i32 %x, -1
  %not.cmp = icmp ne i32 %x, 0
  %.cmp1 = and i1 %cmp1, %not.cmp
  ret i1 %.cmp1
}


; Test to ensure that non-prevailing weak aliasee is kept as a weak definition
; when the alias is not dead.
; RUN: opt -module-summary %s -o %t1.bc
; RUN: llvm-lto2 run %t1.bc \
; RUN:	 -r=%t1.bc,__a,lx \
; RUN:	 -r=%t1.bc,__b,l \
; RUN:	 -r=%t1.bc,a,plx \
; RUN:	 -r=%t1.bc,b,pl \
; RUN:   -o %t2.o -save-temps

; Check that __a is kept as a weak def. __b can be dropped since its alias is
; not live and will also be dropped.
; RUN: llvm-dis %t2.o.1.1.promote.bc -o - | FileCheck %s
; CHECK: define weak hidden void @__a
; CHECK: declare hidden void @__b
; CHECK: declare void @b

target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-linux-gnu"

@a = hidden alias void (), void ()* @__a

define weak hidden void @__a() {
entry:
  ret void
}

@b = hidden alias void (), void ()* @__b

define weak hidden void @__b() {
entry:
  ret void
}

Fix target for new X86 test

; Test to ensure that non-prevailing weak aliasee is kept as a weak definition
; when the alias is not dead.
; RUN: opt -module-summary %s -o %t1.bc
; RUN: llvm-lto2 run %t1.bc \
; RUN:	 -r=%t1.bc,__a,lx \
; RUN:	 -r=%t1.bc,__b,l \
; RUN:	 -r=%t1.bc,a,plx \
; RUN:	 -r=%t1.bc,b,pl \
; RUN:   -o %t2.o -save-temps

; Check that __a is kept as a weak def. __b can be dropped since its alias is
; not live and will also be dropped.
; RUN: llvm-dis %t2.o.1.1.promote.bc -o - | FileCheck %s
; CHECK: define weak hidden void @__a
; CHECK: declare hidden void @__b
; CHECK: declare void @b

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@a = hidden alias void (), void ()* @__a

define weak hidden void @__a() {
entry:
  ret void
}

@b = hidden alias void (), void ()* @__b

define weak hidden void @__b() {
entry:
  ret void
}


; RUN: llc < %s -march=x86-64 -disable-mmx | grep punpcklwd | count 2

define void @foo() nounwind {
  %cti69 = trunc <8 x i32> undef to <8 x i16>     ; <<8 x i16>> [#uses=1]
  store <8 x i16> %cti69, <8 x i16>* undef
  ret void
}

define void @bar() nounwind {
  %cti44 = trunc <4 x i32> undef to <4 x i16>     ; <<4 x i16>> [#uses=1]
  store <4 x i16> %cti44, <4 x i16>* undef
  ret void
}

Make this test less fragile.

; RUN: llc < %s -march=x86-64 -disable-mmx >/dev/null

define void @foo(<8 x i32>* %p) nounwind {
  %t = load <8 x i32>* %p
  %cti69 = trunc <8 x i32> %t to <8 x i16>     ; <<8 x i16>> [#uses=1]
  store <8 x i16> %cti69, <8 x i16>* undef
  ret void
}

define void @bar(<4 x i32>* %p) nounwind {
  %t = load <4 x i32>* %p
  %cti44 = trunc <4 x i32> %t to <4 x i16>     ; <<4 x i16>> [#uses=1]
  store <4 x i16> %cti44, <4 x i16>* undef
  ret void
}


; Demonstrate all of the variable argument handling intrinsic functions plus
; the va_arg instruction.

implementation
declare void %llvm.va_start(sbyte**, ...)
declare void %llvm.va_copy(sbyte**, sbyte*)
declare void %llvm.va_end(sbyte**)

int %test(int %X, ...) {
	%ap = alloca sbyte*
	%aq = alloca sbyte*
	call void (sbyte**, ...)* %llvm.va_start(sbyte** %ap, int %X)
	%apv = load sbyte** %ap
	call void %llvm.va_copy(sbyte** %aq, sbyte* %apv)
	call void %llvm.va_end(sbyte** %aq)

	%tmp = va_arg sbyte** %ap, int

	call void %llvm.va_end(sbyte** %ap)
	ret int %tmp
}

Update test to new style

; Demonstrate all of the variable argument handling intrinsic functions plus
; the va_arg instruction.

implementation
declare sbyte* %llvm.va_start()
declare sbyte* %llvm.va_copy(sbyte*)
declare void %llvm.va_end(sbyte*)

int %test(int %X, ...) {
	%ap = call sbyte* %llvm.va_start()
	%aq = call sbyte* %llvm.va_copy(sbyte* %ap)
	call void %llvm.va_end(sbyte* %aq)

	%tmp = vaarg sbyte* %ap, int
	%ap2 = vanext sbyte* %ap, int

	call void %llvm.va_end(sbyte* %ap2)
	ret int %tmp
}


; RUN: llvm-as < %s | llc -x86-asm-syntax=intel -enable-x86-fastcc | not grep call

fastcc int %bar(int %X, int(double, int) *%FP) {
     %Y = tail call fastcc int %FP(double 0.0, int %X)
     ret int %Y
}

Fix this to test the BE we care about

; RUN: llvm-as < %s | llc -march=x86 -x86-asm-syntax=intel -enable-x86-fastcc | not grep call

fastcc int %bar(int %X, int(double, int) *%FP) {
     %Y = tail call fastcc int %FP(double 0.0, int %X)
     ret int %Y
}


; RUN: opt -module-summary %s -o %t.o
; RUN: opt -module-summary %p/Inputs/thin1.ll -o %t.coll.o
; RUN: llvm-ar rcs %t1.a %t.coll.o
; RUN: opt -module-summary %p/Inputs/thin2.ll -o %t.coll.o
; RUN: llvm-ar rcsc %t2.a %t.coll.o

; RUN: ld.lld %t.o %t1.a %t2.a -o %t
; RUN: llvm-nm %t | FileCheck %s

; CHECK: T _start
; CHECK: T blah
; CHECK: T foo

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-scei-ps4"

define i32 @_start() {
entry:
  %call = call i32 @foo(i32 23)
  %call1 = call i32 @blah(i32 37)
  ret i32 0
}

declare i32 @foo(i32) #1
declare i32 @blah(i32) #1

Test we handle collisions correctly in presence of --whole-archive.

; RUN: opt -module-summary %s -o %t.o
; RUN: opt -module-summary %p/Inputs/thin1.ll -o %t.coll.o
; RUN: llvm-ar rcs %t1.a %t.coll.o
; RUN: opt -module-summary %p/Inputs/thin2.ll -o %t.coll.o
; RUN: llvm-ar rcsc %t2.a %t.coll.o

; RUN: ld.lld %t.o %t1.a %t2.a -o %t
; RUN: llvm-nm %t | FileCheck %s

; Check we handle this case correctly even in presence of --whole-archive.
; RUN: ld.lld %t.o --whole-archive %t1.a %t2.a -o %t
; RUN: llvm-nm %t | FileCheck %s

; CHECK: T _start
; CHECK: T blah
; CHECK: T foo

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-scei-ps4"

define i32 @_start() {
entry:
  %call = call i32 @foo(i32 23)
  %call1 = call i32 @blah(i32 37)
  ret i32 0
}

declare i32 @foo(i32) #1
declare i32 @blah(i32) #1


; RUN: llc < %s -march=r600 -mcpu=redwood -show-mc-encoding -o - | FileCheck --check-prefix=EG-CHECK %s
; RUN: llc < %s -march=r600 -mcpu=rv710 -show-mc-encoding -o - | FileCheck --check-prefix=R600-CHECK %s

; EG-CHECK: @call_fs
; EG-CHECK: CALL_FS  ; encoding: [0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x84]
; R600-CHECK: @call_fs
; R600-CHECK:CALL_FS ; encoding: [0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x89]

define void @call_fs() #0 {
  ret void
}

attributes #0 = { "ShaderType"="1" } ; Vertex Shader

Add a test for r183108

; RUN: llc < %s -march=r600 -mcpu=redwood -show-mc-encoding -o - | FileCheck --check-prefix=EG-CHECK %s
; RUN: llc < %s -march=r600 -mcpu=rv710 -show-mc-encoding -o - | FileCheck --check-prefix=R600-CHECK %s

; EG-CHECK: @call_fs
; EG-CHECK: .long 257
; EG-CHECK: CALL_FS  ; encoding: [0x00,0x00,0x00,0x00,0x00,0x00,0xc0,0x84]
; R600-CHECK: @call_fs
; R600-CHECK: .long 257
; R600-CHECK:CALL_FS ; encoding: [0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x89]

define void @call_fs() #0 {
  ret void
}

attributes #0 = { "ShaderType"="1" } ; Vertex Shader


; RUN: opt -mtriple=x86_64-pc-win32-coff %s -o - | lli

@o = common global i32 0, align 4

define i32 @main() {
  %patatino = load i32, i32* @o, align 4
  ret i32 %patatino
}

Make this test Windows-only (try to placate buildbots).

; REQUIRES: system-windows
; RUN: opt -mtriple=x86_64-pc-win32-coff %s -o - | lli

@o = common global i32 0, align 4

define i32 @main() {
  %patatino = load i32, i32* @o, align 4
  ret i32 %patatino
}


; RUN: llc < %s -march=thumb -mattr=+thumb2 | FileCheck %s

define void @test1() {
; CHECK: test1:
; CHECK: sub sp, #256
    %tmp = alloca [ 64 x i32 ] , align 4
    ret void
}

define void @test2() {
; CHECK: test2:
; CHECK: sub.w sp, sp, #4160
; CHECK: sub sp, #8
    %tmp = alloca [ 4168 x i8 ] , align 4
    ret void
}

define i32 @test3() {
; CHECK: test3:
; CHECK: sub.w sp, sp, #805306368
; CHECK: sub sp, #20
    %retval = alloca i32, align 4
    %tmp = alloca i32, align 4
    %a = alloca [805306369 x i8], align 16
    store i32 0, i32* %tmp
    %tmp1 = load i32* %tmp
    ret i32 %tmp1
}

Make this test pass on Linux.

; RUN: llc < %s -march=thumb -mattr=+thumb2 -mtriple=arm-apple-darwin | FileCheck %s -check-prefix=DARWIN
; RUN: llc < %s -march=thumb -mattr=+thumb2 -mtriple=arm-linux-gnueabi | FileCheck %s -check-prefix=LINUX

define void @test1() {
; DARWIN: test1:
; DARWIN: sub sp, #256
; LINUX: test1:
; LINUX: sub sp, #256
    %tmp = alloca [ 64 x i32 ] , align 4
    ret void
}

define void @test2() {
; DARWIN: test2:
; DARWIN: sub.w sp, sp, #4160
; DARWIN: sub sp, #8
; LINUX: test2:
; LINUX: sub.w sp, sp, #4160
; LINUX: sub sp, #8
    %tmp = alloca [ 4168 x i8 ] , align 4
    ret void
}

define i32 @test3() {
; DARWIN: test3:
; DARWIN: push    {r4, r7, lr}
; DARWIN: sub.w sp, sp, #805306368
; DARWIN: sub sp, #20
; LINUX: test3:
; LINUX: stmfd   sp!, {r4, r7, r11, lr}
; LINUX: sub.w sp, sp, #805306368
; LINUX: sub sp, #16
    %retval = alloca i32, align 4
    %tmp = alloca i32, align 4
    %a = alloca [805306369 x i8], align 16
    store i32 0, i32* %tmp
    %tmp1 = load i32* %tmp
    ret i32 %tmp1
}


; RUN: llc -mtriple=thumbv7-linux-gnueabihf -o - -show-mc-encoding -t2-reduce-limit2=0 %s | FileCheck %s
; RUN: llc -mtriple=thumbv7-linux-gnueabihf -o - -show-mc-encoding %s | FileCheck %s --check-prefix=CHECK-OPT

define i32 @and(i32 %a, i32 %b) nounwind readnone {
; CHECK-LABEL: and:
; CHECK: and.w r{{[0-9]+}}, r{{[0-9]+}}, r{{[0-9]+}} @ encoding: [{{0x..,0x..,0x..,0x..}}]
; CHECK-OPT: ands r{{[0-7]}}, r{{[0-7]}} @ encoding: [{{0x..,0x..}}]
entry:
  %and = and i32 %b, %a
  ret i32 %and
}

Add Thumb-2 code size optimization test for ASR (immediate).

; RUN: llc -mtriple=thumbv7-linux-gnueabihf -o - -show-mc-encoding -t2-reduce-limit=0 -t2-reduce-limit2=0 %s | FileCheck %s
; RUN: llc -mtriple=thumbv7-linux-gnueabihf -o - -show-mc-encoding %s | FileCheck %s --check-prefix=CHECK-OPT

define i32 @and(i32 %a, i32 %b) nounwind readnone {
; CHECK-LABEL: and:
; CHECK: and.w r{{[0-9]+}}, r{{[0-9]+}}, r{{[0-9]+}} @ encoding: [{{0x..,0x..,0x..,0x..}}]
; CHECK-OPT: ands r{{[0-7]}}, r{{[0-7]}} @ encoding: [{{0x..,0x..}}]
entry:
  %and = and i32 %b, %a
  ret i32 %and
}

define i32 @asr-imm(i32 %a) nounwind readnone {
; CHECK-LABEL: "asr-imm":
; CHECK: asr.w r{{[0-9]+}}, r{{[0-9]+}}, #13 @ encoding: [{{0x..,0x..,0x..,0x..}}]
; CHECK-OPT: asrs r{{[0-7]}}, r{{[0-7]}}, #13 @ encoding: [{{0x..,0x..}}]
entry:
  %shr = ashr i32 %a, 13
  ret i32 %shr
}


; RUN: %clang_cc1 -S -emit-llvm -o - -fexperimental-new-pass-manager -fsanitize=address -triple=x86_64-linux %s | FileCheck %s

; CHECK: @llvm.global_ctors = {{.*}}@asan.module_ctor
; CHECK: declare void @__asan_loadN

define i32 @test_load(i32* %a) sanitize_address {
entry:
  %tmp1 = load i32, i32* %a, align 4
  ret i32 %tmp1
}

Fix for arm bots afternew PM pass port. Prevent cross compiling on arm.

; RUN: %clang_cc1 -S -emit-llvm -o - -fexperimental-new-pass-manager -fsanitize=address %s | FileCheck %s

; CHECK: @llvm.global_ctors = {{.*}}@asan.module_ctor
; CHECK: declare void @__asan_loadN

define i32 @test_load(i32* %a) sanitize_address {
entry:
  %tmp1 = load i32, i32* %a, align 4
  ret i32 %tmp1
}


; RUN: llvm-as < %s | llc -march=x86 -join-subclass-copies -stats |& grep {Number of subclass joins performed}

@mem.6 = external global i64		; <i64*> [#uses=1]

define i64 @attachFunc() nounwind  {
entry:
	%tmp64.i = add i64 0, 72		; <i64> [#uses=1]
	%tmp68.i = load i64* @mem.6, align 8		; <i64> [#uses=1]
	%tmp70.i = icmp sgt i64 %tmp64.i, %tmp68.i		; <i1> [#uses=1]
	br i1 %tmp70.i, label %bb73.i, label %bb116

bb73.i:		; preds = %entry
	br label %bb116

bb116:		; preds = %bb73.i, %entry
	ret i64 %tmp68.i
}

Update test to reflect command line option name change.

; RUN: llvm-as < %s | llc -march=x86 -join-cross-class-copies -stats |& grep {Number of cross class joins performed}

@mem.6 = external global i64		; <i64*> [#uses=1]

define i64 @attachFunc() nounwind  {
entry:
	%tmp64.i = add i64 0, 72		; <i64> [#uses=1]
	%tmp68.i = load i64* @mem.6, align 8		; <i64> [#uses=1]
	%tmp70.i = icmp sgt i64 %tmp64.i, %tmp68.i		; <i1> [#uses=1]
	br i1 %tmp70.i, label %bb73.i, label %bb116

bb73.i:		; preds = %entry
	br label %bb116

bb116:		; preds = %bb73.i, %entry
	ret i64 %tmp68.i
}


; RUN: llvm-as < %s | opt -scalar-evolution -analyze | not grep Unpredictable

define void @foo(i32 %n) {
entry:
	br label %header
header:
	%i = phi i32 [ 0, %entry ], [ %i.inc, %next ]
	%cond = icmp sgt i32 %n, %i
	br i1 %cond, label %next, label %return
next:
        %i.inc = add i32 %i, 1
	br label %header
return:
	ret void
}

Change negative grep into positive one in my yesterday's testcase.

; RUN: llvm-as < %s | opt -scalar-evolution -analyze | grep {Loop header: ( 0 smax  %n) iterations!}

define void @foo(i32 %n) {
entry:
	br label %header
header:
	%i = phi i32 [ 0, %entry ], [ %i.inc, %next ]
	%cond = icmp sgt i32 %n, %i
	br i1 %cond, label %next, label %return
next:
        %i.inc = add i32 %i, 1
	br label %header
return:
	ret void
}


; RUN: not llvm-as %s -o /dev/null -f &&
; RUN: llvm-as %s -o /dev/null -f 2>&1 | grep 'Cannot form'

int %main() {
         %foo  = call sbyte* %llvm.stacksave()
         %foop = cast sbyte* %foo to label*
         %nret = load label* %foop
         br label %nret;
}

Make sure this file gets upgraded with llvm-upgrade

; RUN: llvm-upgrade %s | not llvm-as -o /dev/null -f &&
; RUN: llvm-upgrade %s | llvm-as -o /dev/null -f 2>&1 | grep 'Cannot form'

int %main() {
         %foo  = call sbyte* %llvm.stacksave()
         %foop = cast sbyte* %foo to label*
         %nret = load label* %foop
         br label %nret;
}


; RUN: llvm-as -o %t.bc %s
; RUN: ld.lld -m elf_x86_64 --lto-jobs=2 -save-temps -o %t %t.bc -shared
; RUN: llvm-nm %t0.lto.o | FileCheck --check-prefix=CHECK0 %s
; RUN: llvm-nm %t1.lto.o | FileCheck --check-prefix=CHECK1 %s

target triple = "x86_64-unknown-linux-gnu"

; CHECK0-NOT: bar
; CHECK0: T foo
; CHECK0-NOT: bar
define void @foo() {
  call void @bar()
  ret void
}

; CHECK1-NOT: foo
; CHECK1: T bar
; CHECK1-NOT: foo
define void @bar() {
  call void @foo()
  ret void
}

Add datalayout to test to prevent an assertion in Debug mode.

; REQUIRES: x86
; RUN: llvm-as -o %t.bc %s
; RUN: ld.lld -m elf_x86_64 --lto-jobs=2 -save-temps -o %t %t.bc -shared
; RUN: llvm-nm %t0.lto.o | FileCheck --check-prefix=CHECK0 %s
; RUN: llvm-nm %t1.lto.o | FileCheck --check-prefix=CHECK1 %s

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; CHECK0-NOT: bar
; CHECK0: T foo
; CHECK0-NOT: bar
define void @foo() {
  call void @bar()
  ret void
}

; CHECK1-NOT: foo
; CHECK1: T bar
; CHECK1-NOT: foo
define void @bar() {
  call void @foo()
  ret void
}


; RUN: llvm-upgrade < %s | llvm-as | llc
%lldb.compile_unit = type { uint, ushort, ushort, sbyte*, sbyte*, sbyte*, {  }* }
%d.compile_unit7 = external global %lldb.compile_unit		; <%lldb.compile_unit*> [#uses=1]

implementation   ; Functions:

declare {  }* %llvm.dbg.stoppoint({  }*, uint, uint, %lldb.compile_unit*)

void %rb_raise(int, ...) {
entry:
	br bool false, label %strlen.exit, label %no_exit.i

no_exit.i:		; preds = %entry
	ret void

strlen.exit:		; preds = %entry
	%dbg.tmp.1.i2 = call {  }* %llvm.dbg.stoppoint( {  }* null, uint 4358, uint 0, %lldb.compile_unit* %d.compile_unit7 )		; <{  }*> [#uses=0]
	unreachable
}

Fix the intrinsic debug call to make this match current definition.

; RUN: llvm-upgrade < %s | llvm-as | llc
%lldb.compile_unit = type { uint, ushort, ushort, sbyte*, sbyte*, sbyte*, {  }* }
%d.compile_unit7 = external global %lldb.compile_unit		; <%lldb.compile_unit*> [#uses=1]

implementation   ; Functions:

declare void %llvm.dbg.stoppoint(uint, uint, %lldb.compile_unit*)

void %rb_raise(int, ...) {
entry:
	br bool false, label %strlen.exit, label %no_exit.i

no_exit.i:		; preds = %entry
	ret void

strlen.exit:		; preds = %entry
	call void %llvm.dbg.stoppoint(uint 4358, uint 0, %lldb.compile_unit* %d.compile_unit7 )		; <{  }*> [#uses=0]
	unreachable
}


; RUN: llc < %s -fast-isel -fast-isel-abort-args -mtriple=x86_64-apple-darwin10
; XFAIL: *

%struct.s0 = type { x86_fp80, x86_fp80 }

; FastISel cannot handle this case yet. Make sure that we abort.
define i8* @args_fail(%struct.s0* byval nocapture readonly align 16 %y) {
  %1 = bitcast %struct.s0* %y to i8*
  ret i8* %1
}

Update test case to use "not" instead of "XFAIL".

; RUN: not --crash llc < %s -fast-isel -fast-isel-abort-args -mtriple=x86_64-apple-darwin10

%struct.s0 = type { x86_fp80, x86_fp80 }

; FastISel cannot handle this case yet. Make sure that we abort.
define i8* @args_fail(%struct.s0* byval nocapture readonly align 16 %y) {
  %1 = bitcast %struct.s0* %y to i8*
  ret i8* %1
}


; RUN: llvm-as < %s | llvm-dis | FileCheck %s

@v1 = global i32 0
; CHECK: @v1 = global i32 0

@v2 = global [1 x i32] zeroinitializer
; CHECK: @v2 = global [1 x i32] zeroinitializer

@v3 = alias i16, i32* @v1
; CHECK: @v3 = alias i16, i32* @v1

@v4 = alias i32, [1 x i32]* @v2
; CHECK: @v4 = alias i32, [1 x i32]* @v2

@v5 = alias addrspace(2) i32, i32* @v1
; CHECK: @v5 = alias addrspace(2) i32, i32* @v1

@v6 = alias i16, i32* @v1
; CHECK: @v6 = alias i16, i32* @v1

@v7 = thread_local(localdynamic) alias i32* @v1
; CHECK: @v7 = thread_local(localdynamic) alias i32* @v1

Rename alias variables to make it easier to add new tests to the file.

; RUN: llvm-as < %s | llvm-dis | FileCheck %s

@v1 = global i32 0
; CHECK: @v1 = global i32 0

@v2 = global [1 x i32] zeroinitializer
; CHECK: @v2 = global [1 x i32] zeroinitializer

@a1 = alias i16, i32* @v1
; CHECK: @a1 = alias i16, i32* @v1

@a2 = alias i32, [1 x i32]* @v2
; CHECK: @a2 = alias i32, [1 x i32]* @v2

@a3 = alias addrspace(2) i32, i32* @v1
; CHECK: @a3 = alias addrspace(2) i32, i32* @v1

@a4 = alias i16, i32* @v1
; CHECK: @a4 = alias i16, i32* @v1

@a5 = thread_local(localdynamic) alias i32* @v1
; CHECK: @a5 = thread_local(localdynamic) alias i32* @v1


; RUN llvm-upgrade < %s | llvm-as
bool %main(int %X) {
  %res = cast bool true to bool
  ret bool %res
}

Fix the run line and make this test more specific.

; RUN: llvm-upgrade < %s | llvm-as | llvm-dis | grep bitcast
bool %main(int %X) {
  %res = cast bool true to bool
  ret bool %res
}


; The %A getelementptr instruction should be eliminated here

; RUN: if as < %s | opt -instcombine -dce | dis | grep getelementptr | grep '%A'
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

implementation

int *"foo"(int * %I)
begin
	%A = getelementptr int* %I, uint 17
	store int 23, int* %A

	%B = load int* %A
	store int %B, int* %A, uint 0

	%C = getelementptr int* %A
	ret int* %C
end

int *"foo2"(int * %I)
begin
	%A = getelementptr int* %I, uint 0  ; Noop
	ret int * %A
end

Change test to really test the cases we can hit

; The %A getelementptr instruction should be eliminated here

; RUN: if as < %s | opt -instcombine -dce | dis | grep getelementptr | grep '%A'
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

implementation

int *"foo1"(int * %I) { ; Test noop elimination
	%A = getelementptr int* %I, uint 0
	ret int * %A
}

int* %foo2(int* %I) {  ; Test noop elimination
	%A = getelementptr int* %I
	ret int* %A
}
int* %foo3(int * %I) { ; Test that two array indexing geps fold
	%A = getelementptr int* %I, uint 17
	%B = getelementptr int* %A, uint 4
	ret int* %B
}

int* %foo4({int} *%I) { ; Test that two getelementptr insts fold
	%A = getelementptr {int}* %I, uint 1
	%B = getelementptr {int}* %A, uint 0, ubyte 0
	ret int* %B
}


; RUN: llvm-as -o %t.bc %s
; RUN: llvm-lto -exported-symbol=foo -exported-symbol=bar -j2 -o %t.o %t.bc
; RUN: llvm-nm %t.o.0 | FileCheck --check-prefix=CHECK0 %s
; RUN: llvm-nm %t.o.1 | FileCheck --check-prefix=CHECK1 %s

; FIXME: Investigate test failures on these architecures.
; XFAIL: mips-, mipsel-, aarch64

target triple = "x86_64-unknown-linux-gnu"

; CHECK0-NOT: bar
; CHECK0: T foo
; CHECK0-NOT: bar
define void @foo() {
  call void @bar()
  ret void
}

; CHECK1-NOT: foo
; CHECK1: T bar
; CHECK1-NOT: foo
define void @bar() {
  call void @foo()
  ret void
}

Tweak XFAIL line for mips.

; RUN: llvm-as -o %t.bc %s
; RUN: llvm-lto -exported-symbol=foo -exported-symbol=bar -j2 -o %t.o %t.bc
; RUN: llvm-nm %t.o.0 | FileCheck --check-prefix=CHECK0 %s
; RUN: llvm-nm %t.o.1 | FileCheck --check-prefix=CHECK1 %s

; FIXME: Investigate test failures on these architecures.
; XFAIL: mips, mipsel, aarch64

target triple = "x86_64-unknown-linux-gnu"

; CHECK0-NOT: bar
; CHECK0: T foo
; CHECK0-NOT: bar
define void @foo() {
  call void @bar()
  ret void
}

; CHECK1-NOT: foo
; CHECK1: T bar
; CHECK1-NOT: foo
define void @bar() {
  call void @foo()
  ret void
}


; RUN: llvm-as %s -o %t.o
; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    --plugin-opt=save-temps \
; RUN:    -shared %t.o -o %t.so
; RUN: llvm-readobj -r %t.so.o | FileCheck %s

; Test that we produce R_X86_64_GOTPCREL instead of R_X86_64_GOTPCRELX
; CHECK: R_X86_64_GOTPCREL foo

@foo = external global i32
define i32 @bar() {
  %t = load i32, i32* @foo
  ret i32 %t
}

Fix test to not assume it runs on x86 hardware.

; RUN: llvm-as %s -o %t.o
; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    --plugin-opt=save-temps \
; RUN:    -shared %t.o -o %t.so
; RUN: llvm-readobj -r %t.so.o | FileCheck %s

; Test that we produce R_X86_64_GOTPCREL instead of R_X86_64_GOTPCRELX
; CHECK: R_X86_64_GOTPCREL foo

target triple = "x86_64-unknown-linux-gnu"

@foo = external global i32
define i32 @bar() {
  %t = load i32, i32* @foo
  ret i32 %t
}


; RUN: llc < %s -mtriple=armv6-linux-gnu -regalloc=basic | FileCheck %s

; The greedy register allocator uses a single CSR here, invalidating the test.

@b = external global i64*

define i64 @t(i64 %a) nounwind readonly {
entry:
; CHECK: push {lr}
; CHECK: pop {lr}
	%0 = load i64** @b, align 4
	%1 = load i64* %0, align 4
	%2 = mul i64 %1, %a
	ret i64 %2
}

Fix test that depends on register allocation.

; RUN: llc < %s -mtriple=armv6-linux-gnu | FileCheck %s

@b = external global i64*

define i64 @t(i64 %a) nounwind readonly {
entry:
; CHECK: push {r4, r5, lr}
; CHECK: pop {r4, r5, pc}
        call void asm sideeffect "", "~{r4},~{r5}"() nounwind
	%0 = load i64** @b, align 4
	%1 = load i64* %0, align 4
	%2 = mul i64 %1, %a
	ret i64 %2
}


; RUN: llc < %s -mtriple=x86_64-linux   | FileCheck %s -check-prefix=X64
; RUN: llc < %s -mtriple=x86_64-win32   | FileCheck %s -check-prefix=X64
; X64: movq ({{%rsi|%rdx}}), %r

; RUN: llc < %s -march=x86 -mattr=+sse2 | FileCheck %s -check-prefix=X32
; X32: movsd (%ecx), %xmm

; Uses movsd to load / store i64 values if sse2 is available.

; rdar://6659858

define void @foo(i64* %x, i64* %y) nounwind  {
entry:
	%tmp1 = load i64* %y, align 8		; <i64> [#uses=1]
	store i64 %tmp1, i64* %x, align 8
	ret void
}

Make test independent of scheduling

; RUN: llc < %s -mtriple=x86_64-linux   | FileCheck %s -check-prefix=X64
; RUN: llc < %s -mtriple=x86_64-win32   | FileCheck %s -check-prefix=X64
; X64: movq ({{%rsi|%rdx}}), %r

; RUN: llc < %s -march=x86 -mattr=+sse2 | FileCheck %s -check-prefix=X32
; X32: movsd ({{%ecx|%eax}}), %xmm

; Uses movsd to load / store i64 values if sse2 is available.

; rdar://6659858

define void @foo(i64* %x, i64* %y) nounwind  {
entry:
	%tmp1 = load i64* %y, align 8		; <i64> [#uses=1]
	store i64 %tmp1, i64* %x, align 8
	ret void
}


; RUN: llvm-as < %s | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll

void "NewCasts" (short %x) {
  %a = zext short %x to int
  %b = sext short %x to uint
  %c = trunc short %x to ubyte
  %d = uitofp short %x to float
  %e = sitofp short %x to double
  %f = fptoui float %d to short
  %g = fptosi double %e to short
  %i = fpext float %d to double
  %j = fptrunc double %i to float
  %k = bitcast int %a to float
  %l = inttoptr short %x to int*
  %m = ptrtoint int* %l to long
  ret void
}

Add a couple little tests for SExt/ZExt of constants of a sign that doesn't match.

; RUN: llvm-as < %s | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll

void "NewCasts" (short %x) {
  %a = zext short %x to int
  %b = sext short %x to uint
  %c = trunc short %x to ubyte
  %d = uitofp short %x to float
  %e = sitofp short %x to double
  %f = fptoui float %d to short
  %g = fptosi double %e to short
  %i = fpext float %d to double
  %j = fptrunc double %i to float
  %k = bitcast int %a to float
  %l = inttoptr short %x to int*
  %m = ptrtoint int* %l to long
  ret void
}

ushort "ZExtConst" () {
  ret ushort trunc ( uint zext ( short 42 to uint) to ushort )
}

short "SExtConst" () {
  ret short trunc (int sext (ushort 42 to int) to short )
}


void %test() {
	%A = add sbyte 0, 12
	%B = sub sbyte %A, %A
	%C = mul sbyte %B, %B
	;%D = div sbyte %C, %C
	;%E = rem sbyte %D, %D
	;%F = div ubyte 5, 6
	;%G = rem ubyte 6, 5

	%A = add short 0, 12
	%B = sub short %A, %A
	%C = mul short %B, %B
	;%D = div short %C, %C
	;%E = rem short %D, %D
	;%F = div ushort 5, 6
	;%G = rem uint 6, 5

	%A = add int 0, 12
	%B = sub int %A, %A
	%C = mul int %B, %B
	;%D = div int %C, %C
	;%E = rem int %D, %D
	;%F = div uint 5, 6
	;%G = rem uint 6, 5

	ret void
}

Enable div and mod tests

void %test() {
	%A = add sbyte 0, 12
	%B = sub sbyte %A, %A
	%C = mul sbyte %B, %B
	%D = div sbyte %C, %C
	%E = rem sbyte %D, %D
	%F = div ubyte 5, 6
	%G = rem ubyte 6, 5

	%A = add short 0, 12
	%B = sub short %A, %A
	%C = mul short %B, %B
	%D = div short %C, %C
	%E = rem short %D, %D
	%F = div ushort 5, 6
	%G = rem uint 6, 5

	%A = add int 0, 12
	%B = sub int %A, %A
	%C = mul int %B, %B
	%D = div int %C, %C
	%E = rem int %D, %D
	%F = div uint 5, 6
	%G = rem uint 6, 5

	ret void
}


; RUN: llvm-upgrade < %s | llvm-as | opt -constprop | llvm-dis | grep 4294967295 &&
; RUN: llvm-upgrade < %s | llvm-as | opt -constprop | llvm-dis | not grep zeroinitializer

< 4 x uint> %test() {
  %tmp40 = bitcast <2 x long> bitcast (<4 x int> < int 0, int 0, int -1, int 0 > to <2 x long>) to <4 x uint>
  ret <4 x uint> %tmp40
}

Update this test because constant integers are always printed signed now.

; RUN: llvm-upgrade < %s | llvm-as | opt -constprop | llvm-dis | grep 'uint -1' &&
; RUN: llvm-upgrade < %s | llvm-as | opt -constprop | llvm-dis | not grep zeroinitializer

< 4 x uint> %test() {
  %tmp40 = bitcast <2 x long> bitcast (<4 x int> < int 0, int 0, int -1, int 0 > to <2 x long>) to <4 x uint>
  ret <4 x uint> %tmp40
}


; RUN: llvm-upgrade %s | llvm-as -f -o %t.bc
; RUN: lli %t.bc > /dev/null

double %test(double* %DP, double %Arg) {
	%D = load double* %DP
	%V = add double %D, 1.0
	%W = sub double %V, %V
	%X = mul double %W, %W
	%Y = div double %X, %X
	%Z = rem double %Y, %Y
	%Z1 = div double %Z, %W
	%Q = add double %Z, %Arg
	%R = cast double %Q to double
	store double %R, double* %DP
	ret double %Z
}

int %main() {
  %X = alloca double
  call double %test(double* %X, double 2.0)
  ret int 0
}

Make sure the value passed to test function is initialized.

; RUN: llvm-upgrade %s | llvm-as -f -o %t.bc
; RUN: lli %t.bc > /dev/null

double %test(double* %DP, double %Arg) {
	%D = load double* %DP
	%V = add double %D, 1.0
	%W = sub double %V, %V
	%X = mul double %W, %W
	%Y = div double %X, %X
	%Z = rem double %Y, %Y
	%Z1 = div double %Z, %W
	%Q = add double %Z, %Arg
	%R = cast double %Q to double
	store double %R, double* %DP
	ret double %Z
}

int %main() {
  %X = alloca double
  store double 0.0, double* %X
  call double %test(double* %X, double 2.0)
  ret int 0
}


; RUN: llvm-upgrade < %s | llvm-as -f -o %s.bc
; RUN: llvm-link -f -o %s.linked %s.bc

target endian = big
target pointersize = 32
target triple = "powerpc-apple-darwin7.7.0"
deplibs = [ "c", "crtend" ]
%source = global <4 x int> < int 0, int 1, int 2, int 3 >

implementation   ; Functions:

int %main() {
entry:
        ret int 0
}

Fix test not to emit junk into source directory

; RUN: llvm-upgrade < %s | llvm-as -f -o %t1.bc
; RUN: llvm-link -f -o %t2.bc %t1.bc

target endian = big
target pointersize = 32
target triple = "powerpc-apple-darwin7.7.0"
deplibs = [ "c", "crtend" ]
%source = global <4 x int> < int 0, int 1, int 2, int 3 >

implementation   ; Functions:

int %main() {
entry:
        ret int 0
}


; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN:    grep {ret i32 \045storemerge} | wc -l | grep 2
;; Simple sinking tests

; "if then else"
define i32 @test1(i1 %C) {
	%A = alloca i32
        br i1 %C, label %Cond, label %Cond2

Cond:
        store i32 -987654321, i32* %A
        br label %Cont

Cond2:
	store i32 47, i32* %A
	br label %Cont

Cont:
	%V = load i32* %A
	ret i32 %V
}

; "if then"
define i32 @test2(i1 %C) {
	%A = alloca i32
	store i32 47, i32* %A
        br i1 %C, label %Cond, label %Cont

Cond:
        store i32 -987654321, i32* %A
        br label %Cont

Cont:
	%V = load i32* %A
	ret i32 %V
}

Fix this test in a slightly more obvious way.

; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN:    grep {ret i32 %.toremerge} | wc -l | grep 2
;; Simple sinking tests

; "if then else"
define i32 @test1(i1 %C) {
	%A = alloca i32
        br i1 %C, label %Cond, label %Cond2

Cond:
        store i32 -987654321, i32* %A
        br label %Cont

Cond2:
	store i32 47, i32* %A
	br label %Cont

Cont:
	%V = load i32* %A
	ret i32 %V
}

; "if then"
define i32 @test2(i1 %C) {
	%A = alloca i32
	store i32 47, i32* %A
        br i1 %C, label %Cond, label %Cont

Cond:
        store i32 -987654321, i32* %A
        br label %Cont

Cont:
	%V = load i32* %A
	ret i32 %V
}


target endian = little
target pointersize = 32

implementation

int %main(int, sbyte**) {
entry:
	br bool false, label %then, label %endif
then:
	br label %endif
endif:
	%x.0 = phi uint [ 4, %entry ], [ 27, %then ]
	%result.0 = phi int [ 32, %then ], [ 0, %entry ]
	ret int 0
}

Simplify testcase a bit more

target endian = little
target pointersize = 32

implementation

int %main() {
entry:
	br label %endif
then:
	br label %endif
endif:
	%x = phi uint [ 4, %entry ], [ 27, %then ]
	%result = phi int [ 32, %then ], [ 0, %entry ]
	ret int 0
}


; RUN: llvm-upgrade < %s | llvm-as | opt -tailcallelim | llvm-dis | \
; RUN:    $prcontext alloca 1 | grep {i32 @foo}

declare void %bar(int*)
int %foo() {
  %A = alloca int             ;; Should stay in entry block because of 'tail' marker
  store int 17, int* %A
  call void %bar(int* %A)

  %X = tail call int %foo()
  ret int %X
}

Use %prcontext, $prcontext is not resolving for some reason.

; RUN: llvm-upgrade < %s | llvm-as | opt -tailcallelim | llvm-dis | \
; RUN:    %prcontext alloca 1 | grep {i32 @foo}

declare void %bar(int*)
int %foo() {
  %A = alloca int             ;; Should stay in entry block because of 'tail' marker
  store int 17, int* %A
  call void %bar(int* %A)

  %X = tail call int %foo()
  ret int %X
}


; This bug has to do with the fact that constant propogation was implemented in
; terms of _logical_ not (! in C) instead of _bitwise_ not (~ in C).  This was
; due to a spec change.

; RUN: if as < %s | opt -constprop | dis | grep 'int 0'
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

int "test1"() {
	%R = not int 123
	ret int %R
}

int "test2"() {
	%R = not int -123
	ret int %R
}

Fix testcases that used to now dead 'not' instruction

; This bug has to do with the fact that constant propogation was implemented in
; terms of _logical_ not (! in C) instead of _bitwise_ not (~ in C).  This was
; due to a spec change.

; Fix #2: The unary not instruction now no longer exists. Change to xor.

; RUN: if as < %s | opt -constprop | dis | grep 'int 0'
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

int "test1"() {
	%R = xor int 123, -1
	ret int %R
}

int "test2"() {
	%R = xor int -123, -1
	ret int %R
}


; RUN: opt < %s -instsimplify -S | FileCheck %s

define i32 @factorize(i32 %x, i32 %y) {
; CHECK: @factorize
; (X | 2) & (X | 2) -> X | (1 & 2) -> X
  %l = or i32 %x, 1
  %r = or i32 %x, 2
  %z = and i32 %l, %r
  ret i32 %z
; CHECK: ret i32 %x
}

define i32 @expand(i32 %x) {
; CHECK: @expand
; ((X & 1) | 2) & 1 -> ((X & 1) & 1) | (2 & 1) -> (X & 1) | 0 -> X & 1
  %a = and i32 %x, 1
  %b = or i32 %a, 2
  %c = and i32 %b, 1
  ret i32 %c
; CHECK: ret i32 %a
}

Fix typo in comment, spotted by Deewiant.

; RUN: opt < %s -instsimplify -S | FileCheck %s

define i32 @factorize(i32 %x, i32 %y) {
; CHECK: @factorize
; (X | 1) & (X | 2) -> X | (1 & 2) -> X
  %l = or i32 %x, 1
  %r = or i32 %x, 2
  %z = and i32 %l, %r
  ret i32 %z
; CHECK: ret i32 %x
}

define i32 @expand(i32 %x) {
; CHECK: @expand
; ((X & 1) | 2) & 1 -> ((X & 1) & 1) | (2 & 1) -> (X & 1) | 0 -> X & 1
  %a = and i32 %x, 1
  %b = or i32 %a, 2
  %c = and i32 %b, 1
  ret i32 %c
; CHECK: ret i32 %a
}


Fix this test. Don't null out the file, just XFAIL it until patch can be fixed.

; RUN: llvm-as < %s | llc -mtriple=i386-apple-darwin | grep mov | count 1
; XFAIL: *

@f = external global void ()*		; <void ()**> [#uses=1]

define i32 @main() nounwind {
entry:
	load void ()** @f, align 8		; <void ()*>:0 [#uses=1]
	tail call void %0( ) nounwind
	ret i32 0
}


; The reassociate pass is not preserving dominance properties correctly
;
; RUN: as < %s | opt -reassociate -verify

int %compute_dist(int %i, int %j) {
        %reg119 = sub int %j, %i
        ret int %reg119
}

Verify is implicit for opt

; The reassociate pass is not preserving dominance properties correctly
;
; RUN: as < %s | opt -reassociate

int %compute_dist(int %i, int %j) {
        %reg119 = sub int %j, %i
        ret int %reg119
}