implementation
declare int "printf"(sbyte*, int, float)

int "testissue"(int %i, float %x, float %y)
begin
bb1:
	%x1 = mul float %x, %y			;; x1
	%y1 = mul float %y, 0.75		;; y1
	%z1 = add float %x1, %y1		;; z1 = x1 + y1

	%x2 = mul float %x, 0.5			;; x2
	%y2 = mul float %y, 0.9			;; y2
	%z2 = add float %x2, %y2		;; z2 = x2 + y2

	%z3 = add float %z1, %z2		;; z3 = z1 + z2

	%i1 = shl int   %i, ubyte 3		;; i1
	%j1 = add int   %i, 7			;; j1
	%m1 = add int   %i1, %j1		;; k1 = i1 + j1
;;	%m1 = div int   %k1, 99			;; m1 = k1 / 99

	%b  = setle int %m1, 6			;; (m1 <= 6)?
	br bool %b, label %bb1, label %bb2

bb2:
	%Msg = cast ulong 0 to sbyte *
	call int %printf(sbyte* %Msg, int %m1, float %z3)
	ret int 0
end

Update testcase to be legal llvm

implementation
declare int "printf"(sbyte*, int, float)

int %testissue(int %i, float %x, float %y) {
	br label %bb1
bb1:
	%x1 = mul float %x, %y			;; x1
	%y1 = mul float %y, 0.75		;; y1
	%z1 = add float %x1, %y1		;; z1 = x1 + y1

	%x2 = mul float %x, 0.5			;; x2
	%y2 = mul float %y, 0.9			;; y2
	%z2 = add float %x2, %y2		;; z2 = x2 + y2

	%z3 = add float %z1, %z2		;; z3 = z1 + z2

	%i1 = shl int   %i, ubyte 3		;; i1
	%j1 = add int   %i, 7			;; j1
	%m1 = add int   %i1, %j1		;; k1 = i1 + j1
;;	%m1 = div int   %k1, 99			;; m1 = k1 / 99

	%b  = setle int %m1, 6			;; (m1 <= 6)?
	br bool %b, label %bb1, label %bb2

bb2:
	call int %printf(sbyte* null, int %m1, float %z3)
	ret int 0
end


; RUN: if as < %s | opt -funcresolve -disable-output 2>&1 | grep WARNING
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi
%__popcount_tab = external constant [0 x ubyte]
%__popcount_tab = constant [4 x ubyte] c"\00\01\01\02"

void %test() {
	getelementptr [0 x ubyte]* %__popcount_tab, long 0, long 2
	getelementptr [4 x ubyte]* %__popcount_tab, long 0, long 2
	ret void
}

Add testcase for constantexpr gep

; RUN: if as < %s | opt -funcresolve -disable-output 2>&1 | grep WARNING
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi
%__popcount_tab = external constant [0 x ubyte]
%__popcount_tab = constant [4 x ubyte] c"\00\01\01\02"

declare void %foo(ubyte *)

void %test() {
	getelementptr [0 x ubyte]* %__popcount_tab, long 0, long 2
	getelementptr [4 x ubyte]* %__popcount_tab, long 0, long 2
	call void %foo(ubyte * getelementptr ([0 x ubyte]* %__popcount_tab, long 0, long 2))
	ret void
}


%X = global int 7
%msg = internal global [13 x sbyte] c"Hello World\0A\00"

implementation

declare void %printf([13 x sbyte]*)

void %bar() {
  call void %printf([13 x sbyte]* %msg)
  ret void
}

void %main() {
        call void %bar()
        ret void
}

Return 0 to make it into a fully-functioning "Hello, World!" test case.

%X = global int 7
%msg = internal global [13 x sbyte] c"Hello World\0A\00"

implementation

declare void %printf([13 x sbyte]*)

void %bar() {
  call void %printf([13 x sbyte]* %msg)
  ret void
}

int %main() {
        call void %bar()
        ret int 0
}


; REQUIRES: x86
; RUN: llvm-as %p/Inputs/linkonce-odr.ll -o %t1.o
; RUN: llc %s -o %t2.o -filetype=obj
; RUN: ld.lld %t1.o %t2.o -o %t.so -shared
; RUN: llvm-readobj -t %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"
declare void @f()

define void @g() {
  call void @f()
  ret void
}

; Be sure that the linkonce_odr symbol 'f' is kept.
; CHECK: Symbol {
; CHECK:   Name: f
; CHECK:   Value: 0x1010
; CHECK:   Size: 1
; CHECK:   Binding: Weak
; CHECK:   Type: Function
; CHECK:   Other: 0
; CHECK:   Section: .text
; CHECK: }

Check optimized bitcode instead of produced shared library.

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

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
declare void @f()

define void @g() {
  call void @f()
  ret void
}

; Be sure that 'f' is kept and has weak_odr visibility.
; CHECK: define weak_odr void @f()


; RUN: llc < %s | FileCheck %s

;CHECK-LABEL: test
define <2 x i256> @test() {
  %S = shufflevector <2 x i256> zeroinitializer, <2 x i256> <i256 -1, i256 -1>, <2 x i32> <i32 0, i32 2>
  %B = shl <2 x i256> %S, <i256 -1, i256 -1> ; DAG Combiner crashes here
  ret <2 x i256> %B
}

Set missing x86 arch in a CodeGen regression test.

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

;CHECK-LABEL: test
define <2 x i256> @test() {
  %S = shufflevector <2 x i256> zeroinitializer, <2 x i256> <i256 -1, i256 -1>, <2 x i32> <i32 0, i32 2>
  %B = shl <2 x i256> %S, <i256 -1, i256 -1> ; DAG Combiner crashes here
  ret <2 x i256> %B
}


; RUN: llvm-as < %s | opt -abcd -disable-output

define void @test(i32 %x) {
entry:
  br label %label1
label1:
  %A = phi i32 [ 0, %entry ], [ %A.1, %label2 ]
  %B = icmp slt i32 %A, %x
  br i1 %B, label %label2, label %label2
label2:
  %A.1 = add i32 %A, 1
  br label %label1
label3:  ; No predecessors!
  ret void
}

Test the pass the test is actually for, instead of one that doesn't exist.

; RUN: llvm-as < %s | opt -ssi-everything -disable-output

define void @test(i32 %x) {
entry:
  br label %label1
label1:
  %A = phi i32 [ 0, %entry ], [ %A.1, %label2 ]
  %B = icmp slt i32 %A, %x
  br i1 %B, label %label2, label %label2
label2:
  %A.1 = add i32 %A, 1
  br label %label1
label3:  ; No predecessors!
  ret void
}


; 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
}

Update comments to be actually accurate

; Testcase for calls to the standard C "pow" function
;
; Equivalent to: http://gcc.gnu.org/ml/gcc-patches/2003-02/msg01786.html
; RUN: llvm-as < %s | opt -simplify-libcalls -disable-output &&
; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | not grep 'call double .pow'

declare double %pow(double, double)

double %test1(double %X) {
	%Y = call double %pow(double %X, double 0.0)
	ret double %Y    ; x^0.0 always equals 1.0
}

double %test2(double %X) {
	%Y = call double %pow(double %X, double -0.0)
	ret double %Y    ; x^-0.0 always equals 1.0
}

double %test3(double %X) {
	%Y = call double %pow(double 1.0, double %X)
	ret double %Y    ; 1.0^x always equals 1.0
}


; RUN: as < %s | opt -cee
;
; The 'cee' pass is breaking SSA form when it blindly forwards the branch from
; Eq to branch to "Forwarded" instead.

implementation

int %test(int %A, int %B, bool %c0) {
Start:
	%c1 = seteq int %A, %B
	br bool %c1, label %Eq, label %Loop

Eq:	; In this block we know that A == B
	br label %Loop    ; This should be modified to branch to "Forwarded".

Loop:        ;; Merge point, nothing is known here...
	%Z = phi int [%A, %Start], [%B, %Eq], [%Z, %Bottom]
	%c2 = setgt int %A, %B
	br bool %c2, label %Forwarded, label %Bottom

Forwarded:
	call int %test(int 0, int %Z, bool true)
	br label %Bottom

Bottom:
	br label %Loop
}

Make test more interesting by adding dummy phi node

; RUN: as < %s | opt -cee
;
; The 'cee' pass is breaking SSA form when it blindly forwards the branch from
; Eq to branch to "Forwarded" instead.

implementation

int %test(int %A, int %B, bool %c0) {
Start:
	%c1 = seteq int %A, %B
	br bool %c1, label %Eq, label %Loop

Eq:	; In this block we know that A == B
	br label %Loop    ; This should be modified to branch to "Forwarded".

Loop:        ;; Merge point, nothing is known here...
	%Z = phi int [%A, %Start], [%B, %Eq], [%Z, %Bottom]
	%c2 = setgt int %A, %B
	br bool %c2, label %Forwarded, label %Bottom

Forwarded:
	%Z2 = phi int [%Z, %Loop]
	call int %test(int 0, int %Z2, bool true)
	br label %Bottom

Bottom:
	br label %Loop
}


; XFAIL: *
; RUN: opt < %s -newgvn -S | FileCheck %s

define i32 @main() {
block1:
	%z1 = bitcast i32 0 to i32
	br label %block2
block2:
  %z2 = bitcast i32 0 to i32
  ret i32 %z2
}

; CHECK: define i32 @main() {
; CHECK-NEXT: block1:
; CHECK-NEXT:   ret i32 0
; CHECK-NEXT: }

Change test to reflect difference between GVN and NewGVN.

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

define i32 @main() {
block1:
	%z1 = bitcast i32 0 to i32
	br label %block2
block2:
  %z2 = bitcast i32 0 to i32
  ret i32 %z2
}

; CHECK: define i32 @main() {
; CHECK-NEXT: block1:
; CHECK-NEXT:   br label %block2
; CHECK: block2:
; CHECK-NEXT:   ret i32 0
; CHECK-NEXT: }


; Test that the ExitInMainOptimization pass works correctly
; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | grep -c 'ret int 3' | grep 1

declare void "exit"(int)
declare void "exitonly"(int)

implementation   ; Functions:

int "main"() {
        call void "exitonly" ( int 3 )
        call void "exit" ( int 3 )
        ret int 0
}

Use the %name rather than the "name" format so those familiar with the llvm-dis output don't go blind.

; Test that the ExitInMainOptimization pass works correctly
; RUN: llvm-as < %s | opt -simplify-libcalls | llvm-dis | grep -c 'ret int 3' | grep 1

declare void %exit(int)
declare void %exitonly(int)

implementation   ; Functions:

int %main () {
        call void %exitonly ( int 3 )
        call void %exit ( int 3 )
        ret int 0
}


; REQUIRES: x86

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

; Test to ensure that thinlto-index-only with obj-path creates the file.
; RUN: rm -f %t4.o
; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=obj-path=%t4.o -shared %t1.o %t2.o -o %t3
; RUN: llvm-readobj -h %t4.o | FileCheck %s
; RUN: llvm-nm %t4.o | count 0

; CHECK: Format: ELF64-x86-64

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

declare void @g(...)

define void @f() {
entry:
  call void (...) @g()
  ret void
}

Update lld tests based on changed llvm-nm output

; REQUIRES: x86

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

; Test to ensure that thinlto-index-only with obj-path creates the file.
; RUN: rm -f %t4.o
; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=obj-path=%t4.o -shared %t1.o %t2.o -o %t3
; RUN: llvm-readobj -h %t4.o | FileCheck %s
; RUN: llvm-nm %t4.o | FileCheck %s -check-prefix=NO-SYMBOLS
; NO-SYMBOLS: no symbols

; CHECK: Format: ELF64-x86-64

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

declare void @g(...)

define void @f() {
entry:
  call void (...) @g()
  ret void
}


; REQUIRES: asserts
; RUN: opt -regions -analyze < %s | FileCheck %s

; While working on improvements to the region info analysis, this test
; case caused an incorrect region 3 => 8 to be detected.

define internal i8 @wibble() {
bb:
  br i1 true, label %bb1, label %bb8

bb1:                                              ; preds = %bb
  switch i32 0, label %bb2 [
    i32 0, label %bb3
    i32 1, label %bb7
  ]

bb2:                                              ; preds = %bb1
  br label %bb4

bb3:                                              ; preds = %bb1
  br label %bb5

bb4:                                              ; preds = %bb2
  br label %bb6

bb5:                                              ; preds = %bb3
  br label %bb6

bb6:                                              ; preds = %bb5, %bb4
  br label %bb7

bb7:                                              ; preds = %bb6, %bb1
  br label %bb8

bb8:                                              ; preds = %bb7, %bb
  ret i8 1
}

; CHECK:      [0] bb => <Function Return>
; CHECK-NEXT:   [1] bb => bb8
; CHECK-NEXT:     [2] bb1 => bb7

Add missing CHECK: line to test case added in 29097

; REQUIRES: asserts
; RUN: opt -regions -analyze < %s | FileCheck %s

; While working on improvements to the region info analysis, this test
; case caused an incorrect region 3 => 8 to be detected.

define internal i8 @wibble() {
bb:
  br i1 true, label %bb1, label %bb8

bb1:                                              ; preds = %bb
  switch i32 0, label %bb2 [
    i32 0, label %bb3
    i32 1, label %bb7
  ]

bb2:                                              ; preds = %bb1
  br label %bb4

bb3:                                              ; preds = %bb1
  br label %bb5

bb4:                                              ; preds = %bb2
  br label %bb6

bb5:                                              ; preds = %bb3
  br label %bb6

bb6:                                              ; preds = %bb5, %bb4
  br label %bb7

bb7:                                              ; preds = %bb6, %bb1
  br label %bb8

bb8:                                              ; preds = %bb7, %bb
  ret i8 1
}

; CHECK:      [0] bb => <Function Return>
; CHECK-NEXT:   [1] bb => bb8
; CHECK-NEXT:     [2] bb1 => bb7
; CHECK-NEXT: End region tree


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

