; RUN: opt -slp-vectorizer -S %s

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

define void @f(i128 %p1) {
entry:
  br label %while.body

while.body:
  %p.05 = phi i8* [ %add.ptr, %while.body ], [ null, %entry ]
  %p1.addr.04 = phi i128 [ %sub, %while.body ], [ %p1, %entry ]
  %add.ptr = getelementptr inbounds i8, i8* %p.05, i32 2
  %sub = add nsw i128 %p1.addr.04, -2
  %tobool = icmp eq i128 %sub, 0
  br i1 %tobool, label %while.end, label %while.body

while.end:
  ret void
}

Correct a typo for a LoopVectorize test

; RUN: opt -loop-vectorize -S %s

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

define void @f(i128 %p1) {
entry:
  br label %while.body

while.body:
  %p.05 = phi i8* [ %add.ptr, %while.body ], [ null, %entry ]
  %p1.addr.04 = phi i128 [ %sub, %while.body ], [ %p1, %entry ]
  %add.ptr = getelementptr inbounds i8, i8* %p.05, i32 2
  %sub = add nsw i128 %p1.addr.04, -2
  %tobool = icmp eq i128 %sub, 0
  br i1 %tobool, label %while.end, label %while.body

while.end:
  ret void
}


; RUN: llvm-as < %s | opt -deadargelim | llvm-dis | grep nounwind | count 2
; RUN: llvm-as < %s | opt -deadargelim | llvm-dis | grep signext | count 2
; RUN: llvm-as < %s | opt -deadargelim | llvm-dis | not grep inreg
; RUN: llvm-as < %s | opt -deadargelim | llvm-dis | not grep zeroext
; RUN: llvm-as < %s | opt -deadargelim | llvm-dis | not grep byval

	%struct = type { }

@g = global i8 0

define internal i8 @foo(i8* inreg %p, i8 signext %y, ... ) zeroext nounwind {
	store i8 %y, i8* @g
	ret i8 0
}

define i32 @bar() {
	%A = call i8(i8*, i8, ...)* @foo(i8* inreg null, i8 signext 1, %struct* byval null ) zeroext nounwind
	ret i32 0
}

Store the result of multiple identical run lines in a temporary file.

; RUN: llvm-as < %s | opt -deadargelim | llvm-dis > %t
; RUN: cat %t | grep nounwind | count 2
; RUN: cat %t | grep signext | count 2
; RUN: cat %t | not grep inreg
; RUN: cat %t | not grep zeroext
; RUN: cat %t | not grep byval

	%struct = type { }

@g = global i8 0

define internal i8 @foo(i8* inreg %p, i8 signext %y, ... ) zeroext nounwind {
	store i8 %y, i8* @g
	ret i8 0
}

define i32 @bar() {
	%A = call i8(i8*, i8, ...)* @foo(i8* inreg null, i8 signext 1, %struct* byval null ) zeroext nounwind
	ret i32 0
}


; Test merging of blocks that only have PHI nodes in them.  This tests the case
; where the mergedinto block doesn't have any PHI nodes, and is in fact
; dominated by the block-to-be-eliminated
;
; RUN: llvm-as < %s | opt -simplifycfg | llvm-dis | not grep N:
;

define i32 @test(i1 %a, i1 %b) {
	br i1 %b, label %N, label %Q
Q:
	br label %N
N:
	%W = phi i32 [0, %0], [1, %Q]
	; This block should be foldable into M
	br label %M

M:
	%R = add i32 %W, 1
	ret i32 %R
}

Make this test more challenging to help it avoid being optimized away before it tests what it is intended to test.

; Test merging of blocks that only have PHI nodes in them.  This tests the case
; where the mergedinto block doesn't have any PHI nodes, and is in fact
; dominated by the block-to-be-eliminated
;
; RUN: llvm-as < %s | opt -simplifycfg | llvm-dis | not grep N:
;

declare i1 @foo()

define i32 @test(i1 %a, i1 %b) {
        %c = call i1 @foo()
	br i1 %c, label %N, label %P
P:
        %d = call i1 @foo()
	br i1 %d, label %N, label %Q
Q:
	br label %N
N:
	%W = phi i32 [0, %0], [1, %Q], [2, %P]
	; This block should be foldable into M
	br label %M

M:
	%R = add i32 %W, 1
	ret i32 %R
}


; LoopInfo is incorrectly calculating loop nesting!  In this case it doesn't
; figure out that loop "Inner" should be nested inside of leep "LoopHeader",
; and instead nests it just inside loop "Top"
;
; RUN: analyze -loops %s | grep '     Loop Containing: label %Inner'
;

implementation

void %test() {
	br label %Top
Top:
	br label %LoopHeader
Next:
	br bool false, label %Inner, label %Out
Inner:
	br bool false, label %Inner, label %LoopHeader

LoopHeader:
	br label %Next

Out:
	br bool false, label %Top, label %Done

Done:
	ret void
}

Fix testcase failing because of change of output

; LoopInfo is incorrectly calculating loop nesting!  In this case it doesn't
; figure out that loop "Inner" should be nested inside of leep "LoopHeader",
; and instead nests it just inside loop "Top"
;
; RUN: analyze -loops %s | grep '     Loop Containing:[ ]*%Inner'
;

implementation

void %test() {
	br label %Top
Top:
	br label %LoopHeader
Next:
	br bool false, label %Inner, label %Out
Inner:
	br bool false, label %Inner, label %LoopHeader

LoopHeader:
	br label %Next

Out:
	br bool false, label %Top, label %Done

Done:
	ret void
}


; RUN: llc < %s -march=ppc32