cond_true:		; preds = %entry
	br label %return

cond_false:		; preds = %entry
	br label %return

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

Use the correct syntax. Note to self: test before committing things!

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

cond_true:		; preds = %entry
	br label %return

cond_false:		; preds = %entry
	br label %return

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


; RUN: llc -mtriple=arm64-apple-ios7.0 %s -o - | FileCheck %s

@g0 = external global <3 x float>, align 16
@g1 = external global <3 x float>, align 4

; CHECK: ldr s[[R0:[0-9]+]], {{\[}}[[R1:x[0-9]+]]{{\]}}, #4
; CHECK: ld1.s { v[[R0]] }[1], {{\[}}[[R1]]{{\]}}
; CHECK: str d[[R0]]

define void @blam() {
  %tmp4 = getelementptr inbounds <3 x float>, <3 x float>* @g1, i64 0, i64 0
  %tmp5 = load <3 x float>, <3 x float>* @g0, align 16
  %tmp6 = extractelement <3 x float> %tmp5, i64 0
  store float %tmp6, float* %tmp4
  %tmp7 = getelementptr inbounds float, float* %tmp4, i64 1
  %tmp8 = load <3 x float>, <3 x float>* @g0, align 16
  %tmp9 = extractelement <3 x float> %tmp8, i64 1
  store float %tmp9, float* %tmp7
  ret void;
}

Use option -march instead of -mtriple to avoid overconditionalizing the test.

; RUN: llc -march aarch64 %s -o - | FileCheck %s

@g0 = external global <3 x float>, align 16
@g1 = external global <3 x float>, align 4

; CHECK: ldr s[[R0:[0-9]+]], {{\[}}[[R1:x[0-9]+]]{{\]}}, #4
; CHECK: ld1{{\.?s?}} { v[[R0]]{{\.?s?}} }[1], {{\[}}[[R1]]{{\]}}
; CHECK: str d[[R0]]

define void @blam() {
  %tmp4 = getelementptr inbounds <3 x float>, <3 x float>* @g1, i64 0, i64 0
  %tmp5 = load <3 x float>, <3 x float>* @g0, align 16
  %tmp6 = extractelement <3 x float> %tmp5, i64 0
  store float %tmp6, float* %tmp4
  %tmp7 = getelementptr inbounds float, float* %tmp4, i64 1
  %tmp8 = load <3 x float>, <3 x float>* @g0, align 16
  %tmp9 = extractelement <3 x float> %tmp8, i64 1
  store float %tmp9, float* %tmp7
  ret void;
}


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

; RUN: ld -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

@a = weak global i32 42
@b = global i32* @a

; Test that @b and @c end up pointing to the same variable.

; CHECK: @a = weak global i32 42
; CHECK: @b = global i32* @a
; CHECK: @c = global i32* @a

Make the test a bit more strict.

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

; RUN: ld -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

@a = weak global i32 42
@b = global i32* @a

; Test that @b and @c end up pointing to the same variable.

; CHECK: @a = weak global i32 42
; CHECK: @b = global i32* @a{{$}}
; CHECK: @c = global i32* @a{{$}}


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

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-f128:128:128-v128:128:128-n32:64"
target triple = "powerpc64-bgq-linux"

define void @_Z15quad_copy_1024nPcS_m() nounwind {
; CHECK: @_Z15quad_copy_1024nPcS_m

entry:
  br i1 undef, label %short_msg, label %if.end

if.end:                                           ; preds = %entry
  %0 = tail call double* asm sideeffect "qvstfdux $2,$0,$1", "=b,{r7},{f11},0,~{memory}"(i32 64, double undef, double* undef) nounwind, !srcloc !0
  unreachable

; CHECK: qvstfdux 11,{{[0-9]+}},7

short_msg:                                        ; preds = %entry
  ret void
}

!0 = metadata !{i32 -2147422199}

Simplify the testcase a bit.

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

define void @f() {
; CHECK: @f

entry:
  %0 = tail call double* asm sideeffect "qvstfdux $2,$0,$1", "=b,{r7},{f11},0,~{memory}"(i32 64, double undef, double* undef)
  ret void

; CHECK: qvstfdux 11,{{[0-9]+}},7
}


; RUN: opt -mtriple=x86_64-- -O0 -debug-pass=Structure < %s -o /dev/null 2>&1 | FileCheck %s

; REQUIRES: asserts

; CHECK-LABEL: Pass Arguments:
; CHECK-NEXT: Target Transform Information
; CHECK-NEXT:   FunctionPass Manager
; CHECK-NEXT:     Module Verifier
; CHECK-NEXT:     Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
; CHECK-NEXT: Pass Arguments:
; CHECK-NEXT: Target Library Information
; CHECK-NEXT: Target Transform Information
;             Target Pass Configuration
; CHECK:      Assumption Cache Tracker
; CHECK-NEXT: Profile summary info
; CHECK-NEXT:   ModulePass Manager
; CHECK-NEXT:     Force set function attributes
; CHECK-NEXT:     CallGraph Construction
; CHECK-NEXT:     Call Graph SCC Pass Manager
; CHECK-NEXT:       Inliner for always_inline functions
; CHECK-NEXT:       FunctionPass Manager
; CHECK-NEXT:         Module Verifier
; CHECK-NEXT:     Bitcode Writer

define void @f() {
  ret void
}

Allow for optional No-Op Barrier Pass in O0 pipeline

; RUN: opt -mtriple=x86_64-- -O0 -debug-pass=Structure < %s -o /dev/null 2>&1 | FileCheck %s

; REQUIRES: asserts

; CHECK-LABEL: Pass Arguments:
; CHECK-NEXT: Target Transform Information
; CHECK-NEXT:   FunctionPass Manager
; CHECK-NEXT:     Module Verifier
; CHECK-NEXT:     Instrument function entry/exit with calls to e.g. mcount() (pre inlining)
; CHECK-NEXT: Pass Arguments:
; CHECK-NEXT: Target Library Information
; CHECK-NEXT: Target Transform Information
;             Target Pass Configuration
; CHECK:      Assumption Cache Tracker
; CHECK-NEXT: Profile summary info
; CHECK-NEXT:   ModulePass Manager
; CHECK-NEXT:     Force set function attributes
; CHECK-NEXT:     CallGraph Construction
; CHECK-NEXT:     Call Graph SCC Pass Manager
; CHECK-NEXT:       Inliner for always_inline functions
;                   A No-Op Barrier Pass
; CHECK:            FunctionPass Manager
; CHECK-NEXT:         Module Verifier
; CHECK-NEXT:     Bitcode Writer

define void @f() {
  ret void
}


; Simple sanity check testcase.  Both alloca's should be eliminated.
; RUN: opt < %s -debugify -mem2reg -check-debugify -S | FileCheck %s

; CHECK-NOT: alloca
; CHECK: CheckModuleDebugify: PASS

define double @testfunc(i32 %i, double %j) {
	%I = alloca i32		; <i32*> [#uses=4]
	%J = alloca double		; <double*> [#uses=2]
	store i32 %i, i32* %I
	store double %j, double* %J
	%t1 = load i32, i32* %I		; <i32> [#uses=1]
	%t2 = add i32 %t1, 1		; <i32> [#uses=1]
	store i32 %t2, i32* %I
	%t3 = load i32, i32* %I		; <i32> [#uses=1]
	%t4 = sitofp i32 %t3 to double		; <double> [#uses=1]
	%t5 = load double, double* %J		; <double> [#uses=1]
	%t6 = fmul double %t4, %t5		; <double> [#uses=1]
	ret double %t6
}

Fix test failing after r332416

; Simple sanity check testcase.  Both alloca's should be eliminated.
; RUN: opt < %s -debugify -mem2reg -check-debugify -S | FileCheck %s

; CHECK-NOT: alloca
; CHECK: CheckModuleDebugify [{{.*}}]: PASS

define double @testfunc(i32 %i, double %j) {
	%I = alloca i32		; <i32*> [#uses=4]
	%J = alloca double		; <double*> [#uses=2]
	store i32 %i, i32* %I
	store double %j, double* %J
	%t1 = load i32, i32* %I		; <i32> [#uses=1]
	%t2 = add i32 %t1, 1		; <i32> [#uses=1]
	store i32 %t2, i32* %I
	%t3 = load i32, i32* %I		; <i32> [#uses=1]
	%t4 = sitofp i32 %t3 to double		; <double> [#uses=1]
	%t5 = load double, double* %J		; <double> [#uses=1]
	%t6 = fmul double %t4, %t5		; <double> [#uses=1]
	ret double %t6
}


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

; zext R25:R24, R24
; eor R25, R25
define i16 @zext1(i8 %x) {
; CHECK-LABEL: zext1:
; CHECK: clr r25
  %1 = zext i8 %x to i16
  ret i16 %1
}

; zext R25:R24, R20
; mov R24, R20
; clr R25
define i16 @zext2(i8 %x, i8 %y) {
; CHECK-LABEL: zext2:
; CHECK: mov r24, r22
; CHECK: clr r25
  %1 = zext i8 %y to i16
  ret i16 %1
}

; zext R25:R24, R24
; clr R25
define i16 @zext_i1(i1 %x) {
; CHECK-LABEL: zext_i1:
; CHECK: clr r25
  %1 = zext i1 %x to i16
  ret i16 %1
}

Fix the test suite after r326500.

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

; zext R25:R24, R24
; eor R25, R25
define i16 @zext1(i8 %x) {
; CHECK-LABEL: zext1:
; CHECK: clr r25
  %1 = zext i8 %x to i16
  ret i16 %1
}

; zext R25:R24, R20
; mov R24, R20
; clr R25
define i16 @zext2(i8 %x, i8 %y) {
; CHECK-LABEL: zext2:
; CHECK: mov r24, r22
; CHECK: clr r25
  %1 = zext i8 %y to i16
  ret i16 %1
}

; zext R25:R24, R24
; clr R25
define i16 @zext_i1(i1 %x) {
; CHECK-LABEL: zext_i1:
; CHECK: andi r25, 0
  %1 = zext i1 %x to i16
  ret i16 %1
}


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

@temp1 = global i64 -77129852189294865, align 8

define void @foo() nounwind {
  %x = load i64* @temp1, align 8
  %s = shl i64 %x, 32
  %t = trunc i64 %s to i32
  %z = zext i32 %t to i64
  store i64 %z, i64* @temp1, align 8
; CHECK: movl $0, temp1+4
; CHECK: movl $0, temp1
  ret void
}

Fix the lit test added in r174972

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

@temp1 = global i64 -77129852189294865, align 8

define void @foo() nounwind {
  %x = load i64* @temp1, align 8
  %s = shl i64 %x, 32
  %t = trunc i64 %s to i32
  %z = zext i32 %t to i64
  store i64 %z, i64* @temp1, align 8
; CHECK: movl $0, {{_?}}temp1+4
; CHECK: movl $0, {{_?}}temp1
  ret void
}


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

define i16 @test1(i8 %x) {
  %A = sext i8 %x to i32
  %B = trunc i32 %A to i16
  ret i16 %B
}

define i8 @test2(i16 %x) {
  %A = sext i16 %x to i32
  %B = trunc i32 %A to i8
  ret i8 %B
}

define i16 @test3(i16 %x) {
  %A = sext i16 %x to i32
  %B = trunc i32 %A to i16
  ret i16 %B
}

define i16 @test4(i8 %x) {
  %A = zext i8 %x to i32
  %B = trunc i32 %A to i16
  ret i16 %B
}

define i8 @test5(i16 %x) {
  %A = zext i16 %x to i32
  %B = trunc i32 %A to i8
  ret i8 %B
}

define i16 @test6(i16 %x) {
  %A = zext i16 %x to i32
  %B = trunc i32 %A to i16
  ret i16 %B
}

Fix this test to match the new output from scalar-evolution.

; RUN: llvm-as < %s | opt -analyze -scalar-evolution | grep {(trunc i} | not grep ext

define i16 @test1(i8 %x) {
  %A = sext i8 %x to i32
  %B = trunc i32 %A to i16
  ret i16 %B
}

define i8 @test2(i16 %x) {
  %A = sext i16 %x to i32
  %B = trunc i32 %A to i8
  ret i8 %B
}

define i16 @test3(i16 %x) {
  %A = sext i16 %x to i32
  %B = trunc i32 %A to i16
  ret i16 %B
}

define i16 @test4(i8 %x) {
  %A = zext i8 %x to i32
  %B = trunc i32 %A to i16
  ret i16 %B
}

define i8 @test5(i16 %x) {
  %A = zext i16 %x to i32
  %B = trunc i32 %A to i8
  ret i8 %B
}

define i16 @test6(i16 %x) {
  %A = zext i16 %x to i32
  %B = trunc i32 %A to i16
  ret i16 %B
}


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

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

implementation

int "test1"(int %A) {
	%B = shl int %A, ubyte 0
	ret int %B
}

int "test2"(ubyte %A) {
	%B = shl int 0, ubyte %A
	ret int %B
}

int "test3"(int %A) {
	%B = shr int %A, ubyte 0
	ret int %B
}

int "test4"(ubyte %A) {
	%B = shr int 0, ubyte %A
	ret int %B
}

uint "test5"(uint %A) {
	%B = shr uint %A, ubyte 32  ;; shift all bits out
	ret uint %B
}

Check for cannonicalization of shl X, 1 -> add X, X

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

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

implementation

int "test1"(int %A) {
	%B = shl int %A, ubyte 0
	ret int %B
}

int "test2"(ubyte %A) {
	%B = shl int 0, ubyte %A
	ret int %B
}

int "test3"(int %A) {
	%B = shr int %A, ubyte 0
	ret int %B
}

int "test4"(ubyte %A) {
	%B = shr int 0, ubyte %A
	ret int %B
}

uint "test5"(uint %A) {
	%B = shr uint %A, ubyte 32  ;; shift all bits out
	ret uint %B
}

uint %test6(uint %A) {
	%B = shl uint %A, ubyte 1   ;; convert to an add instruction
	ret uint %B
}


; Test linking two functions with different prototypes and two globals
; in different modules.
; RUN: llvm-as %s -o %t.bar.bc -f
; RUN: echo "define i32* @foo(i32 %x) { ret i32* @baz } @baz = external global i32" | \
; RUN:   llvm-as -o %t.foo.bc -f
; RUN: llvm-link %t.bar.bc %t.foo.bc -o %t.bc
; RUN: llvm-link %t.foo.bc %t.bar.bc -o %t.bc
declare i32* @foo(...)
define i32* @bar() {
	%ret = call i32* (...)* @foo( i32 123 )
	ret i32* %ret
}
@baz = global i32 0

Use -f option so test is repeatable.

; Test linking two functions with different prototypes and two globals
; in different modules.
; RUN: llvm-as %s -o %t.bar.bc -f
; RUN: echo "define i32* @foo(i32 %x) { ret i32* @baz } @baz = external global i32" | \
; RUN:   llvm-as -o %t.foo.bc -f
; RUN: llvm-link %t.bar.bc %t.foo.bc -o %t.bc -f
; RUN: llvm-link %t.foo.bc %t.bar.bc -o %t.bc -f
declare i32* @foo(...)
define i32* @bar() {
	%ret = call i32* (...)* @foo( i32 123 )
	ret i32* %ret
}
@baz = global i32 0


; RUN: llvm-link %s %p/unnamed-addr1-b.ll -S -o - | sort | FileCheck %s

; Only in this file
@a = common global i32 0
; CHECK: @a = common global i32 0
@b = common unnamed_addr global i32 0
; CHECK: @b = common unnamed_addr global i32 0

; Other file has unnamed_addr definition
@c = common unnamed_addr global i32 0
; CHECK: @c = common unnamed_addr global i32 0
@d = external global i32
; CHECK: @d = global i32 42
@e = external unnamed_addr global i32
; CHECK: @e = unnamed_addr global i32 42
@f = weak global i32 42
; CHECK: @f = global i32 42

; Other file has non-unnamed_addr definition
@g = common unnamed_addr global i32 0
; CHECK: @g = common global i32 0
@h = external global i32
; CHECK: @h = global i32 42
@i = external unnamed_addr global i32
; CHECK: @i = global i32 42
@j = weak global i32 42
; CHECK: @j = global i32 42

Use CHECK-DAG instead of sort.

; RUN: llvm-link %s %p/unnamed-addr1-b.ll -S -o - | FileCheck %s

; Only in this file
@a = common global i32 0
; CHECK-DAG: @a = common global i32 0
@b = common unnamed_addr global i32 0
; CHECK-DAG: @b = common unnamed_addr global i32 0

; Other file has unnamed_addr definition
@c = common unnamed_addr global i32 0
; CHECK-DAG: @c = common unnamed_addr global i32 0
@d = external global i32
; CHECK-DAG: @d = global i32 42
@e = external unnamed_addr global i32
; CHECK-DAG: @e = unnamed_addr global i32 42
@f = weak global i32 42
; CHECK-DAG: @f = global i32 42

; Other file has non-unnamed_addr definition
@g = common unnamed_addr global i32 0
; CHECK-DAG: @g = common global i32 0
@h = external global i32
; CHECK-DAG: @h = global i32 42
@i = external unnamed_addr global i32
; CHECK-DAG: @i = global i32 42
@j = weak global i32 42
; CHECK-DAG: @j = global i32 42


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

; 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()

Make x86_64-darwin bot happy again.

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()


; RUN: not llc < %s -mcpu=skylake-avx512 2>&1 | FileCheck %s

; make sure we don't crash if scale for gather isn't constant.

; CHECK: LLVM ERROR: Cannot select: intrinsic %llvm.x86.avx512.gather.dpi.512
declare <16 x i32> @llvm.x86.avx512.gather.dpi.512(<16 x i32>, i8*, <16 x i32>, i16, i32)

define internal <16 x i32> @__gather_base_offsets32_i32(i8* readonly %ptr, i32 %offset_scale, <16 x i32> %offsets, <16 x i8> %vecmask) {
  %mask_vec_i1.i.i = icmp ne <16 x i8> %vecmask, zeroinitializer
  %mask_i16.i = bitcast <16 x i1> %mask_vec_i1.i.i to i16
  %res = tail call <16 x i32> @llvm.x86.avx512.gather.dpi.512(<16 x i32> undef, i8* %ptr, <16 x i32> %offsets, i16 %mask_i16.i, i32 %offset_scale)
  ret <16 x i32> %res
}

Add a missing triple, without which the CPU won't parse.

; RUN: not llc < %s -mcpu=skylake-avx512 2>&1 | FileCheck %s

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

; make sure we don't crash if scale for gather isn't constant.

; CHECK: LLVM ERROR: Cannot select: intrinsic %llvm.x86.avx512.gather.dpi.512
declare <16 x i32> @llvm.x86.avx512.gather.dpi.512(<16 x i32>, i8*, <16 x i32>, i16, i32)

define internal <16 x i32> @__gather_base_offsets32_i32(i8* readonly %ptr, i32 %offset_scale, <16 x i32> %offsets, <16 x i8> %vecmask) {
  %mask_vec_i1.i.i = icmp ne <16 x i8> %vecmask, zeroinitializer
  %mask_i16.i = bitcast <16 x i1> %mask_vec_i1.i.i to i16
  %res = tail call <16 x i32> @llvm.x86.avx512.gather.dpi.512(<16 x i32> undef, i8* %ptr, <16 x i32> %offsets, i16 %mask_i16.i, i32 %offset_scale)
  ret <16 x i32> %res
}


; This testcase tests that a worklist is being used, and that globals can be
; removed if they are the subject of a constexpr and ConstantPointerRef

; RUN: if as < %s | opt -globaldce | dis | grep global
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

%t0 = internal global [4 x sbyte] c"foo\00"
%t1 = internal global [4 x sbyte] c"bar\00"

%s1 = internal global [1 x sbyte*] [sbyte* cast ([4 x sbyte]* %t0 to sbyte*)]
%s2 = internal global [1 x sbyte*] [sbyte* getelementptr ([4 x sbyte]* %t1, uint 0, uint 0 )]

Add a simple testcase that just uses a CPR instead of a CPR & ConstExpr

; This testcase tests that a worklist is being used, and that globals can be
; removed if they are the subject of a constexpr and ConstantPointerRef

; RUN: if as < %s | opt -globaldce | dis | grep global
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

%t0 = internal global [4 x sbyte] c"foo\00"
%t1 = internal global [4 x sbyte] c"bar\00"

%s1 = internal global [1 x sbyte*] [sbyte* cast ([4 x sbyte]* %t0 to sbyte*)]
%s2 = internal global [1 x sbyte*] [sbyte* getelementptr ([4 x sbyte]* %t1, uint 0, uint 0 )]

%b = internal global int* %a
%a = internal global int 7


; RUN: llvm-as < %s | llc -march=x86 -o %t -f
; RUN: grep unpcklpd %t | count 1
; RUN: grep movapd %t | count 1

; Shows a dag combine bug that will generate an illegal build vector
; with v2i64 build_vector i32, i32.

define void @test(<2 x double>* %dst, <4 x double> %src) {
entry:
        %tmp7.i = shufflevector <4 x double> %src, <4 x double> undef, <2 x i32> < i32 0, i32 2 >
        store <2 x double> %tmp7.i, <2 x double>* %dst
        ret void
}

Fix test on non-x86 platforms.

; RUN: llvm-as < %s | llc -march=x86 -mattr=sse -o %t -f
; RUN: grep unpcklpd %t | count 1
; RUN: grep movapd %t | count 1

; Shows a dag combine bug that will generate an illegal build vector
; with v2i64 build_vector i32, i32.

define void @test(<2 x double>* %dst, <4 x double> %src) {
entry:
        %tmp7.i = shufflevector <4 x double> %src, <4 x double> undef, <2 x i32> < i32 0, i32 2 >
        store <2 x double> %tmp7.i, <2 x double>* %dst
        ret void
}


declare bool %llvm.isnan(float)
declare bool %llvm.isnan(double)

declare bool %llvm.isunordered(float, float)
declare bool %llvm.isunordered(double, double)

implementation

; Test llvm intrinsics
;
void %libm() {
	call bool %llvm.isnan(float 0.0)
	call bool %llvm.isnan(double 10.0)
        call bool %llvm.isunordered(float 0.0, float 1.0)
        call bool %llvm.isunordered(double 0.0, double 1.0)
	ret void
}

Add a nan, stop testing isnan

declare bool %llvm.isunordered(float, float)
declare bool %llvm.isunordered(double, double)

implementation

; Test llvm intrinsics
;
void %libm() {
        call bool %llvm.isunordered(float 0.0, float 1.0)
        call bool %llvm.isunordered(double 0.0, double double 0x7FF8000000000000)
	ret void
}


; RUN: llc <%s -O2 -mcpu=atom -march=x86 -relocation-model=static | FileCheck -check-prefix=atom %s
; RUN: llc <%s -O2 -mcpu=core2 -march=x86 -relocation-model=static | FileCheck %s

@a = common global i32 0, align 4
@b = common global i32 0, align 4
@c = common global i32 0, align 4
@d = common global i32 0, align 4
@e = common global i32 0, align 4
@f = common global i32 0, align 4

define void @func() nounwind uwtable {
; atom: imull
; atom-NOT: movl
; atom: imull
; CHECK: imull
; CHECK: movl
; CHECK: imull
entry:
  %0 = load i32* @b, align 4
  %1 = load i32* @c, align 4
  %mul = mul nsw i32 %0, %1
  store i32 %mul, i32* @a, align 4
  %2 = load i32* @e, align 4
  %3 = load i32* @f, align 4
  %mul1 = mul nsw i32 %2, %3
  store i32 %mul1, i32* @d, align 4
  ret void
}

Disable the atom scheduling test after r154874 broke it.

; RUN: llc <%s -O2 -mcpu=atom -march=x86 -relocation-model=static | FileCheck -check-prefix=atom %s
; RUN: llc <%s -O2 -mcpu=core2 -march=x86 -relocation-model=static | FileCheck %s
;
; FIXME: Atom's scheduler is temporarily disabled.
; XFAIL: *

@a = common global i32 0, align 4
@b = common global i32 0, align 4
@c = common global i32 0, align 4
@d = common global i32 0, align 4
@e = common global i32 0, align 4
@f = common global i32 0, align 4

define void @func() nounwind uwtable {
; atom: imull
; atom-NOT: movl
; atom: imull
; CHECK: imull
; CHECK: movl
; CHECK: imull
entry:
  %0 = load i32* @b, align 4
  %1 = load i32* @c, align 4
  %mul = mul nsw i32 %0, %1
  store i32 %mul, i32* @a, align 4
  %2 = load i32* @e, align 4
  %3 = load i32* @f, align 4
  %mul1 = mul nsw i32 %2, %3
  store i32 %mul1, i32* @d, align 4
  ret void
}


; RUN: llc -mtriple=aarch64_be-- %s -o /dev/null -debug-only=isel -O0 2>&1 | FileCheck %s

; This test uses big endian in order to force an abort since it's not currently supported for GISel.
; The purpose is to check that we don't fall back to FastISel. Checking the pass structure is insufficient
; because the FastISel is set up in the SelectionDAGISel, so it doesn't appear on the pass structure.

; CHECK-NOT: Enabling fast-ise
define void @empty() {
  ret void
}

Add a requires: asserts to a test.

; RUN: llc -mtriple=aarch64_be-- %s -o /dev/null -debug-only=isel -O0 2>&1 | FileCheck %s
; REQUIRES: asserts

; This test uses big endian in order to force an abort since it's not currently supported for GISel.
; The purpose is to check that we don't fall back to FastISel. Checking the pass structure is insufficient
; because the FastISel is set up in the SelectionDAGISel, so it doesn't appear on the pass structure.

; CHECK-NOT: Enabling fast-ise
define void @empty() {
  ret void
}


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

; Check that functions with "returns_twice" calls are only inlined,
; if they are themselve marked as such.

declare i32 @a() returns_twice
declare i32 @b() returns_twice

define i32 @f() {
entry:
  %call = call i32 @a() returns_twice
  %add = add nsw i32 1, %call
  ret i32 %add
}

define i32 @g() {
entry:
; CHECK-LABEL: define i32 @g(
; CHECK: call i32 @f()
; CHECK-NOT: call i32 @a()
  %call = call i32 @f()
  %add = add nsw i32 1, %call
  ret i32 %add
}

define i32 @h() returns_twice {
entry:
  %call = call i32 @b() returns_twice
  %add = add nsw i32 1, %call
  ret i32 %add
}

define i32 @i() {
entry:
; CHECK-LABEL: define i32 @i(
; CHECK: call i32 @b()
; CHECK-NOT: call i32 @h()
  %call = call i32 @h() returns_twice
  %add = add nsw i32 1, %call
  ret i32 %add
}

Fix spelling in comment in test: "themselve" -> "themselves"

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

; Check that functions with "returns_twice" calls are only inlined,
; if they are themselves marked as such.

declare i32 @a() returns_twice
declare i32 @b() returns_twice

define i32 @f() {
entry:
  %call = call i32 @a() returns_twice
  %add = add nsw i32 1, %call
  ret i32 %add
}

define i32 @g() {
entry:
; CHECK-LABEL: define i32 @g(
; CHECK: call i32 @f()
; CHECK-NOT: call i32 @a()
  %call = call i32 @f()
  %add = add nsw i32 1, %call
  ret i32 %add
}

define i32 @h() returns_twice {
entry:
  %call = call i32 @b() returns_twice
  %add = add nsw i32 1, %call
  ret i32 %add
}

define i32 @i() {
entry:
; CHECK-LABEL: define i32 @i(
; CHECK: call i32 @b()
; CHECK-NOT: call i32 @h()
  %call = call i32 @h() returns_twice
  %add = add nsw i32 1, %call
  ret i32 %add
}


; RUN: llvm-as %s -o %t1.o
; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    -r %t1.o -o %t
; RUN: llvm-readobj -symbols %t | FileCheck %s

; CHECK: Symbol {
; CHECK:   Name: foo
; CHECK-NEXT:   Value: 0x0
; CHECK-NEXT:   Size: 1
; CHECK-NEXT:   Binding: Global
; CHECK-NEXT:   Type: Function
; CHECK-NEXT:   Other: 0
; CHECK-NEXT:   Section: .text.foo
; CHECK-NEXT: }

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

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

define internal void @bar() {
  ret void
}

Fix up a new test to allow it to pass on non x86 builds.

; RUN: llvm-as %s -o %t1.o
; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold.so \
; RUN:    -r %t1.o -o %t
; RUN: llvm-readobj -symbols %t | FileCheck %s

; CHECK: Symbol {
; CHECK:   Name: foo
; CHECK-NEXT:   Value: 0x0
; CHECK-NEXT:   Size: 1
; CHECK-NEXT:   Binding: Global
; CHECK-NEXT:   Type: Function
; CHECK-NEXT:   Other: 0
; CHECK-NEXT:   Section: .text.foo
; CHECK-NEXT: }

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

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

define internal void @bar() {
  ret void
}


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

; CHECK: .cfi_startproc
; CHECK: .cfi_def_cfa_offset 8
; CHECK: .cfi_def_cfa_offset 12
; CHECK: .cfi_def_cfa_offset 32
; CHECK: .cfi_offset %esi, -12
; CHECK: .cfi_offset %edi, -8
; CHECK: .cfi_endproc

%0 = type { i64, i64 }

declare fastcc %0 @ReturnBigStruct() nounwind readnone

define void @test(%0* %p) {
  %1 = call fastcc %0 @ReturnBigStruct()
  store %0 %1, %0* %p
  ret void
}

Add a triple to the test to try to fix the windows bots.

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

; CHECK: .cfi_startproc
; CHECK: .cfi_def_cfa_offset 8
; CHECK: .cfi_def_cfa_offset 12
; CHECK: .cfi_def_cfa_offset 32
; CHECK: .cfi_offset %esi, -12
; CHECK: .cfi_offset %edi, -8
; CHECK: .cfi_endproc

%0 = type { i64, i64 }

declare fastcc %0 @ReturnBigStruct() nounwind readnone

define void @test(%0* %p) {
  %1 = call fastcc %0 @ReturnBigStruct()
  store %0 %1, %0* %p
  ret void
}


; RUN: bugpoint %s -output-prefix %t -bugpoint-crashcalls -silence-passes
; RUN: llvm-dis remove_arguments_test.ll.tmp-reduced-simplified.bc -o - | FileCheck %s

; Test to make sure that arguments are removed from the function if they are
; unnecessary. And clean up any types that that frees up too.

; CHECK: target triple
; CHECK-NOT: struct.anon
%struct.anon = type { i32 }

declare i32 @test2()

; CHECK: define void @test() {
define i32 @test(i32 %A, %struct.anon* %B, float %C) {
	call i32 @test2()
	ret i32 %1
}

Fix this test to work under lit.

; RUN: bugpoint %s -output-prefix %t -bugpoint-crashcalls -silence-passes
; RUN: llvm-dis %t-reduced-simplified.bc -o - | FileCheck %s

; Test to make sure that arguments are removed from the function if they are
; unnecessary. And clean up any types that that frees up too.

; CHECK: target triple
; CHECK-NOT: struct.anon
%struct.anon = type { i32 }

declare i32 @test2()

; CHECK: define void @test() {
define i32 @test(i32 %A, %struct.anon* %B, float %C) {
	call i32 @test2()
	ret i32 %1
}


; RUN: llc < %s -mtriple=arm64-apple-ios

define void @test(float * %p1, i32 %v1) {
entry:
  %v2 = extractelement <3 x float> <float 0.000000e+00, float 2.000000e+00, float 0.000000e+00>, i32 %v1
  store float %v2, float* %p1, align 4
  ret void
}

Add CHECK lines to test case

; RUN: llc < %s -mtriple=arm64-apple-ios | FileCheck %s

; CHECK-LABEL: _test:
; CHECK:  fmov.2d v0, #2.00000000
; CHECK:  str  q0, [sp]
; CHECK:  mov  x8, sp
; CHECK:  ldr s0, [x8, w1, sxtw #2]
; CHECK:  str  s0, [x0]

define void @test(float * %p1, i32 %v1) {
entry:
  %v2 = extractelement <3 x float> <float 0.000000e+00, float 2.000000e+00, float 0.000000e+00>, i32 %v1
  store float %v2, float* %p1, align 4
  ret void
}


; For PR1187
; RUN: llvm-upgrade < %s > /dev/null

%mystruct = type { int, double }
%glob = global %mystruct { int 3, double 42.0 }
%fptr = external global void (i32)*

implementation

csretcc void %nada(%mystruct * %ptr, int %val) {
  ret void
}

int %main(int %argc, ubyte** %argv) {
  %astr = alloca %mystruct
  call void %nada(%mystruct* %astr, i32 7)
  %fptr = alloca void (%mystruct*, i32)*
  %f = load void (%mystruct*, i32)**%fptr
  call csretcc void %f(%mystruct* %astr, i32 7)
  ret int 0
}

Add some more interesting cases to this test.

; For PR1187
; RUN: llvm-upgrade < %s > /dev/null

%mystruct = type { int, double }
%glob = global %mystruct { int 3, double 42.0 }
%fptr = external global void (i32)*

implementation

csretcc void %nada(%mystruct * %ptr, int %val) {
  ret void
}

int %main(int %argc, ubyte** %argv) {
  %astr = alloca %mystruct
  call void %nada(%mystruct* %astr, i32 7)
  %fptr = alloca void (%mystruct*, i32)*
  %f = load void (%mystruct*, i32)**%fptr
  call csretcc void %f(%mystruct* %astr, i32 7)
  store void (%mystruct* , i32)* %nada, void (%mystruct*, i32)** %fptr

  ret int 0
}


; We use ld.lld because llvm-lit will append --full-shutdown to
; the ld.lld invocation.
; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
; RUN: ld.lld %t.o -o %t.so -shared -mllvm -time-passes 2>&1 | FileCheck %s

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

define void @patatino() {
  ret void
}

; We should get the output of -time-passes even when --full-shutdown is not specified.
; CHECK: Total Execution Time

Revert an accidental change to where "-flavor GNU" was used by intention.

; We use lld -flavor gnu because llvm-lit will append --full-shutdown to
; the ld.lld invocation.
; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
; RUN: lld -flavor gnu %t.o -o %t.so -shared -mllvm -time-passes 2>&1 | FileCheck %s

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

define void @patatino() {
  ret void
}

; We should get the output of -time-passes even when --full-shutdown is not specified.
; CHECK: Total Execution Time


; RUN: llc %s -o %t.o -filetype=obj -relocation-model=pic
; RUN: llvm-as %p/Inputs/pr19901-1.ll -o %t2.o
; RUN: ld -shared -o %t.so -plugin %llvmshlibdir/LLVMgold.so %t2.o %t.o
; RUN: llvm-objdump -d -symbolize %t.so | FileCheck %s

; CHECK: g:
; CHECK-NEXT: push
; CHECK-NEXT: callq f

target triple = "x86_64-unknown-linux-gnu"
define i32 @g() {
  call void @f()
  ret i32 0
}
define linkonce_odr hidden void @f() {
  ret void
}

Update to not depend on "llvm-objdump -d -symbolize".

; RUN: llc %s -o %t.o -filetype=obj -relocation-model=pic
; RUN: llvm-as %p/Inputs/pr19901-1.ll -o %t2.o
; RUN: ld -shared -o %t.so -plugin %llvmshlibdir/LLVMgold.so %t2.o %t.o
; RUN: llvm-readobj -t %t.so | FileCheck %s

; CHECK:       Symbol {
; CHECK:         Name: f
; CHECK-NEXT:    Value:
; CHECK-NEXT:    Size:
; CHECK-NEXT:    Binding: Local
; CHECK-NEXT:    Type: Function
; CHECK-NEXT:    Other: 2
; CHECK-NEXT:    Section: .text
; CHECK-NEXT:  }

target triple = "x86_64-unknown-linux-gnu"
define i32 @g() {
  call void @f()
  ret i32 0
}
define linkonce_odr hidden void @f() {
  ret void
}


; RUN: llc < %s | FileCheck %s
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
target triple = "arm64-apple-ios5.0.0"

; Ensure we're generating ldp instructions instead of ldr Q.
; CHECK: ldp
; CHECK: stp
define void @f(i64* %p, i64* %q) {
  %addr2 = getelementptr i64* %q, i32 1
  %addr = getelementptr i64* %p, i32 1
  %x = load i64* %p
  %y = load i64* %addr
  store i64 %x, i64* %q
  store i64 %y, i64* %addr2
  ret void
}

Update test to use a more modern AArch64 triple, as requested by Renato.

; RUN: llc < %s | FileCheck %s
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-linux-gnu"

; Ensure we're generating ldp instructions instead of ldr Q.
; CHECK: ldp
; CHECK: stp
define void @f(i64* %p, i64* %q) {
  %addr2 = getelementptr i64* %q, i32 1
  %addr = getelementptr i64* %p, i32 1
  %x = load i64* %p
  %y = load i64* %addr
  store i64 %x, i64* %q
  store i64 %y, i64* %addr2
  ret void
}


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

define i64 @t(i64 %a, i64 %b) nounwind ssp {
entry:
; CHECK-LABEL: t:
	%asmtmp = tail call i64 asm "rorq $1,$0", "=r,J,0,~{dirflag},~{fpsr},~{flags},~{cc}"(i32 1, i64 %a) nounwind		; <i64> [#uses=1]
; CHECK:      #APP
; CHECK-NEXT: rorq    %[[REG1:.*]]
; CHECK-NEXT: #NO_APP
	%asmtmp1 = tail call i64 asm "rorq $1,$0", "=r,J,0,~{dirflag},~{fpsr},~{flags},~{cc}"(i32 1, i64 %b) nounwind		; <i64> [#uses=1]
; CHECK-NEXT: #APP
; CHECK-NEXT: rorq    %[[REG2:.*]]
; CHECK-NEXT: #NO_APP
	%0 = add i64 %asmtmp1, %asmtmp		; <i64> [#uses=1]
; CHECK-NEXT: leaq    (%[[REG2]],%[[REG1]]), %rax
	ret i64 %0
; CHECK-NEXT: retq
}

Make the test properly constrained

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

define i64 @t(i64 %a, i64 %b) nounwind ssp {
entry:
; CHECK-LABEL: t:
	%asmtmp = tail call i64 asm "rorq $1,$0", "=r,J,0,~{dirflag},~{fpsr},~{flags},~{cc}"(i32 1, i64 %a) nounwind		; <i64> [#uses=1]
; CHECK:      #APP
; CHECK-NEXT: rorq    %[[REG1:.*]]
; CHECK-NEXT: #NO_APP
	%asmtmp1 = tail call i64 asm "rorq $1,$0", "=r,J,0,~{dirflag},~{fpsr},~{flags},~{cc}"(i32 1, i64 %b) nounwind		; <i64> [#uses=1]
; CHECK-NEXT: #APP
; CHECK-NEXT: rorq    %[[REG2:.*]]
; CHECK-NEXT: #NO_APP
	%0 = add i64 %asmtmp1, %asmtmp		; <i64> [#uses=1]
; CHECK-NEXT: leaq    (%[[REG2]],%[[REG1]]), %rax
	ret i64 %0
; CHECK:      retq
}


; RUN: if as < %s | opt -load ~/llvm/lib/Debug/libhello.so -deadargelim | dis | grep DEADARG
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

implementation

; test - an obviously dead argument
internal int %test(int %v, int %DEADARG1, int* %p) {
	store int %v, int* %p
	ret int %v
}

; hardertest - an argument which is only used by a call of a function with a
; dead argument.
internal int %hardertest(int %DEADARG2) {
	%p = alloca int
	%V = call int %test(int 5, int %DEADARG2, int* %p)
	ret int %V
}

; evenhardertest - recursive dead argument...
internal void %evenhardertest(int %DEADARG3) {
	call void %evenhardertest(int %DEADARG3)
	ret void
}

Make testcase more interesting, remove absolute path from -load line

; RUN: if as < %s | opt -deadargelim | dis | grep DEADARG
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi

implementation

; test - an obviously dead argument
internal int %test(int %v, int %DEADARG1, int* %p) {
	store int %v, int* %p
	ret int %v
}

; hardertest - an argument which is only used by a call of a function with a
; dead argument.
internal int %hardertest(int %DEADARG2) {
	%p = alloca int
	%V = call int %test(int 5, int %DEADARG2, int* %p)
	ret int %V
}

; evenhardertest - recursive dead argument...
internal void %evenhardertest(int %DEADARG3) {
	call void %evenhardertest(int %DEADARG3)
	ret void
}

internal void %needarg(int %TEST) {
	call int %needarg2(int %TEST)
	ret void
}

internal int %needarg2(int %TEST) {
	ret int %TEST
}

internal void %needarg3(int %TEST3) {
	call void %needarg(int %TEST3)
	ret void
}


; REQUIRES: x86
; RUN: llvm-as %p/Inputs/linkonce-odr.ll -o %t1.o
; RUN: llc %s -o %t2.o -filetype=obj
; RUN: ld.lld %t1.o %t2.o -o %t.so -shared
; RUN: llvm-readobj -t %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"
declare void @f()

define void @g() {
  call void @f() ret void
}

; Be sure that the linkonce_odr symbol 'f' is kept.
; CHECK: Symbol {
; CHECK:   Name: f
; CHECK:   Value: 0x1010
; CHECK:   Size: 1
; CHECK:   Binding: Weak
; CHECK:   Type: Function
; CHECK:   Other: 0
; CHECK:   Section: .text
; CHECK: }

Tidy up this test a bit.


; test unconditional branch
void %main() {
	br label %Test
Test:
	%X = seteq int 0, 4
	br bool %X, label %Test, label %Label
Label:
	ret void
}

Return 'int 0' instead of void so that the test can be considered to pass.

; test unconditional branch
int %main() {
	br label %Test
Test:
	%X = seteq int 0, 4
	br bool %X, label %Test, label %Label
Label:
	ret int 0
}


; 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

Revert r75663 (and r76805), as it is causing regressions on powerpc.

; Test to make sure that the 'private' is used correctly.
;
; RUN: llvm-as < %s | llc -mtriple=powerpc-unknown-linux-gnu > %t
; RUN: grep .Lfoo: %t
; RUN: grep bl.*\.Lfoo %t
; RUN: grep .Lbaz: %t
; RUN: grep lis.*\.Lbaz %t
; RUN: llvm-as < %s | llc -mtriple=powerpc-apple-darwin > %t
; RUN: grep L_foo: %t
; RUN: grep bl.*\L_foo %t
; RUN: grep L_baz: %t
; RUN: grep lis.*\L_baz %t

define private void @foo() nounwind {
        ret void
}

@baz = private global i32 4;

define i32 @bar() nounwind {
        call void @foo()
	%1 = load i32* @baz, align 4
        ret i32 %1
}


; RUN: llc < %s -march=thumb -stats 2>&1 | \
; RUN:   grep "4 .*Number of machine instrs printed"

;; Integer absolute value, should produce something as good as:
;; Thumb:
;;   movs r0, r0
;;   bpl
;;   rsb r0, r0, #0 (with opitmization, bpl + rsb is if-converted into rsbmi)
;;   bx lr

define i32 @test(i32 %a) {
        %tmp1neg = sub i32 0, %a
        %b = icmp sgt i32 %a, -1
        %abs = select i1 %b, i32 %a, i32 %tmp1neg
        ret i32 %abs
; CHECK:  movs r0, r0
; CHECK:  bpl
; CHECK:  rsb r0, r0, #0
; CHECK:  bx lr
}

Rewrite a test to count emitted instructions without using -stats

; RUN: llc < %s -march=thumb -filetype=obj -o %t.o
; RUN: llvm-objdump -disassemble -arch=thumb %t.o | FileCheck %s

define i32 @test(i32 %a) {
        %tmp1neg = sub i32 0, %a
        %b = icmp sgt i32 %a, -1
        %abs = select i1 %b, i32 %a, i32 %tmp1neg
        ret i32 %abs

; This test just checks that 4 instructions were emitted

; CHECK:      {{^.text:}}
; CHECK-NEXT: 0:
; CHECK-NEXT: 2:
; CHECK-NEXT: 4:
; CHECK-NEXT: 6:

; CHECK-NOT: 8:
}


; RUN: llvm-as < %s | llc -march=ppc32 -mcpu=g5 &&
; RUN: llvm-as < %s | llc -march=ppc32 -mcpu=g5 | not grep mullw
; RUN: llvm-as < %s | llc -march=ppc32 -mcpu=g5 | grep vmsumuhm

<4 x int> %test(<4 x int>* %X, <4 x int>* %Y) {
        %tmp = load <4 x int>* %X
        %tmp2 = load <4 x int>* %Y
        %tmp3 = mul <4 x int> %tmp, %tmp2
        ret <4 x int> %tmp3
}

Add tests for v8i16 and v16i8

; RUN: llvm-as < %s | llc -march=ppc32 -mcpu=g5 &&
; RUN: llvm-as < %s | llc -march=ppc32 -mcpu=g5 | not grep mullw &&
; RUN: llvm-as < %s | llc -march=ppc32 -mcpu=g5 | grep vmsumuhm

<4 x int> %test_v4i32(<4 x int>* %X, <4 x int>* %Y) {
        %tmp = load <4 x int>* %X
        %tmp2 = load <4 x int>* %Y
        %tmp3 = mul <4 x int> %tmp, %tmp2
        ret <4 x int> %tmp3
}

<8 x short> %test_v8i16(<8 x short>* %X, <8 x short>* %Y) {
        %tmp = load <8 x short>* %X
        %tmp2 = load <8 x short>* %Y
        %tmp3 = mul <8 x short> %tmp, %tmp2
        ret <8 x short> %tmp3
}

<16 x sbyte> %test_v16i8(<16 x sbyte>* %X, <16 x sbyte>* %Y) {
        %tmp = load <16 x sbyte>* %X
        %tmp2 = load <16 x sbyte>* %Y
        %tmp3 = mul <16 x sbyte> %tmp, %tmp2
        ret <16 x sbyte> %tmp3
}


define weak void @weakfunc() {
entry:
  ret void
}

Add triple to input file.

target triple = "x86_64-unknown-linux-gnu"
define weak void @weakfunc() {
entry:
  ret void
}


; RUN: llvm-link %s -S -o - | FileCheck %s

@g1 = global void()* @f2
; CHECK: @g1 = global void ()* @f2

@p1 = global i8 42
; CHECK: @p1 = global i8 42

@p2 = internal global i8 43
; CHECK: @p2 = internal global i8 43

define void @f1() prologue i8* @p1 {
  ret void
}
; CHECK: define void @f1() prologue i8* @p1 {

define internal void @f2() prologue i8* @p2 {
  ret void
}

; CHECK: define internal void @f2() prologue i8* @p2 {

Make this test less strict.

; RUN: llvm-link %s -S -o - | FileCheck %s

@g1 = global void()* @f2
; CHECK-DAG: @g1 = global void ()* @f2

@p1 = global i8 42
; CHECK-DAG: @p1 = global i8 42

@p2 = internal global i8 43
; CHECK-DAG: @p2 = internal global i8 43

define void @f1() prologue i8* @p1 {
  ret void
}
; CHECK-DAG: define void @f1() prologue i8* @p1 {

define internal void @f2() prologue i8* @p2 {
  ret void
}

; CHECK-DAG: define internal void @f2() prologue i8* @p2 {


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

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
declare void @f()

define void @g() {
  call void @f()
  ret void
}

; Be sure that 'f' is kept and has weak_odr visibility.
; CHECK: define weak_odr void @f()

Fix typo. Visibility -> Linkage. Pointy-hat to me.

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

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
declare void @f()

define void @g() {
  call void @f()
  ret void
}

; Be sure that 'f' is kept and has weak_odr linkage.
; CHECK: define weak_odr void @f()


; RUN: not llc -verify-machineinstrs -march=r600 -mcpu=SI %s -o /dev/null 2>&1 | FileCheck %s
; RUN: rm %S/private-memory-broken.s

; Make sure promote alloca pass doesn't crash

; CHECK: unsupported call

declare i32 @foo(i32*) nounwind

define void @call_private(i32 addrspace(1)* %out, i32 %in) nounwind {
entry:
  %tmp = alloca [2 x i32]
  %tmp1 = getelementptr [2 x i32]* %tmp, i32 0, i32 0
  %tmp2 = getelementptr [2 x i32]* %tmp, i32 0, i32 1
  store i32 0, i32* %tmp1
  store i32 1, i32* %tmp2
  %tmp3 = getelementptr [2 x i32]* %tmp, i32 0, i32 %in
  %val = call i32 @foo(i32* %tmp3) nounwind
  store i32 %val, i32 addrspace(1)* %out
  ret void
}

Revert "Temporary hack to try cleaning extra .s file from bots."

; RUN: not llc -verify-machineinstrs -march=r600 -mcpu=SI %s -o /dev/null 2>&1 | FileCheck %s

; Make sure promote alloca pass doesn't crash

; CHECK: unsupported call

declare i32 @foo(i32*) nounwind

define void @call_private(i32 addrspace(1)* %out, i32 %in) nounwind {
entry:
  %tmp = alloca [2 x i32]
  %tmp1 = getelementptr [2 x i32]* %tmp, i32 0, i32 0
  %tmp2 = getelementptr [2 x i32]* %tmp, i32 0, i32 1
  store i32 0, i32* %tmp1
  store i32 1, i32* %tmp2
  %tmp3 = getelementptr [2 x i32]* %tmp, i32 0, i32 %in
  %val = call i32 @foo(i32* %tmp3) nounwind
  store i32 %val, i32 addrspace(1)* %out
  ret void
}


; RUN: opt %s -S -place-safepoints | FileCheck %s

declare void @foo() "gc-leaf-function"

; Calls of functions with the "gc-leaf-function" attribute shouldn't get
; safepoints.  An entry safepoint should get inserted, though.
define void @test_leaf_function() gc "statepoint-example" {
; CHECK-LABEL: test_leaf_function
; CHECK: gc.statepoint.p0f_isVoidf
; CHECK-NOT: statepoint
; CHECK-NOT: gc.result
entry:
  call void @foo()
  ret void
}

; This function is inlined when inserting a poll.
declare void @do_safepoint()
define void @gc.safepoint_poll() {
; CHECK-LABEL: gc.safepoint_poll
entry:
  call void @do_safepoint()
  ret void
}

Correct my last commit (revision 256860).

; RUN: opt %s -S -place-safepoints | FileCheck %s

declare void @foo() "gc-leaf-function"

; Calls of functions with the "gc-leaf-function" attribute shouldn't be turned
; into a safepoint.  An entry safepoint should get inserted, though.
define void @test_leaf_function() gc "statepoint-example" {
; CHECK-LABEL: test_leaf_function
; CHECK: gc.statepoint.p0f_isVoidf
; CHECK-NOT: statepoint
; CHECK-NOT: gc.result
entry:
  call void @foo()
  ret void
}

; This function is inlined when inserting a poll.
declare void @do_safepoint()
define void @gc.safepoint_poll() {
; CHECK-LABEL: gc.safepoint_poll
entry:
  call void @do_safepoint()
  ret void
}


; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
; RUN: llvm-as %p/Inputs/internalize-exportdyn.ll -o %t2.o
; RUN: ld.lld -m elf_x86_64 %t.o %t2.o -o %t2 --export-dynamic -save-temps
; RUN: llvm-dis < %t2.lto.bc | FileCheck %s

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

define void @_start() {
  ret void
}

define void @foo() {
  ret void
}

define hidden void @bar() {
  ret void
}

define linkonce_odr void @zed() unnamed_addr {
  ret void
}

define linkonce_odr void @bah() {
  ret void
}

define linkonce_odr void @baz() {
  ret void
}

@use_baz = global void ()* @baz

; Check what gets internalized.
; CHECK: define void @_start()
; CHECK: define void @foo()
; CHECK: define internal void @bar()
; CHECK: define internal void @zed()
; CHECK: define weak_odr void @bah()
; CHECK: define weak_odr void @baz()

Add a test showing that the new local_unnamed_addr attribute can permit internalization.

; REQUIRES: x86
; RUN: llvm-as %s -o %t.o
; RUN: llvm-as %p/Inputs/internalize-exportdyn.ll -o %t2.o
; RUN: ld.lld -m elf_x86_64 %t.o %t2.o -o %t2 --export-dynamic -save-temps
; RUN: llvm-dis < %t2.lto.bc | FileCheck %s

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

define void @_start() {
  ret void
}

define void @foo() {
  ret void
}

define hidden void @bar() {
  ret void
}

define linkonce_odr void @zed() local_unnamed_addr {
  ret void
}

define linkonce_odr void @zed2() unnamed_addr {
  ret void
}

define linkonce_odr void @bah() {
  ret void
}

define linkonce_odr void @baz() {
  ret void
}

@use_baz = global void ()* @baz

; Check what gets internalized.
; CHECK: define void @_start()
; CHECK: define void @foo()
; CHECK: define internal void @bar()
; CHECK: define internal void @zed()
; CHECK: define internal void @zed2()
; CHECK: define weak_odr void @bah()
; CHECK: define weak_odr void @baz()


; RUN: llvm-as < %s | llc -march=ppc32 -mcpu=g5 | grep vxor | wc -l | grep 1
; There should be exactly one vxor here, not two.

void %test(<4 x float>* %P1, <4 x int>* %P2) {
        store <4 x float> zeroinitializer, <4 x float>* %P1
        store <4 x int> zeroinitializer, <4 x int>* %P2
        ret void
}

Make this test more interesting by checking that the 0.0 used to implement vector fmul gets cse'd also.

; RUN: llvm-as < %s | llc -march=ppc32 -mcpu=g5 --enable-unsafe-fp-math | grep vxor | wc -l | grep 1
; There should be exactly one vxor here.

void %test(<4 x float>* %P1, <4 x int>* %P2, <4 x float>* %P3) {
        %tmp = load <4 x float>* %P3
        %tmp3 = load <4 x float>* %P1
        %tmp4 = mul <4 x float> %tmp, %tmp3
        store <4 x float> %tmp4, <4 x float>* %P3
        store <4 x float> zeroinitializer, <4 x float>* %P1
        store <4 x int> zeroinitializer, <4 x int>* %P2
        ret void
}


; RUN: llc -march=hexagon -filetype=obj %s -o - \
; RUN: | llvm-objdump -d - | FileCheck %s

define i32 @foo (i1 %a, i32 %b, i32 %c)
{
  %1 = select i1 %a, i32 %b, i32 %c
  ret i32 %1
}

; CHECK: 00 40 00 85 85004000
; CHECK: 00 40 9f 52 529f4000
; CHECK: 00 60 01 74 74016000
; CHECK: 00 e0 82 74 7482e000

Fix testcase accidentally broken by r296645


; RUN: llvm-as %s -o %t.o
; RUN: wasm-ld %t.o %t.o -o %t.wasm -r
; RUN: llvm-readobj -t %t.wasm | FileCheck %s

target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown-wasm"

define weak void @f() {
  ret void
}

; CHECK:        Symbol {
; CHECK-NEXT:     Name: f
; CHECK-NEXT:     Type: FUNCTION (0x0)
; CHECK-NEXT:     Flags: 0x1
; CHECK-NEXT:   }

Update test to match new readobj output. NFC.

; RUN: llvm-as %s -o %t.o
; RUN: wasm-ld %t.o %t.o -o %t.wasm -r
; RUN: llvm-readobj -t %t.wasm | FileCheck %s

target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown-wasm"

define weak void @f() {
  ret void
}

; CHECK:        Symbol {
; CHECK-NEXT:     Name: f
; CHECK-NEXT:     Type: FUNCTION (0x0)
; CHECK-NEXT:     Flags: 0x1
; CHECK-NEXT:     ElementIndex: 0x0
; CHECK-NEXT:   }


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

; Test that SCCP has basic knowledge of when and/or/mul nuke overdefined values.

; CHECK-LABEL: test
; CHECK: ret i32 0
 define i32 @test(i32 %X) {
  %Y = and i32 %X, 0
  ret i32 %Y
}

; CHECK-LABEL: test2
; CHECK: ret i32 -1
define i32 @test2(i32 %X) {
  %Y = or i32 -1, %X
  ret i32 %Y
}

; CHECK-LABEL: test3
; CHECK: ret i32 0
define i32 @test3(i32 %X) {
  %Y = and i32 undef, %X
  ret i32 %Y
}

; CHECK-LABEL: test4
; CHECK: ret i32 -1
define i32 @test4(i32 %X) {
  %Y = or i32 %X, undef
  ret i32 %Y
}

; CHECK-LABEL: test5
; CHECK: ret i32 0
define i32 @test5(i32 %foo) {
  %patatino = mul i32 %foo, undef
  ret i32 %patatino
}

Make the test added in r289175 more meaningful.

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

; Test that SCCP has basic knowledge of when and/or/mul nuke overdefined values.

; CHECK-LABEL: test
; CHECK: ret i32 0
 define i32 @test(i32 %X) {
  %Y = and i32 %X, 0
  ret i32 %Y
}

; CHECK-LABEL: test2
; CHECK: ret i32 -1
define i32 @test2(i32 %X) {
  %Y = or i32 -1, %X
  ret i32 %Y
}

; CHECK-LABEL: test3
; CHECK: ret i32 0
define i32 @test3(i32 %X) {
  %Y = and i32 undef, %X
  ret i32 %Y
}

; CHECK-LABEL: test4
; CHECK: ret i32 -1
define i32 @test4(i32 %X) {
  %Y = or i32 %X, undef
  ret i32 %Y
}

; X * 0 = 0 even if X is overdefined.
; CHECK-LABEL: test5
; CHECK: ret i32 0
define i32 @test5(i32 %foo) {
  %patatino = mul i32 %foo, 0
  ret i32 %patatino
}


; RUN: llvm-as < %s | llc -march=x86 -o %t -f
; RUN: grep unpcklpd %t | count 1
; RUN: grep movapd %t | count 1

; Shows a dag combine bug that will generate an illegal build vector
; with v2i64 build_vector i32, i32.

define void @test(<2 x double>* %dst, <4 x double> %src) {
entry:
        %tmp7.i = shufflevector <4 x double> %src, <4 x double> undef, <2 x i32> < i32 0, i32 2 >
        store <2 x double> %tmp7.i, <2 x double>* %dst
        ret void
}

Add newline at end of file.


; RUN: llvm-upgrade < %s | llvm-as | opt  -licm -stats |& \
; RUN:   grep {memory locations promoted to register}

%X = global int 7

void %testfunc(int %i) {
	br label %Loop

Loop:
	%j = phi uint [0, %0], [%Next, %Loop]

	%x = load int* %X  ; Should promote this to a register inside of loop!
	%x2 = add int %x, 1
	store int %x2, int* %X

	%Next = add uint %j, 1
	%cond = seteq uint %Next, 0
	br bool %cond, label %Out, label %Loop

Out:
	ret void
}

void %testhard(int %i) {
	br label %Loop
Loop:
	%X1 = getelementptr int* %X, long 0
	%A = load int* %X1 ; Aliases X, needs to be rewritten
	%V = add int %A, 1
	%X2 = getelementptr int* %X, long 0
	store int %V, int* %X2
	br bool false, label %Loop, label %Exit

Exit:
	ret void

}

Fix this test from Duncan's experiment.


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

; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep div

implementation

int %test1(int %A) {
	%B = div int %A, 1
	ret int %B
}

uint %test2(uint %A) {
	%B = div uint %A, 8   ; => Shift
	ret int %B
}

int %test3(int %A) {
	%B = div int 0, %A    ; => 0, don't need to keep traps
	ret int %B
}

Add a new testcase for X/-1, fix bug that prevented tests from running right

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

; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep div

implementation

int %test1(int %A) {
	%B = div int %A, 1
	ret int %B
}

uint %test2(uint %A) {
	%B = div uint %A, 8   ; => Shift
	ret uint %B
}

int %test3(int %A) {
	%B = div int 0, %A    ; => 0, don't need to keep traps
	ret int %B
}

int %test4(int %A) {
	%B = div int %A, -1    ; 0-A
	ret int %B
}


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

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

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

Allow this to pass on non-linux systems as well, such as darwin

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

target triple = "i686-pc-linux-gnu"

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

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


; RUN: opt < %s -instcombine -S > %t
target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"

define i1 @test1(i32 *%x) nounwind {
entry:
; RUN: grep {ptrtoint i32\\* %x to i64} %t
	%tmp = ptrtoint i32* %x to i1
	ret i1 %tmp
}

define i32* @test2(i128 %x) nounwind {
entry:
; RUN: grep {inttoptr i64 %.mp1 to i32\\*} %t
	%tmp = inttoptr i128 %x to i32*
	ret i32* %tmp
}

Convert this test to FileCheck and add a testcase for PR3574.

; RUN: opt < %s -instcombine -S | FileCheck %s
target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"

define i1 @test1(i32 *%x) nounwind {
entry:
; CHECK: test1
; CHECK: ptrtoint i32* %x to i64
	%tmp = ptrtoint i32* %x to i1
	ret i1 %tmp
}

define i32* @test2(i128 %x) nounwind {
entry:
; CHECK: test2
; CHECK: inttoptr i64 %tmp1 to i32*
	%tmp = inttoptr i128 %x to i32*
	ret i32* %tmp
}

; PR3574
; CHECK: f0
; CHECK: %tmp = zext i32 %a0 to i64
; CHECK: ret i64 %tmp
define i64 @f0(i32 %a0) nounwind {
       %t0 = inttoptr i32 %a0 to i8*
       %t1 = ptrtoint i8* %t0 to i64
       ret i64 %t1
}


; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-gnu -mcpu=pwr8 -mattr=+vsx < %s | FileCheck %s

define <4 x float> @bar(float* %p, float* %q) {
  %1 = bitcast float* %p to <12 x float>*
  %2 = bitcast float* %q to <12 x float>*
  %3 = load <12 x float>, <12 x float>* %1, align 16
  %4 = load <12 x float>, <12 x float>* %2, align 16
  %5 = fsub <12 x float> %4, %3
  %6 = shufflevector <12 x float> %5, <12 x float> undef, <4 x i32> <i32 0, i32 3, i32 6, i32 9>
  ret <4 x float>  %6

; CHECK: xxspltw
; CHECK: vmrghw
; CHECK: vsldoi
}

Make test slightly more explicit. NFC.

; RUN: llc -verify-machineinstrs -mtriple=powerpc64-linux-gnu -mcpu=pwr8 -mattr=+vsx < %s | FileCheck %s

define <4 x float> @bar(float* %p, float* %q) {
  %1 = bitcast float* %p to <12 x float>*
  %2 = bitcast float* %q to <12 x float>*
  %3 = load <12 x float>, <12 x float>* %1, align 16
  %4 = load <12 x float>, <12 x float>* %2, align 16
  %5 = fsub <12 x float> %4, %3
  %6 = shufflevector <12 x float> %5, <12 x float> undef, <4 x i32> <i32 0, i32 3, i32 6, i32 9>
  ret <4 x float>  %6

; CHECK: xxspltw
; CHECK-NEXT: xxspltw
; CHECK-NEXT: xxspltw
; CHECK-NEXT: vmrghw
; CHECK-NEXT: vmrghw
; CHECK-NEXT: xxswapd
; CHECK-NEXT: vsldoi
; CHECK-NEXT: blr
}


; REQUIRES: x86
; RUN: llvm-mc -filetype=obj -o %t.o %p/Inputs/dynsym.s
; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -shared
; RUN: llvm-as %s -o %t2.o
; RUN: ld.lld -m elf_x86_64 %t2.o %t.so -o %t
; RUN: llvm-readobj -dyn-symbols %t | FileCheck %s

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

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

; CHECK:      Name: foo
; CHECK-NEXT: Value:
; CHECK-NEXT: Size:
; CHECK-NEXT: Binding:
; CHECK-NEXT: Type:
; CHECK-NEXT: Other:
; CHECK-NEXT: Section: .text
define void @foo() {
  ret void
}

Add triple to llvm-mc command line. Should fix Windows bot.

; REQUIRES: x86
; RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux -o %t.o %p/Inputs/dynsym.s
; RUN: ld.lld -m elf_x86_64 %t.o -o %t.so -shared
; RUN: llvm-as %s -o %t2.o
; RUN: ld.lld -m elf_x86_64 %t2.o %t.so -o %t
; RUN: llvm-readobj -dyn-symbols %t | FileCheck %s

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

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

; CHECK:      Name: foo
; CHECK-NEXT: Value:
; CHECK-NEXT: Size:
; CHECK-NEXT: Binding:
; CHECK-NEXT: Type:
; CHECK-NEXT: Other:
; CHECK-NEXT: Section: .text
define void @foo() {
  ret void
}


; RUN: llvm-as < %s | llc -march=ppc64 > %t
; RUN: grep  __floattitf %t
; RUN: grep  __fixunstfti %t

target datalayout = "E-p:64:64:64-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-f128:64:128"
target triple = "powerpc64-apple-darwin9.2.0"

define ppc_fp128 @foo(i128 %a) nounwind  {
entry:
	%tmp2829 = uitofp i128 %a to ppc_fp128		; <i64> [#uses=1]
	ret ppc_fp128 %tmp2829
}
define i128 @boo(ppc_fp128 %a) nounwind  {
entry:
	%tmp2829 = fptoui ppc_fp128 %a to i128		; <i64> [#uses=1]
	ret i128 %tmp2829
}

Check that running the DAG combiner between type and operation legalization does something useful.

; RUN: llvm-as < %s | llc -march=ppc64 -debug |& not grep store
; RUN: llvm-as < %s | llc -march=ppc64 > %t
; RUN: grep  __floattitf %t
; RUN: grep  __fixunstfti %t

target datalayout = "E-p:64:64:64-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-f128:64:128"
target triple = "powerpc64-apple-darwin9.2.0"

define ppc_fp128 @foo(i128 %a) nounwind  {
entry:
	%tmp2829 = uitofp i128 %a to ppc_fp128		; <i64> [#uses=1]
	ret ppc_fp128 %tmp2829
}
define i128 @boo(ppc_fp128 %a) nounwind  {
entry:
	%tmp2829 = fptoui ppc_fp128 %a to i128		; <i64> [#uses=1]
	ret i128 %tmp2829
}


; RUN: llc < %s -march=thumb -filetype=obj -o %t.o
; RUN: llvm-objdump -disassemble -arch=thumb %t.o | FileCheck %s

define i32 @test(i32 %a) {
        %tmp1neg = sub i32 0, %a
        %b = icmp sgt i32 %a, -1
        %abs = select i1 %b, i32 %a, i32 %tmp1neg
        ret i32 %abs

; This test just checks that 4 instructions were emitted

; CHECK:      {{^.text:}}
; CHECK-NEXT: 0:
; CHECK-NEXT: 2:
; CHECK-NEXT: 4:
; CHECK-NEXT: 6:

; CHECK-NOT: 8:
}

Revert "Rewrite a test to count emitted instructions without using -stats"

; RUN: llc < %s -march=thumb -stats 2>&1 | \
; RUN:   grep "4 .*Number of machine instrs printed"

;; Integer absolute value, should produce something as good as:
;; Thumb:
;;   movs r0, r0
;;   bpl
;;   rsb r0, r0, #0 (with opitmization, bpl + rsb is if-converted into rsbmi)
;;   bx lr

define i32 @test(i32 %a) {
        %tmp1neg = sub i32 0, %a
        %b = icmp sgt i32 %a, -1
        %abs = select i1 %b, i32 %a, i32 %tmp1neg
        ret i32 %abs
; CHECK:  movs r0, r0
; CHECK:  bpl
; CHECK:  rsb r0, r0, #0
; CHECK:  bx lr
}


; RUN: llvm-as < %s > %t.bc
; RUN: llvm-as < `dirname %s`/testlink1.ll > %t2.bc
; RUN: llvm-link %t.bc %t.bc %t2.bc -o %t1.bc
; RUN: llvm-dis < %t1.bc |grep "kallsyms_names = extern_weak" &&
; RUN: llvm-dis < %t1.bc |grep "MyVar = external global int" &&
; RUN: llvm-dis < %t1.bc |grep "Inte = global int"

%kallsyms_names = extern_weak global [0 x ubyte]
%MyVar     = extern_weak global int
%Inte = extern_weak global int

implementation

Make sure linker output is overwritten so this test can pass multiple times.

; RUN: llvm-as < %s > %t.bc
; RUN: llvm-as < `dirname %s`/testlink1.ll > %t2.bc
; RUN: llvm-link %t.bc %t.bc %t2.bc -o %t1.bc -f
; RUN: llvm-dis < %t1.bc |grep "kallsyms_names = extern_weak" &&
; RUN: llvm-dis < %t1.bc |grep "MyVar = external global int" &&
; RUN: llvm-dis < %t1.bc |grep "Inte = global int"

%kallsyms_names = extern_weak global [0 x ubyte]
%MyVar     = extern_weak global int
%Inte = extern_weak global int

implementation


void %main() {
	%A = and sbyte 4, 8
	%B = or sbyte %A, 7
	%C = xor sbyte %B, %A

	%A = and short 4, 8
	%B = or short %A, 7
	%C = xor short %B, %A

	%A = and int 4, 8
	%B = or int %A, 7
	%C = xor int %B, %A

	ret void
}

Make testcase return 0 on success

int %main() {
	%A = and sbyte 4, 8
	%B = or sbyte %A, 7
	%C = xor sbyte %B, %A

	%A = and short 4, 8
	%B = or short %A, 7
	%C = xor short %B, %A

	%A = and int 4, 8
	%B = or int %A, 7
	%C = xor int %B, %A

	ret int 0
}


implementation

;; This is a simple nested loop to test interval construction

int "loop test"(int %i, int %j)
begin
Start:
	%j1 = add int 0, 0
	br label %L1Header

L1Header:
	%j2 = phi int [%j1, %Start], [%j3, %L2Done]

	%i1 = add int 0, 0             ; %i1 = 0
	br label %L2Body
L2Body:
	%i2 = phi int [%i1, %L1Header], [%i3, %L2Body]
	%i3 = add int %i2, 1
	%L2Done = seteq int %i3, 10
	br bool %L2Done, label %L2Done, label %L2Body
L2Done:
	%j3 = add int %j2, %i3
	%L1Done = seteq int %j3, 100
	br bool %L1Done, label %L1Done, label %L1Header

L1Done:
	ret int %j3
end

Add a useless phi for testing with InductionVariables stuff

implementation

;; This is a simple nested loop to test interval construction

int "loop test"(int %i, int %j)
begin
Start:
	%j1 = add int 0, 0
	br label %L1Header

L1Header:
	%j2 = phi int [%j1, %Start], [%j3, %L2Done]

	%i1 = add int 0, 0             ; %i1 = 0
	br label %L2Body
L2Body:
	%wl = phi int [%j, %L1Header], [%wl, %L2Body]    ;; Useless PHI
	%i2 = phi int [%i1, %L1Header], [%i3, %L2Body]
	%i3 = add int %i2, 1
	%L2Done = seteq int %i3, 10
	br bool %L2Done, label %L2Done, label %L2Body
L2Done:
	%j3 = add int %j2, %i3
	%L1Done = seteq int %j3, 100
	br bool %L1Done, label %L1Done, label %L1Header

L1Done:
	ret int %j3
end


; REQUIRES: x86
; RUN: rm -f %t.so %t.so.lto.bc %t.so.lto.o
; RUN: llvm-as %s -o %t.o
; RUN: llvm-as %p/Inputs/save-temps.ll -o %t2.o
; RUN: ld.lld -shared -m elf_x86_64 %t.o %t2.o -o %t.so -save-temps
; RUN: llvm-nm %t.so | FileCheck %s
; RUN: llvm-nm %t.so.lto.bc | FileCheck %s
; RUN: llvm-nm %t.so.lto.o | FileCheck %s

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

define void @foo() {
  ret void
}

; CHECK: T bar
; CHECK: T foo

Use %t as the output file name to avoid repetition. NFC.

; REQUIRES: x86
; RUN: rm -f %t %t.lto.bc %t.lto.o
; RUN: llvm-as %s -o %t.o
; RUN: llvm-as %p/Inputs/save-temps.ll -o %t2.o
; RUN: ld.lld -shared -m elf_x86_64 %t.o %t2.o -o %t -save-temps
; RUN: llvm-nm %t | FileCheck %s
; RUN: llvm-nm %t.lto.bc | FileCheck %s
; RUN: llvm-nm %t.lto.o | FileCheck %s

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

define void @foo() {
  ret void
}

; CHECK: T bar
; CHECK: T foo


; This test makes sure we can extract the instrumentation map from an
; XRay-instrumented object file.
;
; RUN: llvm-xray extract %S/Inputs/elf64-example.bin | FileCheck %s

; CHECK:      ---
; CHECK-NEXT: - { id: 1, address: 0x000000000041C900, function: 0x000000000041C900, kind: function-enter, always-instrument: true }
; CHECK-NEXT: - { id: 1, address: 0x000000000041C912, function: 0x000000000041C900, kind: function-exit, always-instrument: true }
; CHECK-NEXT: - { id: 2, address: 0x000000000041C930, function: 0x000000000041C930, kind: function-enter, always-instrument: true }
; CHECK-NEXT: - { id: 2, address: 0x000000000041C946, function: 0x000000000041C930, kind: function-exit, always-instrument: true }
; CHECK-NEXT: ...

Fix yaml matching to be more permissive

; This test makes sure we can extract the instrumentation map from an
; XRay-instrumented object file.
;
; RUN: llvm-xray extract %S/Inputs/elf64-example.bin | FileCheck %s

; CHECK:      ---
; CHECK-NEXT: - { id: 1, address: 0x000000000041C900, function: 0x000000000041C900, kind: function-enter, always-instrument: true{{.*}} }
; CHECK-NEXT: - { id: 1, address: 0x000000000041C912, function: 0x000000000041C900, kind: function-exit, always-instrument: true{{.*}} }
; CHECK-NEXT: - { id: 2, address: 0x000000000041C930, function: 0x000000000041C930, kind: function-enter, always-instrument: true{{.*}} }
; CHECK-NEXT: - { id: 2, address: 0x000000000041C946, function: 0x000000000041C930, kind: function-exit, always-instrument: true{{.*}} }
; CHECK-NEXT: ...


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

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

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

; CHECK: define available_externally void @bar() {

Make the test a bit more interesting.

; 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() {


void %main() {
	%double1 = add double 0.0, 0.0
	%double2 = add double 0.0, 0.0
	%float1 = add float 0.0, 0.0
	%float2 = add float 0.0, 0.0
	%test49 = seteq float %float1, %float2
	%test50 = setge float %float1, %float2
	%test51 = setgt float %float1, %float2
	%test52 = setle float %float1, %float2
	%test53 = setlt float %float1, %float2
	%test54 = setne float %float1, %float2
	%test55 = seteq double %double1, %double2
	%test56 = setge double %double1, %double2
	%test57 = setgt double %double1, %double2
	%test58 = setle double %double1, %double2
	%test59 = setlt double %double1, %double2
	%test60 = setne double %double1, %double2
	ret void
}

Return 'int 0' instead of 'void' so that the test can be seen as successful.

int %main() {
	%double1 = add double 0.0, 0.0
	%double2 = add double 0.0, 0.0
	%float1 = add float 0.0, 0.0
	%float2 = add float 0.0, 0.0
	%test49 = seteq float %float1, %float2
	%test50 = setge float %float1, %float2
	%test51 = setgt float %float1, %float2
	%test52 = setle float %float1, %float2
	%test53 = setlt float %float1, %float2
	%test54 = setne float %float1, %float2
	%test55 = seteq double %double1, %double2
	%test56 = setge double %double1, %double2
	%test57 = setgt double %double1, %double2
	%test58 = setle double %double1, %double2
	%test59 = setlt double %double1, %double2
	%test60 = setne double %double1, %double2
	ret int 0
}


; RUN: llvm-as < %s | llc -march=ppc32 | grep {fabs f1, f1}

define double @fabs(double %f) {
entry:
	%tmp2 = tail call double @fabs( double %f )		; <double> [#uses=1]
	ret double %tmp2
}

Add explicit triples to avoid default behavior that varies by host.

; RUN: llvm-as < %s | llc -march=ppc32 -mtriple=powerpc-apple-darwin | grep {fabs f1, f1}

define double @fabs(double %f) {
entry:
	%tmp2 = tail call double @fabs( double %f )		; <double> [#uses=1]
	ret double %tmp2
}


; 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: not llvm-ar r %T/test.a . 2>&1 | FileCheck %s
;CHECK: . Is a directory

;RUN: rm -f %T/test.a
;RUN: touch %T/a-very-long-file-name
;RUN: llvm-ar r %T/test.a %s %T/a-very-long-file-name
;RUN: llvm-ar r %T/test.a %T/a-very-long-file-name
;RUN: llvm-ar t %T/test.a | FileCheck -check-prefix=MEMBERS %s
;MEMBERS-NOT: /
;MEMBERS: a-very-long-file-name
;MEMBERS: directory.ll
;MEMBERS-NOT: a-very-long-file-name

Fix an ordering problem in the test.

;RUN: not llvm-ar r %T/test.a . 2>&1 | FileCheck %s
;CHECK: . Is a directory

;RUN: rm -f %T/test.a
;RUN: touch %T/a-very-long-file-name
;RUN: llvm-ar r %T/test.a %s %T/a-very-long-file-name
;RUN: llvm-ar r %T/test.a %T/a-very-long-file-name
;RUN: llvm-ar t %T/test.a | sort | FileCheck -check-prefix=MEMBERS %s
;MEMBERS-NOT: /
;MEMBERS: a-very-long-file-name
;MEMBERS: directory.ll
;MEMBERS-NOT: a-very-long-file-name


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

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

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

Add an additional InstructionSimplify factorization test.

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

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

define i32 @factorize2(i32 %x) {
; CHECK: @factorize2
; 3*X - 2*X -> X
  %l = mul i32 3, %x
  %r = mul i32 2, %x
  %z = sub i32 %l, %r
  ret i32 %z
; CHECK: ret i32 %x
}

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


; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu -mattr=+sse2,-avx | grep movq
; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu -mattr=+sse2,-avx | grep mov | count 1
; RUN: llc < %s -march=x86-64 -mtriple=x86_64-pc-linux -mattr=+sse2-avx | grep movd

define <2 x i64> @t1(i64 %x) nounwind  {
	%tmp8 = insertelement <2 x i64> zeroinitializer, i64 %x, i32 0
	ret <2 x i64> %tmp8
}

Fix a typo in the mattr part of the run line.

; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu -mattr=+sse2,-avx | grep movq
; RUN: llc < %s -march=x86 -mtriple=i386-linux-gnu -mattr=+sse2,-avx | grep mov | count 1
; RUN: llc < %s -march=x86-64 -mtriple=x86_64-pc-linux -mattr=+sse2,-avx | grep movd

define <2 x i64> @t1(i64 %x) nounwind  {
	%tmp8 = insertelement <2 x i64> zeroinitializer, i64 %x, i32 0
	ret <2 x i64> %tmp8
}


; RUN: llc < %s -march=x86 -mattr=+sse2

define <4 x float> @t1(<4 x float> %Q) {
        %tmp15 = fsub <4 x float> < float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00 >, %Q
	ret <4 x float> %tmp15
}

define <4 x float> @t2(<4 x float> %Q) {
        %tmp15 = fsub <4 x float> zeroinitializer, %Q
	ret <4 x float> %tmp15
}

Fix a test that has no checks.

; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mcpu=corei7 | FileCheck %s

; FNEG is defined as subtraction from -0.0.

; This test verifies that we use an xor with a constant to flip the sign bits; no subtraction needed.
define <4 x float> @t1(<4 x float> %Q) {
; CHECK-LABEL: t1:
; CHECK: xorps	{{.*}}LCPI0_0{{.*}}, %xmm0
; CHECK-NEXT: retq
        %tmp = fsub <4 x float> < float -0.000000e+00, float -0.000000e+00, float -0.000000e+00, float -0.000000e+00 >, %Q
	ret <4 x float> %tmp
}

; This test verifies that we generate an FP subtraction because "0.0 - x" is not an fneg.
define <4 x float> @t2(<4 x float> %Q) {
; CHECK-LABEL: t2:
; CHECK: xorps	%[[X:xmm[0-9]+]], %[[X]]
; CHECK-NEXT: subps	%xmm0, %[[X]]
; CHECK-NEXT: movaps	%[[X]], %xmm0
; CHECK-NEXT: retq
        %tmp = fsub <4 x float> zeroinitializer, %Q
	ret <4 x float> %tmp
}


; RUN: llc < %s
; PR7170

%big = type [131072 x i8]

declare void @foo(%big* byval align 1)

define void @bar(%big* byval align 1 %x) {
  call void @foo(%big* byval align 1 %x)
  ret void
}

Revert r129875, XFAILing this test for arm, since the fix was reverted.

; RUN: llc < %s
; PR7170
; XFAIL: arm

%big = type [131072 x i8]

declare void @foo(%big* byval align 1)

define void @bar(%big* byval align 1 %x) {
  call void @foo(%big* byval align 1 %x)
  ret void
}


; RUN: (llvm-upgrade < %s | llvm-as -o /dev/null -f) 2>&1 | grep 'Cannot resolve type'
; Test for PR463.  This program is erroneous, but should not crash llvm-as.
%.FOO  = internal global %struct.none zeroinitializer

Fix this to check for the correct error message.

; RUN: (llvm-upgrade < %s | llvm-as -o /dev/null -f) 2>&1 | \
; RUN:   grep 'Cannot create a null initialized value of this type!'
; Test for PR463.  This program is erroneous, but should not crash llvm-as.
%.FOO  = internal global %struct.none zeroinitializer


; This testcase was incorrectly computing that the loopentry.7 loop was
; not a child of the loopentry.6 loop.
;
; RUN: llvm-as < %s | opt -analyze -loops | \
; RUN:   grep {^            Loop Containing: %loopentry.7}

define void @getAndMoveToFrontDecode() {
	br label %endif.2

endif.2:		; preds = %loopexit.5, %0
	br i1 false, label %loopentry.5, label %UnifiedExitNode

loopentry.5:		; preds = %loopexit.6, %endif.2
	br i1 false, label %loopentry.6, label %UnifiedExitNode

loopentry.6:		; preds = %loopentry.7, %loopentry.5
	br i1 false, label %loopentry.7, label %loopexit.6

loopentry.7:		; preds = %loopentry.7, %loopentry.6
	br i1 false, label %loopentry.7, label %loopentry.6

loopexit.6:		; preds = %loopentry.6
	br i1 false, label %loopentry.5, label %loopexit.5

loopexit.5:		; preds = %loopexit.6
	br i1 false, label %endif.2, label %UnifiedExitNode

UnifiedExitNode:		; preds = %loopexit.5, %loopentry.5, %endif.2
	ret void
}

Update this test for the LoopInfo::print changes.

; This testcase was incorrectly computing that the loopentry.7 loop was
; not a child of the loopentry.6 loop.
;
; RUN: llvm-as < %s | opt -analyze -loops | \
; RUN:   grep {^            Loop at depth 4 containing: %loopentry.7<header><latch><exit>}

define void @getAndMoveToFrontDecode() {
	br label %endif.2

endif.2:		; preds = %loopexit.5, %0
	br i1 false, label %loopentry.5, label %UnifiedExitNode

loopentry.5:		; preds = %loopexit.6, %endif.2
	br i1 false, label %loopentry.6, label %UnifiedExitNode

loopentry.6:		; preds = %loopentry.7, %loopentry.5
	br i1 false, label %loopentry.7, label %loopexit.6

loopentry.7:		; preds = %loopentry.7, %loopentry.6
	br i1 false, label %loopentry.7, label %loopentry.6

loopexit.6:		; preds = %loopentry.6
	br i1 false, label %loopentry.5, label %loopexit.5

loopexit.5:		; preds = %loopexit.6
	br i1 false, label %endif.2, label %UnifiedExitNode

UnifiedExitNode:		; preds = %loopexit.5, %loopentry.5, %endif.2
	ret void
}


; RUN: llc < %s -march=ppc64 -mcpu=g5 | FileCheck %s

define i32 @_ZNK4llvm5APInt17countLeadingZerosEv(i64 *%t) nounwind {
        %tmp19 = load i64* %t
        %tmp22 = tail call i64 @llvm.ctlz.i64( i64 %tmp19, i1 true )             ; <i64> [#uses=1]
        %tmp23 = trunc i64 %tmp22 to i32
        %tmp89 = add i32 %tmp23, -64          ; <i32> [#uses=1]
        %tmp90 = add i32 %tmp89, 0            ; <i32> [#uses=1]
        ret i32 %tmp90

; CHECK-LABEL: @_ZNK4llvm5APInt17countLeadingZerosEv
; CHECK: ld [[REG1:[0-9]+]], 0(3)
; CHECK-NEXT: cntlzd [[REG2:[0-9]+]], [[REG1]]
; CHECK-NEXT: addi 3, [[REG2]], -64
; CHECK-NEXT: blr
}

declare i64 @llvm.ctlz.i64(i64, i1)

Fix test to pass on Darwin hosts

; RUN: llc -mcpu=g5 < %s | FileCheck %s
target datalayout = "E-m:e-i64:64-n32:64"
target triple = "powerpc64-unknown-linux-gnu"

define i32 @_ZNK4llvm5APInt17countLeadingZerosEv(i64 *%t) nounwind {
        %tmp19 = load i64* %t
        %tmp22 = tail call i64 @llvm.ctlz.i64( i64 %tmp19, i1 true )             ; <i64> [#uses=1]
        %tmp23 = trunc i64 %tmp22 to i32
        %tmp89 = add i32 %tmp23, -64          ; <i32> [#uses=1]
        %tmp90 = add i32 %tmp89, 0            ; <i32> [#uses=1]
        ret i32 %tmp90

; CHECK-LABEL: @_ZNK4llvm5APInt17countLeadingZerosEv
; CHECK: ld [[REG1:[0-9]+]], 0(3)
; CHECK-NEXT: cntlzd [[REG2:[0-9]+]], [[REG1]]
; CHECK-NEXT: addi 3, [[REG2]], -64
; CHECK-NEXT: blr
}

declare i64 @llvm.ctlz.i64(i64, i1)


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

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

implementation

int "test1"(int %A) {
	%B = shl int %A, ubyte 0
	ret int %B
}

int "test2"(ubyte %A) {
	%B = shl int 0, ubyte %A
	ret int %B
}

int "test3"(int %A) {
	%B = shr int %A, ubyte 0
	ret int %B
}

int "test4"(ubyte %A) {
	%B = shr int 0, ubyte %A
	ret int %B
}

uint "test5"(uint %A) {
	%B = shr uint %A, ubyte 32  ;; shift all bits out
	ret uint %B
}

uint %test6(uint %A) {
	%B = shl uint %A, ubyte 1   ;; convert to an add instruction
	ret uint %B
}

Add new testcase for arithmetic shr of -1

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

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

implementation

int "test1"(int %A) {
	%B = shl int %A, ubyte 0
	ret int %B
}

int "test2"(ubyte %A) {
	%B = shl int 0, ubyte %A
	ret int %B
}

int "test3"(int %A) {
	%B = shr int %A, ubyte 0
	ret int %B
}

int "test4"(ubyte %A) {
	%B = shr int 0, ubyte %A
	ret int %B
}

uint "test5"(uint %A) {
	%B = shr uint %A, ubyte 32  ;; shift all bits out
	ret uint %B
}

uint %test6(uint %A) {
	%B = shl uint %A, ubyte 1   ;; convert to an add instruction
	ret uint %B
}

int %test7(ubyte %A) {
	%B = shr int -1, ubyte %A   ;; Always equal to -1
	ret int %B
}


; Test that: extern int X[]  and int X[] = { 1, 2, 3, 4 } are resolved
; correctly.
;
; RUN: if as < %s | opt -funcresolve | dis | grep external
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi
;

%X = external global int
%X = global [4 x int] [ int 1, int 2, int 3, int 4 ]

implementation   ; Functions:

int %foo(int %x) {
bb1:                                    ;[#uses=0]
	store int 5, int* getelementptr (int* %X, long 2)
	%F = getelementptr int* %X, long 2
	%val = load int* %F
        ret int %val
}

Add check to see if opt aborts

; Test that: extern int X[]  and int X[] = { 1, 2, 3, 4 } are resolved
; correctly.
;
; RUN: if as < %s | opt -funcresolve > /dev/null
; RUN: then echo "opt ok"
; RUN: else exit 1   # Make sure opt doesn't abort!
; RUN: fi
;
; RUN: if as < %s | opt -funcresolve | dis | grep external
; RUN: then exit 1
; RUN: else exit 0
; RUN: fi
;

%X = external global int
%X = global [4 x int] [ int 1, int 2, int 3, int 4 ]

implementation   ; Functions:

int %foo(int %x) {
bb1:                                    ;[#uses=0]
	store int 5, int* getelementptr (int* %X, long 2)
	%F = getelementptr int* %X, long 2
	%val = load int* %F
        ret int %val
}


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

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

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

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

Improve testcase portability on OS/X

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

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

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

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


; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=core-avx2 -mattr=+avx2 | FileCheck %s

; Make sure that we don't match this shuffle using the vpblendw instruction.
; The mask for the vpblendw instruction needs to be identical for both halves
; of the YMM.

; CHECK: blendw1
; CHECK-NOT: vpblendw
; CHECK: ret
define <16 x i16> @blendw1(<16 x i16> %a, <16 x i16> %b) nounwind alwaysinline {
  %t = shufflevector <16 x i16> %a, <16 x i16> %b, <16 x i32> <i32 0, i32 17, i32 18, i32 3, i32 20, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15>
  ret <16 x i16> %t
}

Fix the testcase. We do expect two vblendw on XMMs.

; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=core-avx2 -mattr=+avx2 | FileCheck %s

; Make sure that we don't match this shuffle using the vpblendw YMM instruction.
; The mask for the vpblendw instruction needs to be identical for both halves
; of the YMM. Need to use two vpblendw instructions.

; CHECK: blendw1
; CHECK: vpblendw
; CHECK: vpblendw
; CHECK: ret
define <16 x i16> @blendw1(<16 x i16> %a, <16 x i16> %b) nounwind alwaysinline {
  %t = shufflevector <16 x i16> %a, <16 x i16> %b, <16 x i32> <i32 0, i32 17, i32 18, i32 3, i32 20, i32 5, i32 6, i32 7, i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 31>
  ret <16 x i16> %t
}


; RUN: llc < %s -march=ptx32 -mattr=sm20 | FileCheck %s

define ptx_device float @stack1(float %a) {
  ; CHECK: .local .b32 __local0;
  %a.2 = alloca float
  ; CHECK: st.local.f32 [__local0], %f0
  store float %a, float* %a.2
  %a.3 = load float* %a.2
  ret float %a.3
}

Add .align tests to stack object test file

; RUN: llc < %s -march=ptx32 -mattr=sm20 | FileCheck %s

define ptx_device float @stack1(float %a) {
  ; CHECK: .local .align 4 .b32 __local0;
  %a.2 = alloca float, align 4
  ; CHECK: st.local.f32 [__local0], %f0
  store float %a, float* %a.2
  %a.3 = load float* %a.2
  ret float %a.3
}

define ptx_device float @stack1_align8(float %a) {
  ; CHECK: .local .align 8 .b32 __local0;
  %a.2 = alloca float, align 8
  ; CHECK: st.local.f32 [__local0], %f0
  store float %a, float* %a.2
  %a.3 = load float* %a.2
  ret float %a.3
}


implementation

declare int "printf"(sbyte*, ...)   ;; Prototype for: int __builtin_printf(const char*, ...)

int "testvarar"()
begin
	cast int 0 to sbyte*
	call int(sbyte*, ...) *%printf(sbyte * %0, int 12, sbyte 42);
	ret int %0
end

Use null keyword instead of kludge

implementation

declare int "printf"(sbyte*, ...)   ;; Prototype for: int __builtin_printf(const char*, ...)

int "testvarar"()
begin
	call int(sbyte*, ...) *%printf(sbyte * null, int 12, sbyte 42);
	ret int %0
end


; REQUIRES: shell
; RUN: llvm-link %s %S/Inputs/targettriple-a.ll -S -o - 2>%t.a.err | FileCheck %s
; RUN: (echo foo ;cat %t.a.err) | FileCheck --check-prefix=WARN-A %s

; RUN: llvm-link %s %S/Inputs/targettriple-b.ll -S -o - 2>%t.b.err | FileCheck %s
; RUN: cat %t.b.err | FileCheck --check-prefix=WARN-B %s

; RUN: llvm-link -suppress-warnings %s %S/Inputs/targettriple-b.ll -S -o - 2>%t.no-warn.err | FileCheck %s
; RUN: (echo foo ;cat %t.no-warn.err) | FileCheck --check-prefix=WARN-A %s

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

; CHECK: target triple = "x86_64-unknown-linux-gnu"

; WARN-A-NOT: WARNING

; i386 and x86_64 map to different ArchType enums.
; WARN-B: WARNING: Linking two modules of different target triples:

; x86_64h and x86_64 map to the same ArchType enum.
; WARN-C-NOT: WARNING

Add run line that was missing in r228999.

; REQUIRES: shell
; RUN: llvm-link %s %S/Inputs/targettriple-a.ll -S -o - 2>%t.a.err | FileCheck %s
; RUN: cat %t.a.err | FileCheck --check-prefix=WARN-A %s --allow-empty

; RUN: llvm-link %s %S/Inputs/targettriple-b.ll -S -o - 2>%t.b.err | FileCheck %s
; RUN: cat %t.b.err | FileCheck --check-prefix=WARN-B %s
; RUN: llvm-link %s %S/Inputs/targettriple-c.ll -S -o - 2>%t.c.err | FileCheck %s
; RUN: cat %t.c.err | FileCheck --check-prefix=WARN-C %s --allow-empty

; RUN: llvm-link -suppress-warnings %s %S/Inputs/targettriple-b.ll -S -o - 2>%t.no-warn.err | FileCheck %s
; RUN: cat %t.no-warn.err | FileCheck --check-prefix=WARN-A %s --allow-empty

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

; CHECK: target triple = "x86_64-unknown-linux-gnu"

; WARN-A-NOT: WARNING

; i386 and x86_64 map to different ArchType enums.
; WARN-B: WARNING: Linking two modules of different target triples:

; x86_64h and x86_64 map to the same ArchType enum.
; WARN-C-NOT: WARNING


; RUN: llc -filetype=obj %p/Inputs/ret32.ll -o %t.ret32.o
; RUN: llc -filetype=obj %s -o %t.main.o
; RUN: not lld -flavor wasm --check-signatures --check-signatures -o %t.wasm %t.main.o %t.ret32.o 2>&1 | FileCheck %s

target triple = "wasm32-unknown-unknown-wasm"

; Function Attrs: nounwind
define hidden void @_start() local_unnamed_addr #0 {
entry:
  %call = tail call i32 @ret32(i32 1, i64 2, i32 3) #2
  ret void
}

declare i32 @ret32(i32, i64, i32) local_unnamed_addr #1

; CHECK: error: function signature mismatch: ret32
; CHECK-NEXT: >>> defined as (I32, I64, I32) -> I32 in {{.*}}.main.o
; CHECK-NEXT: >>> defined as (F32) -> I32 in {{.*}}.ret32.o

Fix typo in test file

; RUN: llc -filetype=obj %p/Inputs/ret32.ll -o %t.ret32.o
; RUN: llc -filetype=obj %s -o %t.main.o
; RUN: not lld -flavor wasm --check-signatures -o %t.wasm %t.main.o %t.ret32.o 2>&1 | FileCheck %s

target triple = "wasm32-unknown-unknown-wasm"

; Function Attrs: nounwind
define hidden void @_start() local_unnamed_addr #0 {
entry:
  %call = tail call i32 @ret32(i32 1, i64 2, i32 3) #2
  ret void
}

declare i32 @ret32(i32, i64, i32) local_unnamed_addr #1

; CHECK: error: function signature mismatch: ret32
; CHECK-NEXT: >>> defined as (I32, I64, I32) -> I32 in {{.*}}.main.o
; CHECK-NEXT: >>> defined as (F32) -> I32 in {{.*}}.ret32.o