define void @img2buf(i32 %symbol_size_in_bytes, i16* %ui16) {
        %tmp93 = load i16* null         ; <i16> [#uses=1]
        %tmp99 = call i16 @llvm.bswap.i16( i16 %tmp93 )         ; <i16> [#uses=1]
        store i16 %tmp99, i16* %ui16
        ret void
}

declare i16 @llvm.bswap.i16(i16)

Add nounwind to this test.

; RUN: llc < %s -march=ppc32

define void @img2buf(i32 %symbol_size_in_bytes, i16* %ui16) nounwind {
        %tmp93 = load i16* null         ; <i16> [#uses=1]
        %tmp99 = call i16 @llvm.bswap.i16( i16 %tmp93 )         ; <i16> [#uses=1]
        store i16 %tmp99, i16* %ui16
        ret void
}

declare i16 @llvm.bswap.i16(i16)


; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep {a.off}

define i1 @test1(i32 %a) {
  %a.off = add i32 %a, 4          ; <i32> [#uses=1]
  %C = icmp ult i32 %a.off, 4             ; <i1> [#uses=1]
  ret i1 %C
}

define i1 @test2(i32 %a) {
  %a.off = sub i32 %a, 4          ; <i32> [#uses=1]
  %C = icmp ugt i32 %a.off, -5             ; <i1> [#uses=1]
  ret i1 %C
}

define i1 @test3(i32 %a) {
  %a.off = add i32 %a, 4          ; <i32> [#uses=1]
  %C = icmp slt i32 %a.off, 2147483652             ; <i1> [#uses=1]
  ret i1 %C
}

Tag this test with the PR reference.

; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep {a.off}
; PR1949

define i1 @test1(i32 %a) {
  %a.off = add i32 %a, 4          ; <i32> [#uses=1]
  %C = icmp ult i32 %a.off, 4             ; <i1> [#uses=1]
  ret i1 %C
}

define i1 @test2(i32 %a) {
  %a.off = sub i32 %a, 4          ; <i32> [#uses=1]
  %C = icmp ugt i32 %a.off, -5             ; <i1> [#uses=1]
  ret i1 %C
}

define i1 @test3(i32 %a) {
  %a.off = add i32 %a, 4          ; <i32> [#uses=1]
  %C = icmp slt i32 %a.off, 2147483652             ; <i1> [#uses=1]
  ret i1 %C
}


; RUN: not llvm-as < %s -o /dev/null -f
declare void @h(i32* %num) byval

Test that byval cannot be used with pointers to types with no size.

; RUN: not llvm-as < %s -o /dev/null -f
	%s = type opaque
declare void @h(%s* byval %num)


; test shifts
int %main() {
    %shamt = add ubyte 0, 1

    ; Left shifts...
    %t1 = shl int 1, ubyte %shamt
    %t2 = shl int 1, ubyte 4

    %t1 = shl uint 1, ubyte %shamt
    %t2 = shl uint 1, ubyte 5

    ;%t1 = shl long 1, ubyte %shamt
    %t2 = shl long 1, ubyte 4

    ;%t1 = shl ulong 1, ubyte %shamt
    %t2 = shl ulong 1, ubyte 5

    ; Right shifts...
    %t1 = shr int 1, ubyte %shamt
    %t2 = shr int 1, ubyte 4

    %t1 = shr uint 1, ubyte %shamt
    %t2 = shr uint 1, ubyte 5

    ;%t1 = shr long 1, ubyte %shamt
    %t2 = shr long 1, ubyte 4

    ;%t1 = shr ulong 1, ubyte %shamt
    %t2 = shr ulong 1, ubyte 5
    ret int 0
}

Add tests for 64 bit shifts

; test shifts
int %main() {
    %shamt = add ubyte 0, 1

    ; Left shifts...
    %t1 = shl int 1, ubyte %shamt
    %t2 = shl int 1, ubyte 4

    %t1 = shl uint 1, ubyte %shamt
    %t2 = shl uint 1, ubyte 5

    ;%t1 = shl long 1, ubyte %shamt
    %t2 = shl long 1, ubyte 4

    ;%t1 = shl ulong 1, ubyte %shamt
    %t2 = shl ulong 1, ubyte 5

    ; Right shifts...
    %t1 = shr int 1, ubyte %shamt
    %t2 = shr int 1, ubyte 4

    %t1 = shr uint 1, ubyte %shamt
    %t2 = shr uint 1, ubyte 5

    ;%t1 = shr long 1, ubyte %shamt
    %t1 = shr long 1, ubyte 4
    %t2 = shr long 1, ubyte %shamt
    %t3 = shl long 1, ubyte 4
    %t4 = shl long 1, ubyte %shamt

    ;%t1 = shr ulong 1, ubyte %shamt
    %t1 = shr ulong 1, ubyte 5
    %t2 = shr ulong 1, ubyte %shamt
    %t3 = shl ulong 1, ubyte 5
    %t4 = shl ulong 1, ubyte %shamt
    ret int 0
}


; This testcase is not level raised properly...
;
; RUN: if as < %s | opt -raise | dis | grep ' cast ' | grep '*'
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

	%List = type { int, %List* }

implementation

%List* "createList"(uint %Depth)
begin
	%reg110 = malloc uint, uint 4
	store uint %Depth, uint* %reg110
	%reg113 = call %List* %createList( uint %Depth )
	%reg217 = getelementptr uint* %reg110, uint 2
	%cast221 = cast uint* %reg217 to %List**
	store %List* %reg113, %List** %cast221
	%cast222 = cast uint* %reg110 to %List*
	ret %List* %cast222
end

Convert old style gep index from uint to long

; This testcase is not level raised properly...
;
; RUN: if as < %s | opt -raise | dis | grep ' cast ' | grep '*'
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

	%List = type { int, %List* }

implementation

%List* "createList"(uint %Depth)
begin
	%reg110 = malloc uint, uint 4
	store uint %Depth, uint* %reg110
	%reg113 = call %List* %createList( uint %Depth )
	%reg217 = getelementptr uint* %reg110, long 2
	%cast221 = cast uint* %reg217 to %List**
	store %List* %reg113, %List** %cast221
	%cast222 = cast uint* %reg110 to %List*
	ret %List* %cast222
end


; RUN: llvm-as < %s | llc -f -o /dev/null
target triple = "powerpc-apple-darwin9.5"
        %llvm.dbg.variable.type = type { i32, { }*, i8*, { }*, i32, { }*, i8*, i8* }
@llvm.dbg.variable24 = external constant %llvm.dbg.variable.type                ; <%llvm.dbg.variable.type*> [#uses=1]

declare void @llvm.dbg.declare({ }*, { }*) nounwind

define i32 @isascii(i32 %_c) nounwind {
entry:
	%j = alloca i32
	%0 = bitcast i32* %j to { }*
        call void @llvm.dbg.declare({ }* %0, { }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable24 to { }*))
        unreachable
}

Mark this test as requiring the powerpc target.

; RUN: llvm-as < %s | llc -f -o /dev/null
; XFAIL: *
; XTARGET: powerpc

target triple = "powerpc-apple-darwin9.5"
        %llvm.dbg.variable.type = type { i32, { }*, i8*, { }*, i32, { }*, i8*, i8* }
@llvm.dbg.variable24 = external constant %llvm.dbg.variable.type                ; <%llvm.dbg.variable.type*> [#uses=1]

declare void @llvm.dbg.declare({ }*, { }*) nounwind

define i32 @isascii(i32 %_c) nounwind {
entry:
	%j = alloca i32
	%0 = bitcast i32* %j to { }*
        call void @llvm.dbg.declare({ }* %0, { }* bitcast (%llvm.dbg.variable.type* @llvm.dbg.variable24 to { }*))
        unreachable
}


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

; CHECK: cmovne %rdi, %rsi
; CHECK: movl (%rsi), %eax

%0 = type { i64, i32 }

define i32 @foo(%0* %p, %0* %q, i1 %r) nounwind {
  %t0 = load %0* %p
  %t1 = load %0* %q
  %t4 = select i1 %r, %0 %t0, %0 %t1
  %t5 = extractvalue %0 %t4, 1
  ret i32 %t5
}

Change this to the correct PR number.

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

; CHECK: cmovne %rdi, %rsi
; CHECK: movl (%rsi), %eax

%0 = type { i64, i32 }

define i32 @foo(%0* %p, %0* %q, i1 %r) nounwind {
  %t0 = load %0* %p
  %t1 = load %0* %q
  %t4 = select i1 %r, %0 %t0, %0 %t1
  %t5 = extractvalue %0 %t4, 1
  ret i32 %t5
}


%somestr = constant [sbyte] c"hello world"
%somestr = constant [11x sbyte] c"hello world"
%array   = constant [[2 x int]]  [ [2 x int] [ int 12, int 52 ] ]
           constant { int, int } { int 4, int 3 }

implementation

[[2 x int]]* "test function"(int %i0, int %j0)
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

Add a test for the new null keyword

%somestr = constant [sbyte] c"hello world"
%somestr = constant [11x sbyte] c"hello world"
%array   = constant [[2 x int]]  [ [2 x int] [ int 12, int 52 ] ]
           constant { int, int } { int 4, int 3 }

implementation

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

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

[sbyte]* "yet another func"(int, double)
begin
	ret [sbyte]* null            ; Test null
end

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


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

; Verify that enabling caching is working
; RUN: rm -Rf %t.cache && mkdir %t.cache
; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
; RUN:     --plugin-opt=thinlto \
; RUN:     --plugin-opt=cache-dir=%t.cache \
; RUN:     -o %t3.o %t2.o %t.o

; RUN: ls %t.cache | count 2

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

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

Fix Gold test after caching fix in r283655

; Verify that enabling caching is ignoring module when we emit them without hash.
; RUN: opt -module-summary %s -o %t.o
; RUN: opt -module-summary %p/Inputs/cache.ll -o %t2.o

; RUN: rm -Rf %t.cache && mkdir %t.cache
; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
; RUN:     --plugin-opt=thinlto \
; RUN:     --plugin-opt=cache-dir=%t.cache \
; RUN:     -o %t3.o %t2.o %t.o

; RUN: ls %t.cache | count 0

; Verify that enabling caching is working with module with hash.

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

; RUN: rm -Rf %t.cache && mkdir %t.cache
; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
; RUN:     --plugin-opt=thinlto \
; RUN:     --plugin-opt=cache-dir=%t.cache \
; RUN:     -o %t3.o %t2.o %t.o

; RUN: ls %t.cache | count 2

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

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


; RUN: llc -O0 -mtriple=powerpc-unknown-linux-gnu -maltivec -verify-machineinstrs  < %s | FileCheck %s
; RUN: llc -O0 -mtriple=powerpc64-unknown-linux-gnu -maltivec -verify-machineinstrs < %s | FileCheck %s
; XFAIL: *

; This verifies that we generate correct spill/reload code for vector regs.

define void @addrtaken(i32 %i, <4 x float> %w) nounwind {
entry:
  %i.addr = alloca i32, align 4
  %w.addr = alloca <4 x float>, align 16
  store i32 %i, i32* %i.addr, align 4
  store <4 x float> %w, <4 x float>* %w.addr, align 16
  call void @foo(i32* %i.addr)
  ret void
}

; CHECK: stvx 2, 0, 0
; CHECK: lvx 2, 0, 0

declare void @foo(i32*)

Add -mattr=+altivec and remove XFAIL.

; RUN: llc -O0 -mtriple=powerpc-unknown-linux-gnu -mattr=+altivec -verify-machineinstrs  < %s | FileCheck %s
; RUN: llc -O0 -mtriple=powerpc64-unknown-linux-gnu -mattr=+altivec -verify-machineinstrs < %s | FileCheck %s

; This verifies that we generate correct spill/reload code for vector regs.

define void @addrtaken(i32 %i, <4 x float> %w) nounwind {
entry:
  %i.addr = alloca i32, align 4
  %w.addr = alloca <4 x float>, align 16
  store i32 %i, i32* %i.addr, align 4
  store <4 x float> %w, <4 x float>* %w.addr, align 16
  call void @foo(i32* %i.addr)
  ret void
}

; CHECK: stvx 2, 0, 0
; CHECK: lvx 2, 0, 0

declare void @foo(i32*)


; Test linking of a bc file to an archive via llvm-ld.
; PR1434
; RUN: llvm-as %s -o %t.bar.bc -f
; RUN: echo {define i32* @foo(i32 %x) \{ ret i32* @baz \} \
; RUN:   @baz = external global i32 } | llvm-as -o %t.foo.bc -f
; RUN: llvm-ar rf %t.foo.a %t.foo.bc
; RUN: llvm-ar rf %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

Use the c modifier to tell llvm-ar not to issue a warning when creating the archive (the warning causes the test to fail).

; Test linking of a bc file to an archive via llvm-ld.
; PR1434
; RUN: llvm-as %s -o %t.bar.bc -f
; RUN: echo {define i32* @foo(i32 %x) \{ ret i32* @baz \} \
; RUN:   @baz = external global i32 } | llvm-as -o %t.foo.bc -f
; 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: llc < %s -mtriple=thumbv7-apple-darwin -mattr=+thumb2 | FileCheck %s -check-prefix=DARWIN
; RUN: llc < %s -mtriple=thumbv7-linux -mattr=+thumb2 | FileCheck %s -check-prefix=LINUX

@t = weak global i32 ()* null           ; <i32 ()**> [#uses=1]

declare void @g(i32, i32, i32, i32)

define void @f() {
; DARWIN: f:
; DARWIN: blx _g

; LINUX: f:
; LINUX: bl g
        call void @g( i32 1, i32 2, i32 3, i32 4 )
        ret void
}

define void @h() {
; DARWIN: h:
; DARWIN: blx r0

; LINUX: h:
; LINUX: blx r0
        %tmp = load i32 ()** @t         ; <i32 ()*> [#uses=1]
        %tmp.upgrd.2 = tail call i32 %tmp( )            ; <i32> [#uses=0]
        ret void
}

Remove tail call to preserve this test. A tail call version will follow.

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

@t = weak global i32 ()* null           ; <i32 ()**> [#uses=1]

declare void @g(i32, i32, i32, i32)

define void @f() {
; DARWIN: f:
; DARWIN: blx _g

; LINUX: f:
; LINUX: bl g
        call void @g( i32 1, i32 2, i32 3, i32 4 )
        ret void
}

define void @h() {
; DARWIN: h:
; DARWIN: blx r0

; LINUX: h:
; LINUX: blx r0
        %tmp = load i32 ()** @t         ; <i32 ()*> [#uses=1]
        %tmp.upgrd.2 = call i32 %tmp( )            ; <i32> [#uses=0]
        ret void
}


; RUN: llc -O0 -mtriple=i386-pc-win32 -filetype=asm -o - %s | FileCheck %s

!0 = metadata !{ i32 6, metadata !"Linker Options",
   metadata !{
      metadata !{ metadata !"/DEFAULTLIB:msvcrt.lib" },
      metadata !{ metadata !"/DEFAULTLIB:msvcrt.lib",
                  metadata !"/DEFAULTLIB:secur32.lib" },
      metadata !{ metadata !"/with spaces" } } }

!llvm.module.flags = !{ !0 }

define dllexport void @foo() {
  ret void
}

; CHECK: .section        .drectve,"r"
; CHECK: .ascii   " /DEFAULTLIB:msvcrt.lib"
; CHECK: .ascii   " /DEFAULTLIB:msvcrt.lib"
; CHECK: .ascii   " /DEFAULTLIB:secur32.lib"
; CHECK: .ascii   " \"/with spaces\""
; CHECK: .ascii   " /EXPORT:_foo"

Add a test for proper handling of full Windows path names in the .drectve section

; RUN: llc -O0 -mtriple=i386-pc-win32 -filetype=asm -o - %s | FileCheck %s

!0 = metadata !{ i32 6, metadata !"Linker Options",
   metadata !{
      metadata !{ metadata !"/DEFAULTLIB:msvcrt.lib" },
      metadata !{ metadata !"/DEFAULTLIB:msvcrt.lib",
                  metadata !"/DEFAULTLIB:secur32.lib" },
      metadata !{ metadata !"/DEFAULTLIB:C:\5Cpath to\5Casan_rt.lib" },
      metadata !{ metadata !"/with spaces" } } }

!llvm.module.flags = !{ !0 }

define dllexport void @foo() {
  ret void
}

; CHECK: .section        .drectve,"r"
; CHECK: .ascii   " /DEFAULTLIB:msvcrt.lib"
; CHECK: .ascii   " /DEFAULTLIB:msvcrt.lib"
; CHECK: .ascii   " /DEFAULTLIB:secur32.lib"
; CHECK: .ascii   " \"/DEFAULTLIB:C:\\path to\\asan_rt.lib\""
; CHECK: .ascii   " \"/with spaces\""
; CHECK: .ascii   " /EXPORT:_foo"


; RUN: llc -mtriple wasm32-unknown-unknown-wasm -filetype=obj %s -o - | obj2yaml | FileCheck %s

; Function that uses explict stack, and should generate a reference to
; __stack_pointer, along with the corresponding reloction entry.
define hidden void @foo() #0 {
entry:
  alloca i32, align 4
  ret void
}

; CHECK:  - Type:            IMPORT
; CHECK:     Imports:
; CHECK:       - Module:          env
; CHECK:         Field:           __stack_pointer
; CHECK:         Kind:            GLOBAL
; CHECK:         GlobalType:      I32
; CHECK:         GlobalMutable:   false
; CHECK:   - Type:            CODE
; CHECK:     Relocations:
; CHECK:       - Type:            R_WEBASSEMBLY_GLOBAL_INDEX_LEB
; CHECK:         Index:           0

Fix test breakage from r319810

; RUN: llc -mtriple wasm32-unknown-unknown-wasm -filetype=obj %s -o - | obj2yaml | FileCheck %s

; Function that uses explict stack, and should generate a reference to
; __stack_pointer, along with the corresponding reloction entry.
define hidden void @foo() #0 {
entry:
  alloca i32, align 4
  ret void
}

; CHECK:  - Type:            IMPORT
; CHECK:     Imports:
; CHECK:       - Module:          env
; CHECK:         Field:           __stack_pointer
; CHECK:         Kind:            GLOBAL
; CHECK:         GlobalType:      I32
; CHECK:         GlobalMutable:   true
; CHECK:   - Type:            CODE
; CHECK:     Relocations:
; CHECK:       - Type:            R_WEBASSEMBLY_GLOBAL_INDEX_LEB
; CHECK:         Index:           0


; RUN: llc < %s -mtriple=arm64-linux-gnu -mcpu=cortex-a57 -enable-misched=0 -debug-only=misched -o - 2>&1 > /dev/null | FileCheck %s
; REQUIRES: asserts

@G = external global [0 x i32], align 4

; Check that MMOs are added to epilogue calle-save restore loads so
; that the store to G is not considered dependant on the callee-save
; loads.
;
; CHECK: Before post-MI-sched:
; CHECK-LABEL: # Machine code for function test1:
; CHECK: SU(2):   STRWui %WZR
; CHECK: SU(3):   %X21<def>, %X20<def> = LDPXi %SP
; CHECK:  Predecessors:
; CHECK-NEXT:   out SU(0)
; CHECK-NEXT:   out SU(0)
; CHECK-NEXT:   ch  SU(0)
; CHECK-NEXT:  Successors:
define void @test1() {
entry:
  tail call void asm sideeffect "nop", "~{x20},~{x21},~{x22},~{x23}"() nounwind
  store i32 0, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @G, i64 0, i64 0), align 4
  ret void
}

Fix test to require Asserts since it uses debug output.

; REQUIRES: asserts
; RUN: llc < %s -mtriple=arm64-linux-gnu -mcpu=cortex-a57 -enable-misched=0 -debug-only=misched -o - 2>&1 > /dev/null | FileCheck %s
; REQUIRES: asserts

@G = external global [0 x i32], align 4

; Check that MMOs are added to epilogue calle-save restore loads so
; that the store to G is not considered dependant on the callee-save
; loads.
;
; CHECK: Before post-MI-sched:
; CHECK-LABEL: # Machine code for function test1:
; CHECK: SU(2):   STRWui %WZR
; CHECK: SU(3):   %X21<def>, %X20<def> = LDPXi %SP
; CHECK:  Predecessors:
; CHECK-NEXT:   out SU(0)
; CHECK-NEXT:   out SU(0)
; CHECK-NEXT:   ch  SU(0)
; CHECK-NEXT:  Successors:
define void @test1() {
entry:
  tail call void asm sideeffect "nop", "~{x20},~{x21},~{x22},~{x23}"() nounwind
  store i32 0, i32* getelementptr inbounds ([0 x i32], [0 x i32]* @G, i64 0, i64 0), align 4
  ret void
}


; RUN: opt < %s -sroa -S | FileCheck %s
;
; Make sure that SROA doesn't lose nonnull metadata
; on loads from allocas that get optimized out.

; CHECK-LABEL: define float* @yummy_nonnull
; CHECK: [[RETURN:%(.*)]] = load float*, float** %arg, align 8
; CHECK: [[ASSUME:%(.*)]] = icmp ne float* {{.*}}[[RETURN]], null
; CHECK: call void @llvm.assume(i1 {{.*}}[[ASSUME]])
; CHECK: ret float* {{.*}}[[RETURN]]

define float* @yummy_nonnull(float** %arg) {
entry-block:
	%buf = alloca float*

	%_arg_i8 = bitcast float** %arg to i8*
	%_buf_i8 = bitcast float** %buf to i8*
	call void @llvm.memcpy.p0i8.p0i8.i64(i8* %_buf_i8, i8* %_arg_i8, i64 8, i32 8, i1 false)

	%ret = load float*, float** %buf, align 8, !nonnull !0
	ret float* %ret
}

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

!0 = !{}

Clean up a test case a bit prior to adding more testing for nonnull as part of fixing PR32902.

; RUN: opt < %s -sroa -S | FileCheck %s
;
; Make sure that SROA doesn't lose nonnull metadata
; on loads from allocas that get optimized out.

define float* @yummy_nonnull(float** %arg) {
; CHECK-LABEL: define float* @yummy_nonnull(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    %[[RETURN:.*]] = load float*, float** %arg, align 8
; CHECK-NEXT:    %[[ASSUME:.*]] = icmp ne float* %[[RETURN]], null
; CHECK-NEXT:    call void @llvm.assume(i1 %[[ASSUME]])
; CHECK-NEXT:    ret float* %[[RETURN]]
entry:
  %buf = alloca float*
  %_arg_i8 = bitcast float** %arg to i8*
  %_buf_i8 = bitcast float** %buf to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %_buf_i8, i8* %_arg_i8, i64 8, i32 8, i1 false)
  %ret = load float*, float** %buf, align 8, !nonnull !0
  ret float* %ret
}

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

!0 = !{}


; RUN: llc  < %s -march=mipsel -mcpu=mips32 | FileCheck %s -check-prefix=NAN
; RUN: llc  < %s -march=mipsel -mcpu=mips32 -enable-no-nans-fp-math | FileCheck %s -check-prefix=NO-NAN

define float @foo0(i32 %a, float %d) nounwind readnone {
entry:
; CHECK-NOT: neg.s
  %sub = fsub float -0.000000e+00, %d
  ret float %sub
}

define double @foo1(i32 %a, double %d) nounwind readnone {
entry:
; CHECK:     foo1
; CHECK-NOT: neg.d
; CHECK:     jr
  %sub = fsub double -0.000000e+00, %d
  ret double %sub
}

Revert changes that were accidentally committed.

; RUN: llc  < %s -march=mipsel -mcpu=mips32 | FileCheck %s

define float @foo0(i32 %a, float %d) nounwind readnone {
entry:
; CHECK-NOT: neg.s
  %sub = fsub float -0.000000e+00, %d
  ret float %sub
}

define double @foo1(i32 %a, double %d) nounwind readnone {
entry:
; CHECK:     foo1
; CHECK-NOT: neg.d
; CHECK:     jr
  %sub = fsub double -0.000000e+00, %d
  ret double %sub
}


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

; rdar://11897677

;CHECK: intrin_pmov
;CHECK: pmovzxbw  (%rsi), %xmm0
;CHECK-NEXT: movdqu
;CHECK-NEXT: ret
define void @intrin_pmov(i16* noalias %dest, i8* noalias %src) nounwind uwtable ssp {
  %1 = bitcast i8* %src to <2 x i64>*
  %2 = load <2 x i64>* %1, align 16
  %3 = bitcast <2 x i64> %2 to <16 x i8>
  %4 = tail call <8 x i16> @llvm.x86.sse41.pmovzxbw(<16 x i8> %3) nounwind
  %5 = bitcast i16* %dest to i8*
  %6 = bitcast <8 x i16> %4 to <16 x i8>
  tail call void @llvm.x86.sse2.storeu.dq(i8* %5, <16 x i8> %6) nounwind
  ret void
}

declare <8 x i16> @llvm.x86.sse41.pmovzxbw(<16 x i8>) nounwind readnone

declare void @llvm.x86.sse2.storeu.dq(i8*, <16 x i8>) nounwind

Fix the testcase to work on all platforms.

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

; rdar://11897677

;CHECK: intrin_pmov
;CHECK: pmovzxbw  (%{{.*}}), %xmm0
;CHECK-NEXT: movdqu
;CHECK-NEXT: ret
define void @intrin_pmov(i16* noalias %dest, i8* noalias %src) nounwind uwtable ssp {
  %1 = bitcast i8* %src to <2 x i64>*
  %2 = load <2 x i64>* %1, align 16
  %3 = bitcast <2 x i64> %2 to <16 x i8>
  %4 = tail call <8 x i16> @llvm.x86.sse41.pmovzxbw(<16 x i8> %3) nounwind
  %5 = bitcast i16* %dest to i8*
  %6 = bitcast <8 x i16> %4 to <16 x i8>
  tail call void @llvm.x86.sse2.storeu.dq(i8* %5, <16 x i8> %6) nounwind
  ret void
}

declare <8 x i16> @llvm.x86.sse41.pmovzxbw(<16 x i8>) nounwind readnone

declare void @llvm.x86.sse2.storeu.dq(i8*, <16 x i8>) nounwind


; test phi node
int %main() {
	br label %Test
Test:
	%X = phi int [7, %0]
	ret int %X
}

Make phi test a bit more challenging

; test phi node
void %main() {
	br label %Test
Test:
	%X = phi int [7, %0], [%Y, %Dead]
	ret void
Dead:
	%Y = shr int 12, ubyte 4
	br label %Test
}


; RUN: llvm-as %s -o %t.o
; RUN: llvm-as %p/Inputs/resolve-to-alias.ll -o %t2.o

; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    --plugin-opt=emit-llvm \
; RUN:    -shared %t.o %t2.o -o %t.bc
; RUN: llvm-dis %t.bc -o - | FileCheck %s

define void @foo() {
  call void @bar()
  ret void
}
declare void @bar()

; CHECK: @bar = alias void (), void ()* @zed

; CHECK:      define void @foo() {
; CHECK-NEXT:   call void @bar()
; CHECK-NEXT:   ret void
; CHECK-NEXT: }

; CHECK:      define void @zed() {
; CHECK-NEXT:   ret void
; CHECK-NEXT: }

Make this test a bit more strict.

; RUN: llvm-as %s -o %t.o
; RUN: llvm-as %p/Inputs/resolve-to-alias.ll -o %t2.o

; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    --plugin-opt=emit-llvm \
; RUN:    -shared %t.o %t2.o -o %t.bc
; RUN: llvm-dis %t.bc -o %t.ll
; RUN: FileCheck --check-prefix=PASS1 %s < %t.ll
; RUN: FileCheck --check-prefix=PASS2 %s < %t.ll

; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    --plugin-opt=emit-llvm \
; RUN:    -shared %t2.o %t.o -o %t.bc
; RUN: llvm-dis %t.bc -o %t.ll
; RUN: FileCheck --check-prefix=PASS1 %s < %t.ll
; RUN: FileCheck --check-prefix=PASS2 %s < %t.ll

define void @foo() {
  call void @bar()
  ret void
}
declare void @bar()

; PASS1: @bar = alias void (), void ()* @zed

; PASS1:      define void @foo() {
; PASS1-NEXT:   call void @bar()
; PASS1-NEXT:   ret void
; PASS1-NEXT: }

; PASS2:      define void @zed() {
; PASS2-NEXT:   ret void
; PASS2-NEXT: }


; RUN: llvm-as %s -o %t.o
; RUN: llvm-as %p/Inputs/available-externally.ll -o %t2.o

; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    --plugin-opt=emit-llvm \
; RUN:    -shared %t.o %t2.o -o %t3.o
; RUN: llvm-dis %t3.o -o - | FileCheck %s

define void @foo() {
  call void @bar()
  call void @zed()
  ret void
}
define available_externally void @bar() {
  ret void
}
define available_externally void @zed() {
  ret void
}

; CHECK: define available_externally void @bar() {
; CHECK: define void @zed() {

Test both input file orders.

; RUN: llvm-as %s -o %t.o
; RUN: llvm-as %p/Inputs/available-externally.ll -o %t2.o

; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    --plugin-opt=emit-llvm \
; RUN:    -shared %t.o %t2.o -o %t3.o
; RUN: llvm-dis %t3.o -o - | FileCheck %s

; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    --plugin-opt=emit-llvm \
; RUN:    -shared %t2.o %t.o -o %t3.o
; RUN: llvm-dis %t3.o -o - | FileCheck %s

define void @foo() {
  call void @bar()
  call void @zed()
  ret void
}
define available_externally void @bar() {
  ret void
}
define available_externally void @zed() {
  ret void
}

; CHECK-DAG: define available_externally void @bar() {
; CHECK-DAG: define void @zed() {


; RUN: opt -instcombine -S -o - %s | FileCheck %s
; Test that we don't replace an alias with its aliasee when simplifying GEPs.
; In this test case the transformation is invalid because it replaces the
; reference to the symbol "b" (which refers to whichever instance of "b"
; was chosen by the linker) with a reference to "a" (which refers to the
; specific instance of "b" in this module).

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

@a = internal global [3 x i8*] zeroinitializer
@b = linkonce_odr alias [3 x i8*], [3 x i8*]* @a

define i8** @f() {
  ; CHECK: ret i8** getelementptr ([3 x i8*], [3 x i8*]* @b, i32 0, i32 1)
  ret i8** getelementptr ([3 x i8*], [3 x i8*]* @b, i32 0, i32 1)
}

Fix pointer width in test from r366754.

; RUN: opt -instcombine -S -o - %s | FileCheck %s
; Test that we don't replace an alias with its aliasee when simplifying GEPs.
; In this test case the transformation is invalid because it replaces the
; reference to the symbol "b" (which refers to whichever instance of "b"
; was chosen by the linker) with a reference to "a" (which refers to the
; specific instance of "b" in this module).

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

@a = internal global [3 x i8*] zeroinitializer
@b = linkonce_odr alias [3 x i8*], [3 x i8*]* @a

define i8** @f() {
  ; CHECK: ret i8** getelementptr ([3 x i8*], [3 x i8*]* @b, i64 0, i64 1)
  ret i8** getelementptr ([3 x i8*], [3 x i8*]* @b, i64 0, i64 1)
}


target triple = "hexagon"

define hidden void @fred() #0 {
entry:
  %0 = call { i32, i32 } asm sideeffect " $0 = usr\0A $1 = $2\0A $0 = insert($1, #1, #16)\0Ausr = $0 \0A", "=&r,=&r,r"(i1 undef) #1
  ret void
}

attributes #0 = { nounwind "target-cpu"="hexagonv60" }
attributes #1 = { nounwind }

Add RUN line to test

; RUN: llc -march=hexagon < %s | FileCheck %s
; CHECK: r[[REG0:[0-9]+]] = usr
; CHECK: [[REG0]] = insert(r{{[0-9]+}}, #1, #16)

target triple = "hexagon"

define hidden void @fred() #0 {
entry:
  %0 = call { i32, i32 } asm sideeffect " $0 = usr\0A $1 = $2\0A $0 = insert($1, #1, #16)\0Ausr = $0 \0A", "=&r,=&r,r"(i1 undef) #1
  ret void
}

attributes #0 = { nounwind "target-cpu"="hexagonv60" }
attributes #1 = { nounwind }


; RUN: llvm-as %s -o %t.o
; REQUIRES: asserts

; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    --plugin-opt=disable-verify \
; RUN:    --plugin-opt=-debug-pass=Arguments \
; RUN:    -shared %t.o -o %t2.o 2>&1 | FileCheck %s

; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    --plugin-opt=-debug-pass=Arguments \
; RUN:    -shared %t.o -o %t2.o 2>&1 | FileCheck %s -check-prefix=VERIFY

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

; -disable-verify should disable output verification from the optimization
; pipeline.
; CHECK: Pass Arguments: {{.*}} -verify -ipsccp
; CHECK-NOT: -verify

; VERIFY: Pass Arguments: {{.*}} -verify {{.*}} -verify

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

Fix gold test after r256465.

; RUN: llvm-as %s -o %t.o
; REQUIRES: asserts

; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    --plugin-opt=disable-verify \
; RUN:    --plugin-opt=-debug-pass=Arguments \
; RUN:    -shared %t.o -o %t2.o 2>&1 | FileCheck %s

; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    --plugin-opt=-debug-pass=Arguments \
; RUN:    -shared %t.o -o %t2.o 2>&1 | FileCheck %s -check-prefix=VERIFY

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

; -disable-verify should disable output verification from the optimization
; pipeline.
; CHECK: Pass Arguments: {{.*}} -verify -forceattrs
; CHECK-NOT: -verify

; VERIFY: Pass Arguments: {{.*}} -verify {{.*}} -verify

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


; RUN: llvm-as < %s | llc -march=x86 | grep pcmpeqd | count 4

define <4 x i32> @ioo() {
        ret <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
}
define <2 x i64> @loo() {
        ret <2 x i64> <i64 -1, i64 -1>
}
define <2 x double> @doo() {
        ret <2 x double> <double 0xffffffffffffffff, double 0xffffffffffffffff>
}
define <4 x float> @foo() {
        ret <4 x float> <float 0xffffffffe0000000, float 0xffffffffe0000000, float 0xffffffffe0000000, float 0xffffffffe0000000>
}

Fix this test on hosts that don't have sse2.

; RUN: llvm-as < %s | llc -march=x86 -mattr=sse2 | grep pcmpeqd | count 4

define <4 x i32> @ioo() {
        ret <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>
}
define <2 x i64> @loo() {
        ret <2 x i64> <i64 -1, i64 -1>
}
define <2 x double> @doo() {
        ret <2 x double> <double 0xffffffffffffffff, double 0xffffffffffffffff>
}
define <4 x float> @foo() {
        ret <4 x float> <float 0xffffffffe0000000, float 0xffffffffe0000000, float 0xffffffffe0000000, float 0xffffffffe0000000>
}


; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+avx < %s | FileCheck %s

; Check that this does not fail to combine concat_vectors of a value from
; merge_values through a bitcast.
define void @d() personality i8* undef {
; CHECK-LABEL: d:
; CHECK:       # %bb.0: # %entry
; CHECK-NEXT:    pushq %rax
; CHECK-NEXT:    .cfi_def_cfa_offset 16
; CHECK-NEXT:  .Ltmp0:
; CHECK-NEXT:    callq *%rax
; CHECK-NEXT:  .Ltmp1:
; CHECK-NEXT:  # %bb.1: # %bar
; CHECK-NEXT:  .Ltmp2:
; CHECK-NEXT:    callq *%rax
; CHECK-NEXT:  .Ltmp3:
; CHECK-NEXT:  # %bb.2: # %baz
; CHECK-NEXT:  .LBB1_3: # %foo
; CHECK-NEXT:  .Ltmp4:
entry:
  %call16 = invoke { i8, double } undef()
          to label %bar unwind label %foo

foo:                                              ; preds = %bar, %entry
  %0 = landingpad { i8*, i32 }
          cleanup
  br label %bazr

bar:                                              ; preds = %entry
  %1 = extractvalue { i8, double } %call16, 1
  %2 = bitcast double %1 to <2 x float>
  invoke void undef()
          to label %baz unwind label %foo

baz:                                              ; preds = %bar
  %3 = extractelement <2 x float> %2, i64 0
  br label %bazr

bazr:                                             ; preds = %baz, %foo
  %exn.obj = extractvalue { i8*, i32 } undef, 0
  unreachable
}

Simplify test case from r348759

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+avx < %s | FileCheck %s

declare { i8, double } @fun()

; Check that this does not fail to combine concat_vectors of a value from
; merge_values through a bitcast.
define void @d(i1 %cmp) {
; CHECK-LABEL: d:
; CHECK:       # %bb.0: # %bar
; CHECK-NEXT:    pushq %rax
; CHECK-NEXT:    .cfi_def_cfa_offset 16
; CHECK-NEXT:    callq fun
bar:
  %val = call { i8, double } @fun()
  %extr = extractvalue { i8, double } %val, 1
  %bc = bitcast double %extr to <2 x float>
  br label %baz

baz:
  %extr1 = extractelement <2 x float> %bc, i64 0
  unreachable
}


void %f(uint %a) {
entry:
	%tmp1032 = alloca ubyte, uint %a
	ret void
}

Add a run line to this test.

; RUN: llvm-as < %s | llc -march=arm
void %f(uint %a) {
entry:
	%tmp1032 = alloca ubyte, uint %a
	ret void
}


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

declare sbyte* %strcat(sbyte*,sbyte*)
declare int %puts(sbyte*)
%hello = constant [6 x sbyte] c"hello\00"
%null = constant [1 x sbyte] c"\00"
%null_hello = constant [7 x sbyte] c"\00hello\00"

implementation   ; Functions:

int %main () {
  %target = alloca [1024 x sbyte]
  %arg1 = getelementptr [1024 x sbyte]* %target, int 0, int 0
  store sbyte 0, sbyte* %arg1
  %arg2 = getelementptr [6 x sbyte]* %hello, int 0, int 0
  %rslt1 = call sbyte* %strcat(sbyte* %arg1, sbyte* %arg2)
  %arg3 = getelementptr [1 x sbyte]* %null, int 0, int 0
  %rslt2 = call sbyte* %strcat(sbyte* %rslt1, sbyte* %arg3)
  %arg4 = getelementptr [7 x sbyte]* %null_hello, int 0, int 0
  %rslt3 = call sbyte* %strcat(sbyte* %rslt2, sbyte* %arg4)
  call int %puts(sbyte* %rslt3)
  ret int 0
}

Fix RUN: line to not always pass.

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

declare sbyte* %strcat(sbyte*,sbyte*)
declare int %puts(sbyte*)
%hello = constant [6 x sbyte] c"hello\00"
%null = constant [1 x sbyte] c"\00"
%null_hello = constant [7 x sbyte] c"\00hello\00"

implementation   ; Functions:

int %main () {
  %target = alloca [1024 x sbyte]
  %arg1 = getelementptr [1024 x sbyte]* %target, int 0, int 0
  store sbyte 0, sbyte* %arg1
  %arg2 = getelementptr [6 x sbyte]* %hello, int 0, int 0
  %rslt1 = call sbyte* %strcat(sbyte* %arg1, sbyte* %arg2)
  %arg3 = getelementptr [1 x sbyte]* %null, int 0, int 0
  %rslt2 = call sbyte* %strcat(sbyte* %rslt1, sbyte* %arg3)
  %arg4 = getelementptr [7 x sbyte]* %null_hello, int 0, int 0
  %rslt3 = call sbyte* %strcat(sbyte* %rslt2, sbyte* %arg4)
  call int %puts(sbyte* %rslt3)
  ret int 0
}


; RUN: llc -asm-verbose=false -march=x86-64 -o - < %s | FileCheck %s

; LSR should leave non-affine expressions alone because it currently
; doesn't know how to do anything with them, and when it tries, it
; gets SCEVExpander's current expansion for them, which is suboptimal.

; CHECK:        xorl %eax, %eax
; CHECK-NEXT:   align
; CHECK-NEXT: BB0_1:
; CHECK-NEXT:   movq  %rax, (%{{rdx|r8}})
; CHECK-NEXT:   addq  %{{rsi|rdx}}, %rax
; CHECK-NEXT:   cmpq  %{{rdi|rcx}}, %rax
; CHECK-NEXT:   jl
; CHECK-NEXT:   imulq %rax, %rax
; CHECK-NEXT:   ret
define i64 @foo(i64 %n, i64 %s, i64* %p) nounwind {
entry:
  br label %loop

loop:
  %i = phi i64 [ 0, %entry ], [ %i.next, %loop ]
  volatile store i64 %i, i64* %p
  %i.next = add i64 %i, %s
  %c = icmp slt i64 %i.next, %n
  br i1 %c, label %loop, label %exit

exit:
  %mul = mul i64 %i.next, %i.next
  ret i64 %mul
}

Revert r134366 and add an explicit triple to make this test host-independent.

; RUN: llc -asm-verbose=false -march=x86-64 -mtriple=x86_64-apple-darwin -o - < %s | FileCheck %s

; LSR should leave non-affine expressions alone because it currently
; doesn't know how to do anything with them, and when it tries, it
; gets SCEVExpander's current expansion for them, which is suboptimal.

; CHECK:        xorl %eax, %eax
; CHECK-NEXT:   align
; CHECK-NEXT: BB0_1:
; CHECK-NEXT:   movq  %rax, (%rdx)
; CHECK-NEXT:   addq  %rsi, %rax
; CHECK-NEXT:   cmpq  %rdi, %rax
; CHECK-NEXT:   jl
; CHECK-NEXT:   imulq %rax, %rax
; CHECK-NEXT:   ret
define i64 @foo(i64 %n, i64 %s, i64* %p) nounwind {
entry:
  br label %loop

loop:
  %i = phi i64 [ 0, %entry ], [ %i.next, %loop ]
  volatile store i64 %i, i64* %p
  %i.next = add i64 %i, %s
  %c = icmp slt i64 %i.next, %n
  br i1 %c, label %loop, label %exit

exit:
  %mul = mul i64 %i.next, %i.next
  ret i64 %mul
}


; RUN: llc < %s -fast-isel -fast-isel-abort -march=x86-64 | FileCheck %s
; RUN: llc < %s -fast-isel -march=x86 | grep xor | count 2

; CHECK: doo:
; CHECK: xor
define double @doo(double %x) nounwind {
  %y = fsub double -0.0, %x
  ret double %y
}

; CHECK: foo:
; CHECK: xor
define float @foo(float %x) nounwind {
  %y = fsub float -0.0, %x
  ret float %y
}

Add -mattr=+sse2 to the -march=x86 version of this test. Without sse, this code falls back to SelectionDAG isel which uses an x87 instruction, which is fine, but not what this test is testing for.

; RUN: llc < %s -fast-isel -fast-isel-abort -march=x86-64 | FileCheck %s
; RUN: llc < %s -fast-isel -march=x86 -mattr=+sse2 | grep xor | count 2

; CHECK: doo:
; CHECK: xor
define double @doo(double %x) nounwind {
  %y = fsub double -0.0, %x
  ret double %y
}

; CHECK: foo:
; CHECK: xor
define float @foo(float %x) nounwind {
  %y = fsub float -0.0, %x
  ret float %y
}


; If the result of an instruction is only used outside of the loop, sink
; the instruction to the exit blocks instead of executing it on every
; iteration of the loop.
;
; RUN: llvm-as < %s | opt -licm | llvm-dis | grep -C1 mul | grep Out:

int %test(int %N) {
Entry:
	br label %Loop
Loop:
        %N_addr.0.pn = phi int [ %dec, %Loop ], [ %N, %Entry ]
        %tmp.6 = mul int %N, %N_addr.0.pn
        %dec = add int %N_addr.0.pn, -1
        %tmp.1 = setne int %N_addr.0.pn, 1
        br bool %tmp.1, label %Loop, label %Out
Out:
	ret int %tmp.6
}

Make the test a bit harder so that we test to ensure that _both_ instructions are sunk

; If the result of an instruction is only used outside of the loop, sink
; the instruction to the exit blocks instead of executing it on every
; iteration of the loop.
;
; RUN: llvm-as < %s | opt -licm | llvm-dis | grep -C1 mul | grep Out:

int %test(int %N) {
Entry:
	br label %Loop
Loop:
        %N_addr.0.pn = phi int [ %dec, %Loop ], [ %N, %Entry ]
        %tmp.6 = mul int %N, %N_addr.0.pn
        %tmp.7 = sub int %tmp.6, %N
        %dec = add int %N_addr.0.pn, -1
        %tmp.1 = setne int %N_addr.0.pn, 1
        br bool %tmp.1, label %Loop, label %Out
Out:
	ret int %tmp.7
}


; The %A getelementptr instruction should be eliminated here

; RUN: if as < %s | opt -instcombine -die | 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
}

Add new testcase for gep instruction -> get constexpr promotion

; The %A getelementptr instruction should be eliminated here

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

%Global = constant [10 x sbyte] c"helloworld"

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
}

sbyte * %foo5() {
	; This should be turned into a constexpr instead of being an instruction
	%A = getelementptr [10 x sbyte]* %Global, uint 0, uint 4
	ret sbyte* %A
}


; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep sub &&
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep add

<4 x float> %test(<4 x float> %tmp26, <4 x float> %tmp53) {
  ; (X+Y)-Y != X for fp vectors.
  %tmp64 = add <4 x float> %tmp26, %tmp53
  %tmp75 = sub <4 x float> %tmp64, %tmp53
  ret <4 x float> %tmp75
}

Update this test to use llvm-update.

; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep sub &&
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep add

<4 x float> %test(<4 x float> %tmp26, <4 x float> %tmp53) {
  ; (X+Y)-Y != X for fp vectors.
  %tmp64 = add <4 x float> %tmp26, %tmp53
  %tmp75 = sub <4 x float> %tmp64, %tmp53
  ret <4 x float> %tmp75
}


; This test makes sure that these instructions are properly eliminated.
;

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

implementation

int "test1"(int %A) {
BB0:	br label %BB1
BB1:
	%B = phi int [%A, %BB0]     ; Combine away one argument PHI nodes
	ret int %B
}

Make the testcase more interesting so that DCE does not eliminate it. Use DIE instead of DCE anyway

; This test makes sure that these instructions are properly eliminated.
;

; RUN: if as < %s | opt -instcombine -die | dis | grep phi
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

implementation

int "test1"(int %A, bool %b) {
BB0:    br bool %b, label %BB1, label %BB2
BB1:
        %B = phi int [%A, %BB0]     ; Combine away one argument PHI nodes
        ret int %B
BB2:
        ret int %A
}


; R UN: llc < %s -march=x86-64 | FileCheck %s
; R UN: llc < %s -march=x86 | FileCheck %s
; C HECK: _memcpy
define void @foo([40000 x i32] *%P) nounwind {
  call void @bar([40000 x i32] * byval align 1 %P)
  ret void
}

declare void @bar([40000 x i32] *%P )

Tweak test to work on Linux.

; RUN: llc < %s -march=x86-64 | FileCheck %s
; RUN: llc < %s -march=x86 | FileCheck %s
; CHECK: memcpy
define void @foo([40000 x i32] *%P) nounwind {
  call void @bar([40000 x i32] * byval align 1 %P)
  ret void
}

declare void @bar([40000 x i32] *%P )


; RUN: llvm-as < %s | llc -march=x86 -mattr=sse2 -disable-mmx -o %t -f
; RUN: grep divdi3  %t | count 2

; Test case for r63760 where we generate a legalization assert that an illegal
; type has been inserted by LegalizeDAG after LegalizeType has run. With sse2,
; v2i64 is a legal type but with mmx disabled, i64 is an illegal type. When
; legalizing the divide in LegalizeDAG, we scalarize the vector divide and make
; two 64 bit divide library calls which introduces i64 nodes that needs to be
; promoted.

define <2 x i64> @test_long_div(<2 x i64> %num, <2 x i64> %div) {
  %div.r = sdiv <2 x i64> %num, %div
  ret <2 x i64>  %div.r
}

Make the grep line in this test more specific, to avoid unintended matches.

; RUN: llvm-as < %s | llc -march=x86 -mattr=sse2 -disable-mmx -o %t -f
; RUN: grep {call.*divdi3}  %t | count 2

; Test case for r63760 where we generate a legalization assert that an illegal
; type has been inserted by LegalizeDAG after LegalizeType has run. With sse2,
; v2i64 is a legal type but with mmx disabled, i64 is an illegal type. When
; legalizing the divide in LegalizeDAG, we scalarize the vector divide and make
; two 64 bit divide library calls which introduces i64 nodes that needs to be
; promoted.

define <2 x i64> @test_long_div(<2 x i64> %num, <2 x i64> %div) {
  %div.r = sdiv <2 x i64> %num, %div
  ret <2 x i64>  %div.r
}


; This testcase ensures that redundant loads are preserved when they are not
; allowed to be eliminated.
; RUN: as < %s | dis > Output/%s.before
; RUN: as < %s | opt -load-vn -gcse | dis > Output/%s.after
; RUN: echo some output
; RUN: diff Output/%s.before Output/%s.after
;
int "test1"(int* %P) {
	%A = load int* %P
	store int 1, int * %P
	%B = load int* %P
	%C = add int %A, %B
	ret int %C
}

int "test2"(int* %P) {
	%A = load int* %P
	br label %BB2
BB2:
	store int 5, int * %P
	br label %BB3
BB3:
	%B = load int* %P
	%C = add int %A, %B
	ret int %C
}

Fix testcase to work with store forwarding

; This testcase ensures that redundant loads are preserved when they are not
; allowed to be eliminated.
; RUN: as < %s | opt -load-vn -gcse | dis | grep sub
;
int %test1(int* %P) {
	%A = load int* %P
	store int 1, int* %P
	%B = load int* %P
	%C = sub int %A, %B
	ret int %C
}

int %test2(int* %P) {
	%A = load int* %P
	br label %BB2
BB2:
	store int 5, int* %P
	br label %BB3
BB3:
	%B = load int* %P
	%C = sub int %A, %B
	ret int %C
}


; RUN: llvm-as < %s | llc -march=x86 | grep 18446744073709551615 | count 14
; RUN: llvm-as < %s | llc -march=ppc32 | grep 4294967295 | count 28

; These static initializers are too big to hand off to assemblers
; as monolithic blobs.

@x = global i128 -1
@y = global i256 -1
@z = global i512 -1

Add a target triple; apparently LLVM doesn't use 64-bit data directives on darwin.

; RUN: llvm-as < %s | llc -march=x86 -mtriple=i686-pc-linux-gnu | grep 18446744073709551615 | count 14
; RUN: llvm-as < %s | llc -march=ppc32 | grep 4294967295 | count 28

; These static initializers are too big to hand off to assemblers
; as monolithic blobs.

@x = global i128 -1
@y = global i256 -1
@z = global i512 -1


; Instcombine was missing a test that caused it to make illegal transformations
; sometimes.  In this case, it transforms the sub into an add:
; RUN: if as < %s | opt -instcombine | dis | grep add
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi
;

int "test"(int %i, int %j) {
	%A = mul int %i, %j
	%B = sub int 2, %A
	ret int %B
}

Make sure there is SOME output always so the test is not rerun when unneccesary.

; Instcombine was missing a test that caused it to make illegal transformations
; sometimes.  In this case, it transforms the sub into an add:
; RUN: echo foo
; RUN: if as < %s | opt -instcombine | dis | grep add
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi
;

int "test"(int %i, int %j) {
	%A = mul int %i, %j
	%B = sub int 2, %A
	ret int %B
}


; RUN: llc -march amdgcn %s -filetype=obj
; RUN: llc -march amdgcn <%s | FileCheck %s
define amdgpu_kernel void @f() {
  ; CHECK: ; divergent unreachable
  call void @llvm.amdgcn.unreachable()
  ret void
}

declare void @llvm.amdgcn.unreachable()

Fix test from polluting the source tree

; RUN: llc -march amdgcn %s -filetype=obj -o /dev/null
; RUN: llc -march amdgcn <%s | FileCheck %s
define amdgpu_kernel void @f() {
  ; CHECK: ; divergent unreachable
  call void @llvm.amdgcn.unreachable()
  ret void
}

declare void @llvm.amdgcn.unreachable()


; RUN: llvm-as < %s | llvm-dis > %t1.ll
; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
; RUN: diff %t1.ll %t2.ll
; XFAIL: *
%union.anon = type union { i8, i32, float }

@union1 = constant union { i32, i8 } { i32 4 }
@union2 = constant union { i32, i8 } insertvalue(union { i32, i8 } undef, i32 4, 0)

define void @"Unions" () {
  ret void
}

Revert r98666 too; it's checkin-without-testing day!

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

%union.anon = type union { i8, i32, float }

@union1 = constant union { i32, i8 } { i32 4 }
@union2 = constant union { i32, i8 } insertvalue(union { i32, i8 } undef, i32 4, 0)

define void @"Unions" () {
  ret void
}


; RUN: llc < %s -march=x86 | FileCheck %s
; This should not load or store the top part of *P.

define void @test(i64* %P) nounwind  {
; CHECK-LABEL: test:
; CHECK: movl 4(%esp), %[[REGISTER:.*]]
; CHECK-NOT: 4(%[[REGISTER]])
; CHECK: ret
	%tmp1 = load i64, i64* %P, align 8		; <i64> [#uses=1]
	%tmp2 = xor i64 %tmp1, 1		; <i64> [#uses=1]
	store i64 %tmp2, i64* %P, align 8
	ret void
}

Fix old testcase for dead store to match the original intent.

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -mtriple=i686-pc-linux-gnu | FileCheck %s
; FIXME: This should not load or store the top part of *P.

define void @test(i64* %P) nounwind  {
; CHECK-LABEL: test:
; CHECK:       # BB#0:
; CHECK-NEXT:    movl {{[0-9]+}}(%esp), %eax
; CHECK-NEXT:    movl (%eax), %ecx
; CHECK-NEXT:    movl 4(%eax), %edx
; CHECK-NEXT:    xorl $1, %ecx
; CHECK-NEXT:    orl $2, %ecx
; CHECK-NEXT:    movl %edx, 4(%eax)
; CHECK-NEXT:    movl %ecx, (%eax)
; CHECK-NEXT:    retl
        %tmp1 = load i64, i64* %P, align 8
        %tmp2 = xor i64 %tmp1, 1
        %tmp3 = or i64 %tmp2, 2
        store i64 %tmp3, i64* %P, align 8
        ret void
}


; REQUIRES: x86
; RUN: llvm-as %s -o %t1.o
; RUN: ld.lld -m elf_x86_64 %t1.o %t1.o -o %t.so -shared

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

; Should not encounter a duplicate symbol error for @.str
@.str = private unnamed_addr constant [4 x i8] c"Hey\00", align 1

; Should not encounter a duplicate symbol error for @llvm.global_ctors
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @ctor, i8* null }]
define internal void @ctor() {
  ret void
}

Add a useful test case.

; REQUIRES: x86
; RUN: llvm-as %s -o %t1.o
; RUN: ld.lld -m elf_x86_64 %t1.o %t1.o -o %t.so -shared

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

; Should not encounter a duplicate symbol error for @.str
@.str = private unnamed_addr constant [4 x i8] c"Hey\00", align 1

; Should not encounter a duplicate symbol error for @llvm.global_ctors
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @ctor, i8* null }]
define internal void @ctor() {
  ret void
}

; Should not try to merge a declaration into the combined module.
declare i32 @llvm.ctpop.i32(i32)


; PR1318
; RUN: llvm-as < %s > %t.bc &&
; RUN: opt -load=%llvmlibsdir/LLVMHello%shlibext -hello \
; RUN:   -disable-output %t.bc 2>&1 | grep Hello

@junk = global i32 0

define i32* @somefunk() {
  ret i32* @junk
}

Simplify this test and correct redirection for Tcl exec.

; PR1318
; RUN: llvm-as < %s | opt -load=%llvmlibsdir/LLVMHello%shlibext -hello \
; RUN:   -disable-output - |& grep Hello

@junk = global i32 0

define i32* @somefunk() {
  ret i32* @junk
}


; 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

; RUN: llvm-lto -thinlto-action=import %t.bc -thinlto-index=%t3.bc -o - | llvm-bcanalyzer -dump | FileCheck %s

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

; 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

Replace test from using llvm-lto to use llvm-link (NFC)

; 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


; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm &&
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm | grep align.*1 | wc | grep 1 &&
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm | grep align.*2 | wc | grep 2 &&
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm | grep align.*3 | wc | grep 2

%a = global bool true
%b = global sbyte 1
%c = global short 2
%d = global int 3
%e = global long 4
%f = global float 5.0
%g = global double 6.0

Make it work for both Linux and Mac OS.

; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm &&
; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm | grep align.*1 | wc | grep 1 &&
; RUN: llvm-upgrade < %s | llvm-as | llc -mtriple=arm-linux | grep align.*2 | wc | grep 2 &&
; RUN: llvm-upgrade < %s | llvm-as | llc -mtriple=arm-linux | grep align.*3 | wc | grep 2
; RUN: llvm-upgrade < %s | llvm-as | llc -mtriple=arm-apple-darwin | grep align.*2 | wc | grep 4

%a = global bool true
%b = global sbyte 1
%c = global short 2
%d = global int 3
%e = global long 4
%f = global float 5.0
%g = global double 6.0


; RUN: llvm-upgrade < %s | llvm-as | opt -loop-unroll -disable-output

void @sal__math_float_manipulator_7__math__joint_array_dcv_ops__Omultiply__3([6 x float]* %agg.result) {
entry:
	%tmp282911 = zext i8 0 to i32		; <i32> [#uses=1]
	br label %cond_next

cond_next:		; preds = %cond_next, %entry
	%indvar = phi i8 [ 0, %entry ], [ %indvar.next, %cond_next ]		; <i8> [#uses=1]
	%indvar.next = add i8 %indvar, 1		; <i8> [#uses=2]
	%exitcond = icmp eq i8 %indvar.next, 7		; <i1> [#uses=1]
	br i1 %exitcond, label %bb27, label %cond_next

bb27:		; preds = %cond_next
	%tmp282911.lcssa = phi i32 [ %tmp282911, %cond_next ]		; <i32> [#uses=0]
	ret void
}

Add PR number for reference.

; PR 1334
; RUN: llvm-upgrade < %s | llvm-as | opt -loop-unroll -disable-output

void @sal__math_float_manipulator_7__math__joint_array_dcv_ops__Omultiply__3([6 x float]* %agg.result) {
entry:
	%tmp282911 = zext i8 0 to i32		; <i32> [#uses=1]
	br label %cond_next

cond_next:		; preds = %cond_next, %entry
	%indvar = phi i8 [ 0, %entry ], [ %indvar.next, %cond_next ]		; <i8> [#uses=1]
	%indvar.next = add i8 %indvar, 1		; <i8> [#uses=2]
	%exitcond = icmp eq i8 %indvar.next, 7		; <i1> [#uses=1]
	br i1 %exitcond, label %bb27, label %cond_next

bb27:		; preds = %cond_next
	%tmp282911.lcssa = phi i32 [ %tmp282911, %cond_next ]		; <i32> [#uses=0]
	ret void
}


; RUN: llc < %s -march=x86 -relocation-model=pic -disable-fp-elim -unwind-tables | FileCheck %s
; <rdar://problem/7383328>

@.str = private constant [12 x i8] c"hello world\00", align 1 ; <[12 x i8]*> [#uses=1]

define hidden void @func() nounwind ssp {
entry:
  %0 = call i32 @puts(i8* getelementptr inbounds ([12 x i8]* @.str, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
  br label %return

return:                                           ; preds = %entry
  ret void
}

declare i32 @puts(i8*)

define hidden i32 @main() nounwind ssp {
entry:
  %retval = alloca i32                            ; <i32*> [#uses=1]
  %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
  call void @func() nounwind
  br label %return

return:                                           ; preds = %entry
  %retval1 = load i32* %retval                    ; <i32> [#uses=1]
  ret i32 %retval1
}

; CHECK: .private_extern _func.eh
; CHECK: .private_extern _main.eh

Fix test to work on every platform.

; RUN: llc < %s -mtriple=i386-apple-darwin9 -relocation-model=pic -disable-fp-elim -unwind-tables | FileCheck %s
; <rdar://problem/7383328>

@.str = private constant [12 x i8] c"hello world\00", align 1 ; <[12 x i8]*> [#uses=1]

define hidden void @func() nounwind ssp {
entry:
  %0 = call i32 @puts(i8* getelementptr inbounds ([12 x i8]* @.str, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
  br label %return

return:                                           ; preds = %entry
  ret void
}

declare i32 @puts(i8*)

define hidden i32 @main() nounwind ssp {
entry:
  %retval = alloca i32                            ; <i32*> [#uses=1]
  %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
  call void @func() nounwind
  br label %return

return:                                           ; preds = %entry
  %retval1 = load i32* %retval                    ; <i32> [#uses=1]
  ret i32 %retval1
}

; CHECK: .private_extern _func.eh
; CHECK: .private_extern _main.eh


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

uint %test_extractelement(<4 x uint> %V) {
	%R = extractelement <4 x uint> %V, uint 1
	ret uint %R
}

Test case for the insertelement operation.

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

uint %test_extractelement(<4 x uint> %V) {
        %R = extractelement <4 x uint> %V, uint 1
        ret uint %R
}

<4 x uint> %test_insertelement(<4 x uint> %V) {
        %R = insertelement <4 x uint> %V, uint 0, uint 0
        ret <4 x uint> %R
}


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

declare i8* @fopen(i8*, i8*)
; CHECK: declare noalias i8* @fopen(i8* nocapture, i8* nocapture) [[G0:#[0-9]]]

declare i8 @strlen(i8*)
; CHECK: declare i8 @strlen(i8* nocapture) [[G1:#[0-9]]]

declare i32* @realloc(i32*, i32)
; CHECK: declare noalias i32* @realloc(i32* nocapture, i32) [[G0]]

; Test deliberately wrong declaration

declare i32 @strcpy(...)
; CHECK: declare i32 @strcpy(...)

declare i32 @gettimeofday(i8*, i8*)
; CHECK: declare i32 @gettimeofday(i8* nocapture, i8* nocapture) [[G0]]

; CHECK: attributes [[G0]] = { nounwind }
; CHECK: attributes [[G1]] = { nounwind readonly }

Change the gettimeofday test to only test on a posix platform.

; RUN: opt < %s -functionattrs -S | FileCheck %s
; RUN: opt < %s -mtriple=x86_64-apple-macosx10.8.0 -functionattrs -S | FileCheck -check-prefix=POSIX %s

declare i8* @fopen(i8*, i8*)
; CHECK: declare noalias i8* @fopen(i8* nocapture, i8* nocapture) [[G0:#[0-9]]]

declare i8 @strlen(i8*)
; CHECK: declare i8 @strlen(i8* nocapture) [[G1:#[0-9]]]

declare i32* @realloc(i32*, i32)
; CHECK: declare noalias i32* @realloc(i32* nocapture, i32) [[G0]]

; Test deliberately wrong declaration

declare i32 @strcpy(...)
; CHECK: declare i32 @strcpy(...)

declare i32 @gettimeofday(i8*, i8*)
; CHECK-POSIX: declare i32 @gettimeofday(i8* nocapture, i8* nocapture) [[G0:#[0-9]+]]

; CHECK: attributes [[G0]] = { nounwind }
; CHECK: attributes [[G1]] = { nounwind readonly }
; CHECK-POSIX: attributes [[G0]] = { nounwind }


; RUN: llvm-profdata merge %S/Inputs/diag.proftext -o %T/diag.profdata
; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%T/diag.profdata -S 2>&1 | FileCheck %s

; CHECK: No profile data available for function bar

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

define i32 @bar() {
entry:
  ret i32 0
}

Rename the profdata filename to avoid the conflict b/w tests.

; RUN: llvm-profdata merge %S/Inputs/diag.proftext -o %T/diag2.profdata
; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%T/diag2.profdata -S 2>&1 | FileCheck %s

; CHECK: No profile data available for function bar

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

define i32 @bar() {
entry:
  ret i32 0
}


; RUN: llc < %s | FileCheck %s

target triple = "x86_64-linux-gnu"

define coldcc void @foo() {
; CHECK: pushq %rbp
; CHECK: pushq %r15
; CHECK: pushq %r14
; CHECK: pushq %r13
; CHECK: pushq %r12
; CHECK: pushq %r11
; CHECK: pushq %r10
; CHECK: pushq %r9
; CHECK: pushq %r8
; CHECK: pushq %rdi
; CHECK: pushq %rsi
; CHECK: pushq %rdx
; CHECK: pushq %rcx
; CHECK: pushq %rbx
; CHECK: vmovaps %xmm15
; CHECK: vmovaps %xmm0
  call void asm sideeffect "", "~{xmm15},~{xmm0},~{rbp},~{r15},~{r14},~{r13},~{r12},~{r11},~{r10},~{r9},~{r8},~{rdi},~{rsi},~{rdx},~{rcx},~{rbx}"()
  ret void
}

Fix test by matching movaps instead of AVX-only vmovaps

; RUN: llc < %s | FileCheck %s

target triple = "x86_64-linux-gnu"

define coldcc void @foo() {
; CHECK: pushq %rbp
; CHECK: pushq %r15
; CHECK: pushq %r14
; CHECK: pushq %r13
; CHECK: pushq %r12
; CHECK: pushq %r11
; CHECK: pushq %r10
; CHECK: pushq %r9
; CHECK: pushq %r8
; CHECK: pushq %rdi
; CHECK: pushq %rsi
; CHECK: pushq %rdx
; CHECK: pushq %rcx
; CHECK: pushq %rbx
; CHECK: movaps %xmm15
; CHECK: movaps %xmm0
  call void asm sideeffect "", "~{xmm15},~{xmm0},~{rbp},~{r15},~{r14},~{r13},~{r12},~{r11},~{r10},~{r9},~{r8},~{rdi},~{rsi},~{rdx},~{rcx},~{rbx}"()
  ret void
}


; RUN: llc < %s -mtriple=i686-apple-darwin -mattr=+sse2 | grep mov | grep ecx | grep 0
; RUN: llc < %s -mtriple=i686-apple-darwin -mattr=+sse2 | grep mov | grep xmm0 | grep 8

@d = external global double		; <double*> [#uses=1]
@c = external global double		; <double*> [#uses=1]
@b = external global double		; <double*> [#uses=1]
@a = external global double		; <double*> [#uses=1]

define i32 @foo() nounwind {
entry:
	%0 = load double* @d, align 8		; <double> [#uses=1]
	%1 = load double* @c, align 8		; <double> [#uses=1]
	%2 = load double* @b, align 8		; <double> [#uses=1]
	%3 = load double* @a, align 8		; <double> [#uses=1]
	tail call fastcc void @bar( i32 0, i32 1, i32 2, double 1.000000e+00, double %3, double %2, double %1, double %0 ) nounwind
	ret i32 0
}

declare fastcc void @bar(i32, i32, i32, double, double, double, double, double)

Fix this test to account for a movl $0 being emitted as an xor now, and convert it to FileCheck.

; RUN: llc < %s -mtriple=i686-apple-darwin -mattr=+sse2 | FileCheck %s
; CHECK: movsd %xmm0, 8(%esp)
; CHECK: xorl %ecx, %ecx

@d = external global double		; <double*> [#uses=1]
@c = external global double		; <double*> [#uses=1]
@b = external global double		; <double*> [#uses=1]
@a = external global double		; <double*> [#uses=1]

define i32 @foo() nounwind {
entry:
	%0 = load double* @d, align 8		; <double> [#uses=1]
	%1 = load double* @c, align 8		; <double> [#uses=1]
	%2 = load double* @b, align 8		; <double> [#uses=1]
	%3 = load double* @a, align 8		; <double> [#uses=1]
	tail call fastcc void @bar( i32 0, i32 1, i32 2, double 1.000000e+00, double %3, double %2, double %1, double %0 ) nounwind
	ret i32 0
}

declare fastcc void @bar(i32, i32, i32, double, double, double, double, double)


; RUN: llvm-as < %s | llc -march=x86 | grep {orl	\$1}

define i32 @test(i32 %A) nounwind {
  %B = or i32 %A, 1
  %C = or i32 %B, 1
  %D = and i32 %C, 7057
  ret i32 %D
}

Add a PR comment to this test.

; RUN: llvm-as < %s | llc -march=x86 | grep {orl	\$1}
; PR3018

define i32 @test(i32 %A) nounwind {
  %B = or i32 %A, 1
  %C = or i32 %B, 1
  %D = and i32 %C, 7057
  ret i32 %D
}


; RUN: llc < %s -mtriple=i386-apple-darwin9 | grep no_dead_strip | count 1
; We should have a .no_dead_strip directive for Z but not for X/Y.

@X = internal global i8 4
@Y = internal global i32 123
@Z = internal global i8 4

@llvm.used = appending global [1 x i8*] [ i8* @Z ], section "llvm.metadata"
@llvm.compiler_used = appending global [2 x i8*] [ i8* @X, i8* bitcast (i32* @Y to i8*)], section "llvm.metadata"

Move test from grep to FileCheck.

; RUN: llc < %s -mtriple=i386-apple-darwin9 | FileCheck %s

@X = internal global i8 4
@Y = internal global i32 123
@Z = internal global i8 4

@llvm.used = appending global [1 x i8*] [ i8* @Z ], section "llvm.metadata"
@llvm.compiler_used = appending global [2 x i8*] [ i8* @X, i8* bitcast (i32* @Y to i8*)], section "llvm.metadata"

; CHECK-NOT: .no_dead_strip
; CHECK: .no_dead_strip	_Z
; CHECK-NOT: .no_dead_strip


; Test that the StrCatOptimizer works correctly
; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | not grep 'pow'

declare double %pow(double,double)
%fpstorage = global double 5.0

implementation   ; Functions:

int %main () {
  %fpnum = load double* %fpstorage;
  %one = call double %pow(double 1.0, double %fpnum)
  %two = call double %pow(double %one, double 0.5)
  %three = call double %pow(double %two, double 1.0)
  %four = call double %pow(double %three, double -1.0)
  %five = call double %pow(double %four, double 0.0)
  %result = cast double %five to int
  ret int %result
}

Fix the success criteria for the test to make call instructions with "pow" not just any occurrence of "pow".

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

declare double %pow(double,double)
%fpstorage = global double 5.0

implementation   ; Functions:

int %main () {
  %fpnum = load double* %fpstorage;
  %one = call double %pow(double 1.0, double %fpnum)
  %two = call double %pow(double %one, double 0.5)
  %three = call double %pow(double %two, double 1.0)
  %four = call double %pow(double %three, double -1.0)
  %five = call double %pow(double %four, double 0.0)
  %result = cast double %five to int
  ret int %result
}


; RUN: llc < %s -march=thumb | grep bne | count 1
; RUN: llc < %s -march=thumb | grep beq | count 1

define i32 @f1(float %X, float %Y) {
	%tmp = fcmp uno float %X, %Y
	%retval = select i1 %tmp, i32 1, i32 -1
	ret i32 %retval
}

define i32 @f2(float %X, float %Y) {
	%tmp = fcmp ord float %X, %Y
	%retval = select i1 %tmp, i32 1, i32 -1
	ret i32 %retval
}

Use FileCheck and expand the test a bit.

; RUN: llc < %s -mtriple=thumb-apple-darwin | FileCheck %s

define i32 @f1(float %X, float %Y) {
; CHECK-LABEL _f1:
; CHECK: bne
; CHECK: .data_region
; CHECK: .long   ___unordsf2
	%tmp = fcmp uno float %X, %Y
	%retval = select i1 %tmp, i32 1, i32 -1
	ret i32 %retval
}

define i32 @f2(float %X, float %Y) {
; CHECK-LABEL _f2:
; CHECK: beq
; CHECK: .data_region
; CHECK: .long   ___unordsf2
	%tmp = fcmp ord float %X, %Y
	%retval = select i1 %tmp, i32 1, i32 -1
	ret i32 %retval
}


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

define zeroext i1 @f1(i8* %x) {
entry:
  %0 = load i8* %x, align 1, !range !0
  %tobool = trunc i8 %0 to i1
  ret i1 %tobool
}

; CHECK: f1:
; CHECK: movb	(%rdi), %al
; CHECK-NEXT: ret

!0 = metadata !{i8 0, i8 2}

Add a triple to the test.

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

define zeroext i1 @f1(i8* %x) {
entry:
  %0 = load i8* %x, align 1, !range !0
  %tobool = trunc i8 %0 to i1
  ret i1 %tobool
}

; CHECK: f1:
; CHECK: movb	(%rdi), %al
; CHECK-NEXT: ret

!0 = metadata !{i8 0, i8 2}


; RUN: opt < %s -basicaa -newgvn -instcombine -S | FileCheck %s
; PR4189
@G = external constant [4 x i32]

define i32 @test(i8* %p, i32 %i) nounwind {
entry:
	%P = getelementptr [4 x i32], [4 x i32]* @G, i32 0, i32 %i
	%A = load i32, i32* %P
	store i8 4, i8* %p
	%B = load i32, i32* %P
	%C = sub i32 %A, %B
	ret i32 %C
}

; CHECK: define i32 @test(i8* %p, i32 %i) #0 {
; CHECK-NEXT: entry:
; CHECK-NEXT:   store i8 4, i8* %p, align 1
; CHECK-NEXT:   ret i32 0
; CHECK-NEXT: }

Fix test so that it doesn't rely on InstCombine anymore.

; RUN: opt < %s -basicaa -newgvn -S | FileCheck %s
; PR4189
@G = external constant [4 x i32]

define i32 @test(i8* %p, i32 %i) nounwind {
entry:
	%P = getelementptr [4 x i32], [4 x i32]* @G, i32 0, i32 %i
	%A = load i32, i32* %P
	store i8 4, i8* %p
	%B = load i32, i32* %P
	%C = sub i32 %A, %B
	ret i32 %C
}

; CHECK-LABEL: define i32 @test
; CHECK-NEXT: entry:
; CHECK-NEXT:   %P = getelementptr [4 x i32], [4 x i32]* @G, i32 0, i32 %i
; CHECK-NEXT:   %A = load i32, i32* %P
; CHECK-NEXT:   store i8 4, i8* %p
; CHECK-NEXT:   ret i32 0
; CHECK-NEXT: }


; RUN: llc < %s -march=x86-64 | FileCheck %s
; Verify that we are using the efficient uitofp --> sitofp lowering illustrated
; by the compiler_rt implementation of __floatundisf.
; <rdar://problem/8493982>

target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-apple-darwin10.0.0"

; CHECK: testq %rdi, %rdi
; CHECK-NEXT: jns LBB0_2
; CHECK: shrq
; CHECK-NEXT: andq
; CHECK-NEXT: orq
; CHECK-NEXT: cvtsi2ss
; CHECK: LBB0_2
; CHECK-NEXT: cvtsi2ss
define float @test(i64 %a) {
entry:
  %b = uitofp i64 %a to float
  ret float %b
}

Use –mcpu=generic, so that the test will not fail when run on an Intel Atom processor, due to the Atom scheduler producing an instruction sequence that is different from that which is expected. Patch by Michael Spencer!

; RUN: llc < %s -mcpu=generic -march=x86-64 | FileCheck %s
; Verify that we are using the efficient uitofp --> sitofp lowering illustrated
; by the compiler_rt implementation of __floatundisf.
; <rdar://problem/8493982>

target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-apple-darwin10.0.0"

; CHECK: testq %rdi, %rdi
; CHECK-NEXT: jns LBB0_2
; CHECK: shrq
; CHECK-NEXT: andq
; CHECK-NEXT: orq
; CHECK-NEXT: cvtsi2ss
; CHECK: LBB0_2
; CHECK-NEXT: cvtsi2ss
define float @test(i64 %a) {
entry:
  %b = uitofp i64 %a to float
  ret float %b
}


; Test to make sure that the 'private' is used correctly.
;
; RUN: llvm-as < %s | llc -mtriple=powerpc-unknown-linux-gnu | FileCheck %s -check-prefix=LINUX
; RUN: llvm-as < %s | llc -mtriple=powerpc-apple-darwin | FileCheck %s -check-prefix=DARWIN

define private void @foo() nounwind {
        ret void
; LINUX: .Lfoo:

; DARWIN: L_foo:
}

define i32 @bar() nounwind {
        call void @foo()
	%1 = load i32* @baz, align 4
        ret i32 %1
; LINUX: bar:
; LINUX: bl .Lfoo
; LINUX: lis 3, .Lbaz@ha
; LINUX: lwz 3, .Lbaz@l(3)

; DARWIN: _bar:
; DARWIN: bl L_foo
; DARWIN: lis r2, ha16(L_baz)
; DARWIN: lwz r3, lo16(L_baz)(r2)
}

; LINUX: .Lbaz:
; DARWIN: L_baz:
@baz = private global i32 4

Add -march=ppc32 lines so that this test doesn't ever default to ppc64.

; Test to make sure that the 'private' is used correctly.
;
; RUN: llvm-as < %s | llc -mtriple=powerpc-unknown-linux-gnu -march=ppc32 | FileCheck %s -check-prefix=LINUX
; RUN: llvm-as < %s | llc -mtriple=powerpc-apple-darwin -march=ppc32 | FileCheck %s -check-prefix=DARWIN

define private void @foo() nounwind {
        ret void
; LINUX: .Lfoo:

; DARWIN: L_foo:
}

define i32 @bar() nounwind {
        call void @foo()
	%1 = load i32* @baz, align 4
        ret i32 %1
; LINUX: bar:
; LINUX: bl .Lfoo
; LINUX: lis 3, .Lbaz@ha
; LINUX: lwz 3, .Lbaz@l(3)

; DARWIN: _bar:
; DARWIN: bl L_foo
; DARWIN: lis r2, ha16(L_baz)
; DARWIN: lwz r3, lo16(L_baz)(r2)
}

; LINUX: .Lbaz:
; DARWIN: L_baz:
@baz = private global i32 4


; RUN: llc -mtriple x86_64-linux -mcpu core %s -o - | FileCheck %s
define i32 @f(i1 %foo, i16* %tm_year2, i8* %bar, i16 %zed, i32 %zed2) {
entry:
  br i1 %foo, label %return, label %if.end

if.end:
  %rem = srem i32 %zed2, 100
  %conv3 = trunc i32 %rem to i16
  store i16 %conv3, i16* %tm_year2
  %sext = shl i32 %rem, 16
  %conv5 = ashr exact i32 %sext, 16
  %div = sdiv i32 %conv5, 10
  %conv6 = trunc i32 %div to i8
  store i8 %conv6, i8* %bar
  br label %return

return:
  %retval.0 = phi i32 [ 0, %if.end ], [ -1, %entry ]
  ret i32 %retval.0
}

; We were miscompiling this and using %ax instead of %cx in the movw.
; CHECK: movswl	%cx, %ecx
; CHECK: movw	%cx, (%rsi)
; CHECK: movslq	%ecx, %rcx

Fix the cpu name and add -verify-machineinstrs.

; RUN: llc -mtriple x86_64-linux -mcpu core2 -verify-machineinstrs %s -o - | FileCheck %s
define i32 @f(i1 %foo, i16* %tm_year2, i8* %bar, i16 %zed, i32 %zed2) {
entry:
  br i1 %foo, label %return, label %if.end

if.end:
  %rem = srem i32 %zed2, 100
  %conv3 = trunc i32 %rem to i16
  store i16 %conv3, i16* %tm_year2
  %sext = shl i32 %rem, 16
  %conv5 = ashr exact i32 %sext, 16
  %div = sdiv i32 %conv5, 10
  %conv6 = trunc i32 %div to i8
  store i8 %conv6, i8* %bar
  br label %return

return:
  %retval.0 = phi i32 [ 0, %if.end ], [ -1, %entry ]
  ret i32 %retval.0
}

; We were miscompiling this and using %ax instead of %cx in the movw.
; CHECK: movswl	%cx, %ecx
; CHECK: movw	%cx, (%rsi)
; CHECK: movslq	%ecx, %rcx


; RUN: if as < %s | opt -raise | dis | grep '= cast' | grep \*
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

%FILE = type { int, ubyte*, ubyte*, ubyte, ubyte, uint, uint, uint }

uint %addfile(%FILE* %f) {
	%cast255 = cast %FILE* %f to sbyte*		; <sbyte*> [#uses=1]
	%reg2421 = getelementptr sbyte* %cast255, long 24		; <sbyte*> [#uses=1]
	%reg130 = load sbyte* %reg2421		; <sbyte> [#uses=1]
	%cast250 = cast sbyte %reg130 to uint		; <uint> [#uses=1]
	ret uint %cast250
}

Add information about why this testcase fails

; RUN: if as < %s | opt -raise | dis | grep '= cast' | grep \*
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

%FILE = type { int, ubyte*, ubyte*, ubyte, ubyte, uint, uint, uint }

uint %addfile(%FILE* %f) {
	%cast255 = cast %FILE* %f to sbyte*

	; Addreses a ubyte member in memory...
	%reg2421 = getelementptr sbyte* %cast255, long 24

	; Loads the ubyte
	%reg130 = load sbyte* %reg2421

	; Error, cast cannot convert the source operand to ubyte because then
	; the sign extension would not be performed.  Need to insert a cast.
	;
	%cast250 = cast sbyte %reg130 to uint  ; This is a sign extension instruction
	ret uint %cast250
}


define void @foo() {
  ret void
}

Add layout/triple to fix test on platforms where names are mangled.

target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc"

define void @foo() {
  ret void
}


; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
; RUN: ld.lld %t.o -o %t.so -shared
; RUN: llvm-readelf -s %t.so | FileCheck %s

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

@foo = hidden global i32 42, section "foo_section"
@bar = hidden global i32 42, section "bar_section"
@zed = hidden global i32 42, section "zed_section"

@__start_foo_section = external global i32
@__stop_bar_section = external global i32

define i32* @use1() {
  ret i32* @__start_foo_section
}

define i32* @use2() {
  ret i32* @__stop_bar_section
}

; CHECK-NOT: zed_section
; CHECK:     foo_section PROGBITS
; CHECK-NEXT:     bar_section PROGBITS
; CHECK-NOT: zed_section

Add --gc-sections to a test.

; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
; RUN: ld.lld %t.o -o %t.so -shared
; RUN: llvm-readelf -s %t.so | FileCheck %s
; RUN: ld.lld %t.o -o %t.so -shared --gc-sections
; RUN: llvm-readelf -s %t.so | FileCheck --check-prefix=GC %s

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

@foo = hidden global i32 42, section "foo_section"
@bar = hidden global i32 42, section "bar_section"
@zed = hidden global i32 42, section "zed_section"

@__start_foo_section = external global i32
@__stop_bar_section = external global i32

define hidden i32* @use1() {
  ret i32* @__start_foo_section
}

define i32* @use2() {
  ret i32* @__stop_bar_section
}

; CHECK-NOT: zed_section
; CHECK:     foo_section PROGBITS
; CHECK-NEXT:     bar_section PROGBITS
; CHECK-NOT: zed_section

; GC-NOT: zed_section
; GC-NOT: foo_section
; GC:     bar_section PROGBITS
; GC-NOT: zed_section
; GC-NOT: foo_section


; Tests to make sure elimination of casts is working correctly

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

implementation

int "test1"(int %A)
begin
	%c1 = cast int %A to uint
	%c2 = cast uint %c1 to int
	ret int %c2
end

ulong "test2"(ubyte %A)
begin
	%c1 = cast ubyte %A to ushort
	%c2 = cast ushort %c1 to uint
	%Ret = cast uint %c2 to ulong
	ret ulong %Ret
end

Add another testcase that isn't failing because of another bug in instcombine

; Tests to make sure elimination of casts is working correctly

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

implementation

int %test1(int %A) {
	%c1 = cast int %A to uint
	%c2 = cast uint %c1 to int
	ret int %c2
}

ulong %test2(ubyte %A) {
	%c1 = cast ubyte %A to ushort
	%c2 = cast ushort %c1 to uint
	%Ret = cast uint %c2 to ulong
	ret ulong %Ret
}

ulong %test3(ulong %A) {    ; This function should just use bitwise AND
	%c1 = cast ulong %A to ubyte
	%c2 = cast ubyte %c1 to ulong
	ret ulong %c2
}


%struct.str = type { i64, i8* }

declare i64 @"\01_write"(i32, i8*, i64)

define void @print(%struct.str* %str) {
	%1 = getelementptr inbounds %struct.str* %str, i64 0, i32 1
	%2 = load i8** %1
	%3 = getelementptr inbounds %struct.str* %str, i64 0, i32 0
	%4 = load i64* %3
	tail call i64 @"\01_write"(i32 1, i8* %2, i64 %4)
	ret void
}

Print newlines after printed content by default.

%struct.str = type { i64, i8* }
@str_NL = constant [1 x i8] c"\0a"
declare i64 @"\01_write"(i32, i8*, i64)

define void @print(%struct.str* %str) {
	%1 = getelementptr inbounds %struct.str* %str, i64 0, i32 1
	%2 = load i8** %1
	%3 = getelementptr inbounds %struct.str* %str, i64 0, i32 0
	%4 = load i64* %3
	call i64 @"\01_write"(i32 1, i8* %2, i64 %4)
	%6 = getelementptr inbounds [1 x i8]* @str_NL, i64 0, i64 0
	call i64 @"\01_write"(i32 1, i8* %6, i64 1)
	ret void
}


; RUN: opt < %s -basicaa -sink -S | FileCheck %s

@A = external global i32
@B = external global i32

; Sink should sink the load past the store (which doesn't overlap) into
; the block that uses it.

;      CHECK: @foo
;      CHECK: true:
; CHECK-NEXT: %l = load i32* @A
; CHECK-NEXT: ret i32 %l

define i32 @foo(i1 %z) {
  %l = load i32* @A
  store i32 0, i32* @B
  br i1 %z, label %true, label %false
true:
  ret i32 %l
false:
  ret i32 0
}

; But don't sink volatile loads...

;      CHECK: @foo2
;      CHECK: volatile load
; CHECK-NEXT: store i32

define i32 @foo2(i1 %z) {
  %l = volatile load i32* @A
  store i32 0, i32* @B
  br i1 %z, label %true, label %false
true:
  ret i32 %l
false:
  ret i32 0
}

Fix test; sorry for any inconvenience.

; RUN: opt < %s -basicaa -sink -S | FileCheck %s

@A = external global i32
@B = external global i32

; Sink should sink the load past the store (which doesn't overlap) into
; the block that uses it.

;      CHECK: @foo
;      CHECK: true:
; CHECK-NEXT: %l = load i32* @A
; CHECK-NEXT: ret i32 %l

define i32 @foo(i1 %z) {
  %l = load i32* @A
  store i32 0, i32* @B
  br i1 %z, label %true, label %false
true:
  ret i32 %l
false:
  ret i32 0
}

; But don't sink volatile loads...

;      CHECK: @foo2
;      CHECK: load volatile
; CHECK-NEXT: store i32

define i32 @foo2(i1 %z) {
  %l = load volatile i32* @A
  store i32 0, i32* @B
  br i1 %z, label %true, label %false
true:
  ret i32 %l
false:
  ret i32 0
}


; RUN: llvm-upgrade < %s | llvm-as | llc -march=arm -mattr=+v6

uint %test1(uint %tmp54) {
  %tmp56 = tail call uint asm "uxtb16 $0,$1", "=r,r"( uint %tmp54 )
  ret uint %tmp56
}

void %test2() {
  %tmp1 = call long asm "ldmia $1!, {$0, ${0:H}}", "=r,==r,1"( int** null, int* null )
  %tmp1 = cast long %tmp1 to ulong
  %tmp2 = shr ulong %tmp1, ubyte 32
  %tmp3 = cast ulong %tmp2 to int
  %tmp4 = call int asm "pkhbt $0, $1, $2, lsl #16", "=r,r,r"( int 0, int %tmp3 )
  ret void
}

Test inline asm modifier 'c'.

; RUN: llvm-as < %s | llc -march=arm -mattr=+v6

define i32 @test1(i32 %tmp54) {
	%tmp56 = tail call i32 asm "uxtb16 $0,$1", "=r,r"( i32 %tmp54 )		; <i32> [#uses=1]
	ret i32 %tmp56
}

define void @test2() {
	%tmp1 = call i64 asm "ldmia $1!, {$0, ${0:H}}", "=r,==r,1"( i32** null, i32* null )		; <i64> [#uses=2]
	%tmp2 = lshr i64 %tmp1, 32		; <i64> [#uses=1]
	%tmp3 = trunc i64 %tmp2 to i32		; <i32> [#uses=1]
	%tmp4 = call i32 asm "pkhbt $0, $1, $2, lsl #16", "=r,r,r"( i32 0, i32 %tmp3 )		; <i32> [#uses=0]
	ret void
}

define void @test3() {
	tail call void asm sideeffect "/* number: ${0:c} */", "i"( i32 1 )
	ret void
}


; It's a bad idea to go recursively trapesing through types without a safety
; net.

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

%S = type { %S*, opaque* }

Fix spelling error in comment.

; It's a bad idea to go recursively traipsing through types without a safety
; net.

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

%S = type { %S*, opaque* }


; RUN: llvm-as < %s | llc -march=x86-64 -enable-unsafe-fp-math | not grep mulps
; RUN: llvm-as < %s | llc -march=x86-64 | grep mulps

define void @test14(<4 x float>*) nounwind {
        load <4 x float>* %0, align 1
        mul <4 x float> %2, zeroinitializer
        store <4 x float> %3, <4 x float>* %0, align 1
        ret void
}

Update this test to use fmul instead of mul.

; RUN: llvm-as < %s | llc -march=x86-64 -enable-unsafe-fp-math | not grep mulps
; RUN: llvm-as < %s | llc -march=x86-64 | grep mulps

define void @test14(<4 x float>*) nounwind {
        load <4 x float>* %0, align 1
        fmul <4 x float> %2, zeroinitializer
        store <4 x float> %3, <4 x float>* %0, align 1
        ret void
}


; RUN: llc < %s -march=thumb -mattr=+thumb2 | \
; RUN:   grep {ldr.*\\\[.*\],} | count 1

define i32 @test(i32 %a, i32 %b, i32 %c) {
        %tmp1 = mul i32 %a, %b          ; <i32> [#uses=2]
        %tmp2 = inttoptr i32 %tmp1 to i32*              ; <i32*> [#uses=1]
        %tmp3 = load i32* %tmp2         ; <i32> [#uses=1]
        %tmp4 = sub i32 %tmp1, 8               ; <i32> [#uses=1]
        %tmp5 = mul i32 %tmp4, %tmp3            ; <i32> [#uses=1]
        ret i32 %tmp5
}

Fix the TCL-style quoting in one random test that somehow slipped through my perl nets.

; RUN: llc < %s -march=thumb -mattr=+thumb2 | \
; RUN:   grep "ldr.*\[.*\]," | count 1

define i32 @test(i32 %a, i32 %b, i32 %c) {
        %tmp1 = mul i32 %a, %b          ; <i32> [#uses=2]
        %tmp2 = inttoptr i32 %tmp1 to i32*              ; <i32*> [#uses=1]
        %tmp3 = load i32* %tmp2         ; <i32> [#uses=1]
        %tmp4 = sub i32 %tmp1, 8               ; <i32> [#uses=1]
        %tmp5 = mul i32 %tmp4, %tmp3            ; <i32> [#uses=1]
        ret i32 %tmp5
}


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

; REQUIRES: X86
; RUN: llc %s -o %t.s
; RUN: llvm-mc %t.s -o %t.o -filetype=obj
; RUN: llvm-as %p/Inputs/drop-linkage.ll -o %t2.o
; RUN: ld.lld %t.o %t2.o -o %t.so -save-temps -shared
; RUN: llvm-dis %t.so.lto.opt.bc -o - | FileCheck %s

define void @foo() {
  ret void
}

; CHECK: declare void @foo()

Fix test to run everywhere.

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

; REQUIRES: x86
; RUN: llc %s -o %t.o -filetype=obj
; RUN: llvm-as %p/Inputs/drop-linkage.ll -o %t2.o
; RUN: ld.lld %t.o %t2.o -o %t.so -save-temps -shared
; RUN: llvm-dis %t.so.lto.opt.bc -o - | FileCheck %s

define void @foo() {
  ret void
}

; CHECK: declare void @foo()


; Tests to make sure elimination of casts is working correctly

; RUN: if as < %s | opt -instcombine | grep '%c' | grep cast
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

implementation

int %test1(int %A) {
	%c1 = cast int %A to uint
	%c2 = cast uint %c1 to int
	ret int %c2
}

ulong %test2(ubyte %A) {
	%c1 = cast ubyte %A to ushort
	%c2 = cast ushort %c1 to uint
	%Ret = cast uint %c2 to ulong
	ret ulong %Ret
}

ulong %test3(ulong %A) {    ; This function should just use bitwise AND
	%c1 = cast ulong %A to ubyte
	%c2 = cast ubyte %c1 to ulong
	ret ulong %c2
}

Fix testcase to actually test what we think we are

; Tests to make sure elimination of casts is working correctly

; RUN: if as < %s | opt -instcombine -die | dis | grep '%c' | grep cast
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

implementation

int %test1(int %A) {
	%c1 = cast int %A to uint
	%c2 = cast uint %c1 to int
	ret int %c2
}

ulong %test2(ubyte %A) {
	%c1 = cast ubyte %A to ushort
	%c2 = cast ushort %c1 to uint
	%Ret = cast uint %c2 to ulong
	ret ulong %Ret
}

ulong %test3(ulong %A) {    ; This function should just use bitwise AND
	%c1 = cast ulong %A to ubyte
	%c2 = cast ubyte %c1 to ulong
	ret ulong %c2
}


; For PR1099
; RUN: llvm-as < %s | llc -march=c | \
; RUN:   grep {return ((((llvm_cbe_tmp2 == llvm_cbe_b_0_0_val)) ? (1) : (0)))}

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

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
}

Update this test to match the (corrected) output from the CBE.

; For PR1099
; RUN: llvm-as < %s | llc -march=c | \
; RUN:   grep {return ((((((unsigned short )llvm_cbe_tmp2&65535U) == ((unsigned
short )llvm_cbe_b_0_0_val&65535U))) ? (1) : (0)))}

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

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
}


implementation

; Bytecode gets a constant pool block, that constains:
; type   plane: int(int)

int "main"(int %argc)   ; TODO: , sbyte **argv, sbyte **envp)
begin
        %retval = call int (int) *%test(int %argc)
        %two    = add int %retval, %retval
        ret int %two
end

int "test"(int %i0)
begin
    ret int %i0
end

Add more function call and prototype specific tests

%FunTy = type int(int)

declare int "test"(...)   ; Test differences of prototype
declare int "test"()      ; Differ only by vararg

implementation

void "invoke"(%FunTy *%x)
begin
	%foo = call %FunTy* %x(int 123)
	ret void
end

int "main"(int %argc)   ; TODO: , sbyte **argv, sbyte **envp)
begin
        %retval = call int (int) *%test(int %argc)
        %two    = add int %retval, %retval
	%retval2 = invoke int %test(int %argc)
		   to label %Next except label %Error
Next:
	%two2 = add int %two, %retval2
	call void %invoke (%FunTy* %test)
        ret int %two2
Error:
	ret int -1
end

int "test"(int %i0)
begin
    ret int %i0
end


; RUN: llc < %s
; PR38038

define i8 @crash(half)  {
entry:
  %1 = bitcast half %0 to i16
  %.lobit = lshr i16 %1, 15
  %2 = trunc i16 %.lobit to i8
  ret i8 %2
}

Add x86_64-unkown triple to llc for x86 test.

; RUN: llc < %s -mtriple=x86_64-unknown-unknown
; PR38038

define i8 @crash(half)  {
entry:
  %1 = bitcast half %0 to i16
  %.lobit = lshr i16 %1, 15
  %2 = trunc i16 %.lobit to i8
  ret i8 %2
}


; RUN: llc < %s -march=x86 -x86-asm-syntax=intel | \
; RUN:   grep "lea	EAX, DWORD PTR \[... + 4\*... - 5\]"
; RUN: llc < %s -march=x86 -x86-asm-syntax=intel | \
; RUN:   not grep add

define i32 @test1(i32 %A, i32 %B) {
        %tmp1 = shl i32 %A, 2           ; <i32> [#uses=1]
        %tmp3 = add i32 %B, -5          ; <i32> [#uses=1]
        %tmp4 = add i32 %tmp3, %tmp1            ; <i32> [#uses=1]
        ret i32 %tmp4
}

Rewrite this test properly with a FileCheck instead of greps

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

define i32 @test1(i32 %A, i32 %B) {
  %tmp1 = shl i32 %A, 2
  %tmp3 = add i32 %B, -5
  %tmp4 = add i32 %tmp3, %tmp1
; The above computation of %tmp4 should match a single lea, without using
; actual add instructions.
; CHECK-NOT: add
; CHECK: lea {{[A-Z]+}}, DWORD PTR [{{[A-Z]+}} + 4*{{[A-Z]+}} - 5]

  ret i32 %tmp4
}


; RUN: llc < %s -fast-isel -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512f  | FileCheck %s

define i1 @test_i1(i1* %b) {
; CHECK-LABEL: test_i1:
; CHECK:       # BB#0: # %entry
; CHECK-NEXT:    testb $1, (%rdi)
entry:
  %0 = load i1, i1* %b, align 1
  br i1 %0, label %in, label %out
in:
  ret i1 0
out:
  ret i1 1
}

Use update_llc_test_checks.py to regenerate a test.

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc < %s -fast-isel -mtriple=x86_64-unknown-linux-gnu -mattr=+avx512f  | FileCheck %s

define i1 @test_i1(i1* %b) {
; CHECK-LABEL: test_i1:
; CHECK:       # BB#0: # %entry
; CHECK-NEXT:    testb $1, (%rdi)
; CHECK-NEXT:    je .LBB0_2
; CHECK-NEXT:  # BB#1: # %in
; CHECK-NEXT:    xorl %eax, %eax
; CHECK-NEXT:    retq
; CHECK-NEXT:  .LBB0_2: # %out
; CHECK-NEXT:    movb $1, %al
; CHECK-NEXT:    retq
entry:
  %0 = load i1, i1* %b, align 1
  br i1 %0, label %in, label %out
in:
  ret i1 0
out:
  ret i1 1
}


; This tests value of ELF st_other field for function symbol table entries.
; For microMIPS value should be equal to STO_MIPS_MICROMIPS.

; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+micromips -print-hack-directives %s -o - | FileCheck %s

define i32 @main() nounwind {
entry:
  ret i32 0
}

; CHECK: .set	micromips
; CHECK: main:

Remove -print-hack-directives from a test where we already do the right thing.

; This tests value of ELF st_other field for function symbol table entries.
; For microMIPS value should be equal to STO_MIPS_MICROMIPS.

; RUN: llc -mtriple mipsel-unknown-linux -mcpu=mips32r2 -mattr=+micromips %s -o - | FileCheck %s

define i32 @main() nounwind {
entry:
  ret i32 0
}

; CHECK: .set	micromips
; CHECK: main:


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

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

define i8 @test(i8* %P) nounwind {
; CHECK: lifetime.start
; CHECK-NOT: load
; CHECK: lifetime.end
entry:
  call void @llvm.lifetime.start(i64 32, i8* %P)
  %0 = load i8* %P
  store i8 1, i8* %P
  call void @llvm.lifetime.end(i64 32, i8* %P)
  %1 = load i8* %P
  ret i8 %1
}

declare {}* @llvm.lifetime.start(i64 %S, i8* nocapture %P) readonly
declare void @llvm.lifetime.end(i64 %S, i8* nocapture %P)

Fix intrinsic signature in this test.

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

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

define i8 @test(i8* %P) nounwind {
; CHECK: lifetime.start
; CHECK-NOT: load
; CHECK: lifetime.end
entry:
  call void @llvm.lifetime.start(i64 32, i8* %P)
  %0 = load i8* %P
  store i8 1, i8* %P
  call void @llvm.lifetime.end(i64 32, i8* %P)
  %1 = load i8* %P
  ret i8 %1
}

declare void @llvm.lifetime.start(i64 %S, i8* nocapture %P) readonly
declare void @llvm.lifetime.end(i64 %S, i8* nocapture %P)


; RUN: llvm-as < %s | llc -march=thumb -mattr=+thumb2 -mtriple=armv6-apple-darwin10 | FileCheck %s

@t = weak global i32 ()* null           ; <i32 ()**> [#uses=1]

declare void @g(i32, i32, i32, i32)

define void @f() {
; CHECK: f:
; CHECK: blx
        call void @g( i32 1, i32 2, i32 3, i32 4 )
        ret void
}

define void @h() {
; CHECK: h:
; CHECK: blx r0
        %tmp = load i32 ()** @t         ; <i32 ()*> [#uses=1]
        %tmp.upgrd.2 = tail call i32 %tmp( )            ; <i32> [#uses=0]
        ret void
}

Test both darwin and linux.

; RUN: llvm-as < %s | llc -mtriple=thumbv7-apple-darwin -mattr=+thumb2 | FileCheck %s -check-prefix=DARWIN
; RUN: llvm-as < %s | llc -mtriple=thumbv7-linux -mattr=+thumb2 | FileCheck %s -check-prefix=LINUX

@t = weak global i32 ()* null           ; <i32 ()**> [#uses=1]

declare void @g(i32, i32, i32, i32)

define void @f() {
; DARWIN: f:
; DARWIN: blx L_g$stub

; LINUX: f:
; LINUX: bl g
        call void @g( i32 1, i32 2, i32 3, i32 4 )
        ret void
}

define void @h() {
; DARWIN: h:
; DARWIN: blx r0

; LINUX: h:
; LINUX: blx r0
        %tmp = load i32 ()** @t         ; <i32 ()*> [#uses=1]
        %tmp.upgrd.2 = tail call i32 %tmp( )            ; <i32> [#uses=0]
        ret void
}


; RUN: llc -march=x86 < %s | FileCheck %s
; Verify that llvm.ident metadata is emitted as .ident
; directives in assembly files, and in the .comment section in ELF object files.

; CHECK: .ident  "clang version x.x"
; CHECK-NEXT: .ident  "something else"
!llvm.ident = !{!0, !1}
!0 = metadata !{metadata !"clang version x.x"}
!1 = metadata !{metadata !"something else"}

Add a triple to this test.

; RUN: llc -mtriple=x86_64-linux < %s | FileCheck %s
; Verify that llvm.ident metadata is emitted as .ident
; directives in assembly files, and in the .comment section in ELF object files.

; CHECK: .ident  "clang version x.x"
; CHECK-NEXT: .ident  "something else"
!llvm.ident = !{!0, !1}
!0 = metadata !{metadata !"clang version x.x"}
!1 = metadata !{metadata !"something else"}


; RUN: llvm-as < %s | opt -lcssa | llvm-dis | grep "%lcssa = phi int"

void %lcssa(bool %S2) {
entry:
	br label %loop.interior

loop.interior:		; preds = %entry
	br bool %S2, label %if.true, label %if.false

if.true:
	%X1 = add int 0, 0
	br label %post.if

if.false:
	%X2 = add int 0, 1
	br label %post.if

post.if:
	%X3 = phi int [%X1, %if.true], [%X2, %if.false]
	br bool %S2, label %loop.exit, label %loop.interior

loop.exit:
	%X4 = add int 3, %X3
	ret void
}

Update the testcase to check the full extent of LCSSA.

; RUN: llvm-as < %s | opt -lcssa | llvm-dis | grep "%lcssa = phi int"
; RUN: llvm-as < %s | opt -lcssa | llvm-dis | grep "%X4 = add int 3, %lcssa"

void %lcssa(bool %S2) {
entry:
	br label %loop.interior

loop.interior:		; preds = %entry
	br bool %S2, label %if.true, label %if.false

if.true:
	%X1 = add int 0, 0
	br label %post.if

if.false:
	%X2 = add int 0, 1
	br label %post.if

post.if:
	%X3 = phi int [%X1, %if.true], [%X2, %if.false]
	br bool %S2, label %loop.exit, label %loop.interior

loop.exit:
	%X4 = add int 3, %X3
	ret void
}


; RUN: llc -march=amdgcn -mcpu=gfx900 -amdgpu-atomic-optimizations=true < %s | FileCheck %s
; RUN: llc -march=amdgcn -mcpu=gfx900 -amdgpu-atomic-optimizations=true < %s -use-gpu-divergence-analysis | FileCheck %s

@local = addrspace(3) global i32 undef

define void @reducible(i32 %x) {
; CHECK-LABEL: reducible:
; CHECK-NOT: dpp
entry:
  br label %loop
loop:
  %i = phi i32 [ 0, %entry ], [ %i1, %loop ]
  %gep = getelementptr i32, i32 addrspace(3)* @local, i32 %i
  %cond = icmp ult i32 %i, %x
  %i1 = add i32 %i, 1
  br i1 %cond, label %loop, label %exit
exit:
  %old = atomicrmw add i32 addrspace(3)* %gep, i32 %x acq_rel
  ret void
}

Add amdgpu_kernel for consistency with other tests

; RUN: llc -march=amdgcn -mcpu=gfx900 -amdgpu-atomic-optimizations=true < %s | FileCheck %s
; RUN: llc -march=amdgcn -mcpu=gfx900 -amdgpu-atomic-optimizations=true < %s -use-gpu-divergence-analysis | FileCheck %s

@local = addrspace(3) global i32 undef

define amdgpu_kernel void @reducible(i32 %x) {
; CHECK-LABEL: reducible:
; CHECK-NOT: dpp
entry:
  br label %loop
loop:
  %i = phi i32 [ 0, %entry ], [ %i1, %loop ]
  %gep = getelementptr i32, i32 addrspace(3)* @local, i32 %i
  %cond = icmp ult i32 %i, %x
  %i1 = add i32 %i, 1
  br i1 %cond, label %loop, label %exit
exit:
  %old = atomicrmw add i32 addrspace(3)* %gep, i32 %x acq_rel
  ret void
}