Remove llvm-upgrade and update tests.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48103 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Tanya Lattner 2008-03-09 08:16:40 +00:00
parent 90b347dc90
commit 76806b6a43
65 changed files with 864 additions and 788 deletions

View File

@ -4,6 +4,7 @@
; RUN: llvm-as < %s | llc -march=alpha | grep gprel32
; RUN: llvm-as < %s | llc -march=alpha | grep ldl
; RUN: llvm-as < %s | llc -march=alpha | grep rodata
; END.
target datalayout = "e-p:64:64"
target triple = "alphaev67-unknown-linux-gnu"

View File

@ -1,8 +1,8 @@
; RUN: llvm-upgrade < %s | llvm-as > %t.bc
; RUN: llvm-as < %s > %t.bc
; RUN: echo | llvm-as > %t.tmp.bc
; RUN: llvm-link %t.tmp.bc %t.bc
%X = constant int 5
%Y = internal global [2 x int*] [ int* %X, int * %X]
@X = constant i32 5 ; <i32*> [#uses=2]
@Y = internal global [2 x i32*] [ i32* @X, i32* @X ] ; <[2 x i32*]*> [#uses=0]

View File

@ -1,9 +1,10 @@
; This fails linking when it is linked with an empty file as the first object file
; RUN: llvm-as > %t1.bc < /dev/null
; RUN: llvm-upgrade < %s | llvm-as > %t2.bc
; RUN: llvm-as < %s > %t2.bc
; RUN: llvm-link %t1.bc %t2.bc
%work = global int (int, int)* %zip
@work = global i32 (i32, i32)* @zip ; <i32 (i32, i32)**> [#uses=0]
declare i32 @zip(i32, i32)
declare int %zip(int, int)

View File

@ -1,9 +1,9 @@
; This fails linking when it is linked with an empty file as the first object file
; RUN: llvm-as > %t.LinkTest.bc < /dev/null
; RUN: llvm-upgrade < %s | llvm-as > %t.bc
; RUN: llvm-as < %s > %t.bc
; RUN: llvm-link %t.LinkTest.bc %t.bc
%work = global int 4
%test = global int* getelementptr( int* %work, long 1)
@work = global i32 4 ; <i32*> [#uses=1]
@test = global i32* getelementptr (i32* @work, i64 1) ; <i32**> [#uses=0]

View File

@ -1,19 +1,17 @@
; This one fails because the LLVM runtime is allowing two null pointers of
; the same type to be created!
; RUN: echo {%T = type int} | llvm-upgrade | llvm-as > %t.2.bc
; RUN: llvm-upgrade < %s | llvm-as -f > %t.1.bc
; RUN: echo {%T = type i32} | llvm-as > %t.2.bc
; RUN: llvm-as < %s -f > %t.1.bc
; RUN: llvm-link %t.1.bc %t.2.bc
%T = type opaque
declare %T* %create()
declare %T* @create()
implementation
void %test() {
%X = call %T* %create()
%v = seteq %T* %X, null
define void @test() {
%X = call %T* @create( ) ; <%T*> [#uses=1]
%v = icmp eq %T* %X, null ; <i1> [#uses=0]
ret void
}

View File

@ -2,9 +2,9 @@
; the same type to be created!
; RUN: echo {%S = type \{ %T*\} %T = type opaque} | llvm-as > %t.2.bc
; RUN: llvm-upgrade < %s | llvm-as > %t.1.bc
; RUN: llvm-as < %s > %t.1.bc
; RUN: llvm-link %t.1.bc %t.2.bc
%S = type { %T* }
%T = type int
%S = type { i32* }
%T = type i32

View File

@ -1,7 +1,7 @@
; RUN: echo {%T = type opaque} | llvm-upgrade | llvm-as > %t.2.bc
; RUN: llvm-upgrade < %s | llvm-as > %t.1.bc
; RUN: echo {%T = type opaque} | llvm-as > %t.2.bc
; RUN: llvm-as < %s > %t.1.bc
; RUN: llvm-link %t.1.bc %t.2.bc
%T = type opaque
%a = constant { %T* } { %T* null }
@a = constant { %T* } zeroinitializer ; <{ %T* }*> [#uses=0]

View File

@ -1,8 +1,7 @@
; RUN: echo {%T = type int} | llvm-upgrade | llvm-as > %t.1.bc
; RUN: llvm-upgrade < %s | llvm-as > %t.2.bc
; RUN: echo {%T = type i32} | llvm-as > %t.1.bc
; RUN: llvm-as < %s > %t.2.bc
; RUN: llvm-link %t.1.bc %t.2.bc
%T = type opaque
%X = constant {%T*} {%T* null }
@X = constant { %T* } zeroinitializer ; <{ %T* }*> [#uses=0]

View File

@ -1,7 +1,8 @@
; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
; RUN: echo {%S = type \{ int, int* \} } | llvm-upgrade | llvm-as > %t.out2.bc
; RUN: llvm-as < %s > %t.out1.bc
; RUN: echo {%S = type \{ i32, i32* \} } | llvm-as > %t.out2.bc
; RUN: llvm-link %t.out1.bc %t.out2.bc
%S = type { i32, %T* }
%T = type opaque
%S = type { int, %T* }
;%X = global { int, %T* } { int 5, %T* null }

View File

@ -1,10 +1,10 @@
; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
; RUN: echo {%S = external global \{ int, opaque* \} declare void %F(opaque*)}\
; RUN: | llvm-upgrade | llvm-as > %t.out2.bc
; RUN: llvm-as < %s > %t.out1.bc
; RUN: echo {@S = external global \{ i32, opaque* \} declare void @F(opaque*)}\
; RUN: | llvm-as > %t.out2.bc
; RUN: llvm-link %t.out1.bc %t.out2.bc | llvm-dis | not grep opaque
; After linking this testcase, there should be no opaque types left. The two
; S's should cause the opaque type to be resolved to 'int'.
%S = global { int, int* } { int 5, int* null }
@S = global { i32, i32* } { i32 5, i32* null } ; <{ i32, i32* }*> [#uses=0]
declare void %F(int*)
declare void @F(i32*)

View File

@ -1,8 +1,9 @@
; It's a bad idea to go recursively traipsing through types without a safety
; net.
; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
; RUN: echo "%S = type { %S*, int* }" | llvm-upgrade | llvm-as > %t.out2.bc
; RUN: llvm-as < %s > %t.out1.bc
; RUN: echo "%S = type { %S*, i32* }" | llvm-as > %t.out2.bc
; RUN: llvm-link %t.out1.bc %t.out2.bc
%S = type { %S*, opaque* }

View File

@ -1,12 +1,12 @@
; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
; RUN: echo "%S = type int" | llvm-upgrade | llvm-as > %t.out2.bc
; RUN: llvm-as < %s > %t.out1.bc
; RUN: echo "%S = type i32" | llvm-as > %t.out2.bc
; RUN: llvm-link %t.out2.bc %t.out1.bc
%S = type opaque
void %foo(int* %V) {
ret void
define void @foo(i32* %V) {
ret void
}
declare void %foo(%S*)
declare void @foo.upgrd.1(%S*)

View File

@ -1,17 +1,18 @@
; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
; RUN: echo "%S = type int" | llvm-upgrade | llvm-as > %t.out2.bc
; RUN: llvm-as < %s > %t.out1.bc
; RUN: echo "%S = type i32" | llvm-as > %t.out2.bc
; RUN: llvm-link %t.out2.bc %t.out1.bc
%S = type opaque
void %foo(int* %V) {
ret void
}
declare void %foo(%S*)
void %other() {
call void %foo(%S* null) ; Add a use of the unresolved proto
call void %foo(int* null) ; Add a use of the resolved function
define void @foo(i32* %V) {
ret void
}
declare void @foo.upgrd.1(%S*)
define void @other() {
call void @foo.upgrd.1( %S* null )
call void @foo( i32* null )
ret void
}

View File

@ -1,15 +1,15 @@
; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
; RUN: echo "%S = type int" | llvm-upgrade | llvm-as > %t.out2.bc
; RUN: llvm-as < %s > %t.out1.bc
; RUN: echo "%S = type i32" | llvm-as > %t.out2.bc
; RUN: llvm-link %t.out2.bc %t.out1.bc
%S = type opaque
; GLobal using the resolved function prototype
global void(%S*)* %foo
global void (%S*)* @foo ; <void (%S*)**>:0 [#uses=0]
void %foo(int* %V) {
ret void
define void @foo.upgrd.1(i32* %V) {
ret void
}
declare void %foo(%S*)
declare void @foo(%S*)

View File

@ -1,7 +1,7 @@
; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
; RUN: llvm-as < %s > %t.out1.bc
; RUN: echo { %S = type \[8 x i32\] external global %S } | llvm-as > %t.out2.bc
; RUN: llvm-link %t.out1.bc %t.out2.bc | llvm-dis | grep %S | grep \{
%S = type { int }
%S = type { i32 }

View File

@ -1,8 +1,8 @@
; The linker should merge link-once globals into strong external globals,
; just like it does for weak symbols!
; RUN: echo "%X = global int 7" | llvm-upgrade | llvm-as > %t.2.bc
; RUN: llvm-upgrade < %s | llvm-as > %t.1.bc
; RUN: echo "@X = global i32 7" | llvm-as > %t.2.bc
; RUN: llvm-as < %s > %t.1.bc
; RUN: llvm-link %t.1.bc %t.2.bc
%X = linkonce global int 7
@X = linkonce global i32 7

View File

@ -3,6 +3,7 @@
; Test that -indvars can reduce variable stride IVs. If it can reduce variable
; stride iv's, it will make %iv. and %m.0.0 isomorphic to each other without
; cycles, allowing the tmp.21 subtraction to be eliminated.
; END.
define void @vnum_test8(i32* %data) {
entry:

View File

@ -6,6 +6,8 @@
;
; RUN: llvm-as < %s | opt -instcombine
;
; END.
@.LC0 = internal global [21 x i8] c"hbMakeCodeLengths(1)\00" ; <[21 x i8]*> [#uses=1]
@.LC1 = internal global [21 x i8] c"hbMakeCodeLengths(2)\00" ; <[21 x i8]*> [#uses=1]

View File

@ -11,7 +11,7 @@
;
; Extra code:
; RUN: llvm-as < %s | opt -instcombine
;
; END.
target datalayout = "e-p:32:32"
@silly = external constant i32 ; <i32*> [#uses=1]

View File

@ -11,7 +11,7 @@
;
; RUN: llvm-as < %s -o - | opt -instcombine | llvm-dis | \
; RUN: notcast .*int
; END.
define i1 @lt_signed_to_large_unsigned(i8 %SB) {
%Y = sext i8 %SB to i32 ; <i32> [#uses=1]
%C = icmp ult i32 %Y, 1024 ; <i1> [#uses=1]

View File

@ -1,4 +1,5 @@
; RUN: llvm-as < %s | opt -instcombine -disable-output
; END.
%struct.DecRefPicMarking_s = type { i32, i32, i32, i32, i32, %struct.DecRefPicMarking_s* }
%struct.datapartition = type { %typedef.Bitstream*, %typedef.DecodingEnvironment, i32 (%struct.syntaxelement*, %struct.img_par*, %struct.inp_par*, %struct.datapartition*)* }
%struct.img_par = type { i32, i32, i32, i32, i32*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x [16 x i16]], [6 x [32 x i32]], [16 x [16 x i32]], [4 x [12 x [4 x [4 x i32]]]], [16 x i32], i32**, i32*, i32***, i32**, i32, i32, i32, i32, %typedef.Slice*, %struct.macroblock*, i32, i32, i32, i32, i32, i32, i32**, %struct.DecRefPicMarking_s*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [3 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32***, i32***, i32****, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.timeb, %struct.timeb, i32, i32, i32, i32, i32, i32, i32, i32 }

View File

@ -1,4 +1,5 @@
; RUN: llvm-as < %s | opt -instcombine -disable-output
; END.
define void @test() {
bb38.i:

View File

@ -1,4 +1,5 @@
; RUN: llvm-as < %s | opt -instcombine -disable-output
; END.
%struct.gs_matrix = type { float, i32, float, i32, float, i32, float, i32, float, i32, float, i32 }
%struct.gx_bitmap = type { i8*, i32, i32, i32 }
%struct.gx_device = type { i32, %struct.gx_device_procs*, i8*, i32, i32, float, float, i32, i16, i32, i32 }

View File

@ -1,5 +1,6 @@
; PR905
; RUN: llvm-as < %s | opt -instcombine -disable-output
; END.
%RPYTHON_EXCEPTION = type { %RPYTHON_EXCEPTION_VTABLE* }
%RPYTHON_EXCEPTION_VTABLE = type { %RPYTHON_EXCEPTION_VTABLE*, i32, i32, %RPyOpaque_RuntimeTypeInfo*, %arraytype_Char*, %functiontype_12* }

View File

@ -1,5 +1,6 @@
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: grep {icmp sgt}
; END.
target datalayout = "e-p:32:32"
target triple = "i686-pc-linux-gnu"
%struct.point = type { i32, i32 }

View File

@ -1,4 +1,5 @@
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep select
; END.
target datalayout = "e-p:32:32"
target triple = "i686-pc-linux-gnu"

View File

@ -1,5 +1,6 @@
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: grep -v {icmp ult i32}
; END.
target datalayout = "e-p:32:32"
target triple = "i686-pc-linux-gnu"

View File

@ -2,6 +2,7 @@
; RUN: grep icmp | count 1
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: grep {icmp ugt} | count 1
; END.
target datalayout = "e-p:32:32"
target triple = "i686-pc-linux-gnu"

View File

@ -1,6 +1,7 @@
; For PR1065. This causes an assertion in instcombine if a select with two cmp
; operands is encountered.
; RUN: llvm-as < %s | opt -instcombine -disable-output
; END.
target datalayout = "e-p:32:32"
target triple = "i686-pc-linux-gnu"

View File

@ -1,6 +1,5 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: grep select | not grep {i32\\*}
; END.
; This testcase corresponds to PR362, which notices that this horrible code
; is generated by the C++ front-end and LLVM optimizers, which has lots of
@ -9,28 +8,27 @@
; Instcombine should propagate the load through the select instructions to
; allow elimination of the extra stuff by the mem2reg pass.
implementation ; Functions:
void %_Z5test1RiS_(int* %x, int* %y) {
define void @_Z5test1RiS_(i32* %x, i32* %y) {
entry:
%tmp.1.i = load int* %y ; <int> [#uses=1]
%tmp.3.i = load int* %x ; <int> [#uses=1]
%tmp.4.i = setlt int %tmp.1.i, %tmp.3.i ; <bool> [#uses=1]
%retval.i = select bool %tmp.4.i, int* %y, int* %x ; <int*> [#uses=1]
%tmp.4 = load int* %retval.i ; <int> [#uses=1]
store int %tmp.4, int* %x
ret void
%tmp.1.i = load i32* %y ; <i32> [#uses=1]
%tmp.3.i = load i32* %x ; <i32> [#uses=1]
%tmp.4.i = icmp slt i32 %tmp.1.i, %tmp.3.i ; <i1> [#uses=1]
%retval.i = select i1 %tmp.4.i, i32* %y, i32* %x ; <i32*> [#uses=1]
%tmp.4 = load i32* %retval.i ; <i32> [#uses=1]
store i32 %tmp.4, i32* %x
ret void
}
void %_Z5test2RiS_(int* %x, int* %y) {
define void @_Z5test2RiS_(i32* %x, i32* %y) {
entry:
%tmp.0 = alloca int ; <int*> [#uses=2]
%tmp.2 = load int* %x ; <int> [#uses=2]
store int %tmp.2, int* %tmp.0
%tmp.3.i = load int* %y ; <int> [#uses=1]
%tmp.4.i = setlt int %tmp.2, %tmp.3.i ; <bool> [#uses=1]
%retval.i = select bool %tmp.4.i, int* %y, int* %tmp.0 ; <int*> [#uses=1]
%tmp.6 = load int* %retval.i ; <int> [#uses=1]
store int %tmp.6, int* %y
ret void
%tmp.0 = alloca i32 ; <i32*> [#uses=2]
%tmp.2 = load i32* %x ; <i32> [#uses=2]
store i32 %tmp.2, i32* %tmp.0
%tmp.3.i = load i32* %y ; <i32> [#uses=1]
%tmp.4.i = icmp slt i32 %tmp.2, %tmp.3.i ; <i1> [#uses=1]
%retval.i = select i1 %tmp.4.i, i32* %y, i32* %tmp.0 ; <i32*> [#uses=1]
%tmp.6 = load i32* %retval.i ; <i32> [#uses=1]
store i32 %tmp.6, i32* %y
ret void
}

View File

@ -1,9 +1,10 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -gcse -instcombine | \
; RUN: llvm-as < %s | opt -instcombine -gcse -instcombine | \
; RUN: llvm-dis | not grep getelementptr
bool %test(int* %A) {
%B = getelementptr int* %A, int 1
%C = getelementptr int* %A, uint 1
%V = seteq int* %B, %C
ret bool %V
define i1 @test(i32* %A) {
%B = getelementptr i32* %A, i32 1 ; <i32*> [#uses=1]
%C = getelementptr i32* %A, i64 1 ; <i32*> [#uses=1]
%V = icmp eq i32* %B, %C ; <i1> [#uses=1]
ret i1 %V
}

View File

@ -1,9 +1,9 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | notcast
target endian = little
target pointersize = 32
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | notcast
target datalayout = "e-p:32:32"
int *%test(int *%P) {
%V = cast int* %P to int
%P2 = cast int %V to int*
ret int* %P2
define i32* @test(i32* %P) {
%V = ptrtoint i32* %P to i32 ; <i32> [#uses=1]
%P2 = inttoptr i32 %V to i32* ; <i32*> [#uses=1]
ret i32* %P2
}

View File

@ -1,15 +1,15 @@
; This is the sequence of stuff that the Java front-end expands for a single
; <= comparison. Check to make sure we turn it into a <= (only)
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: grep -v {icmp sle} | not grep #uses
bool %le(int %A, int %B) {
%c1 = setgt int %A, %B;
%tmp = select bool %c1, int 1, int 0;
%c2 = setlt int %A, %B;
%result = select bool %c2, int -1, int %tmp;
%c3 = setle int %result, 0;
ret bool %c3;
define i1 @le(i32 %A, i32 %B) {
%c1 = icmp sgt i32 %A, %B ; <i1> [#uses=1]
%tmp = select i1 %c1, i32 1, i32 0 ; <i32> [#uses=1]
%c2 = icmp slt i32 %A, %B ; <i1> [#uses=1]
%result = select i1 %c2, i32 -1, i32 %tmp ; <i32> [#uses=1]
%c3 = icmp sle i32 %result, 0 ; <i1> [#uses=1]
ret i1 %c3
}

View File

@ -1,251 +1,270 @@
; This test makes sure that add instructions are properly eliminated.
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: grep -v OK | not grep add
; END.
implementation
int %test1(int %A) {
%B = add int %A, 0
ret int %B
define i32 @test1(i32 %A) {
%B = add i32 %A, 0 ; <i32> [#uses=1]
ret i32 %B
}
int %test2(int %A) {
%B = add int %A, 5
%C = add int %B, -5
ret int %C
define i32 @test2(i32 %A) {
%B = add i32 %A, 5 ; <i32> [#uses=1]
%C = add i32 %B, -5 ; <i32> [#uses=1]
ret i32 %C
}
int %test3(int %A) {
%B = add int %A, 5
%C = sub int %B, 5 ;; This should get converted to an add
ret int %C
define i32 @test3(i32 %A) {
%B = add i32 %A, 5 ; <i32> [#uses=1]
;; This should get converted to an add
%C = sub i32 %B, 5 ; <i32> [#uses=1]
ret i32 %C
}
int %test4(int %A, int %B) {
%C = sub int 0, %A
%D = add int %B, %C ; D = B + -A = B - A
ret int %D
define i32 @test4(i32 %A, i32 %B) {
%C = sub i32 0, %A ; <i32> [#uses=1]
; D = B + -A = B - A
%D = add i32 %B, %C ; <i32> [#uses=1]
ret i32 %D
}
int %test5(int %A, int %B) {
%C = sub int 0, %A
%D = add int %C, %B ; D = -A + B = B - A
ret int %D
define i32 @test5(i32 %A, i32 %B) {
%C = sub i32 0, %A ; <i32> [#uses=1]
; D = -A + B = B - A
%D = add i32 %C, %B ; <i32> [#uses=1]
ret i32 %D
}
int %test6(int %A) {
%B = mul int 7, %A
%C = add int %B, %A ; C = 7*A+A == 8*A == A << 3
ret int %C
define i32 @test6(i32 %A) {
%B = mul i32 7, %A ; <i32> [#uses=1]
; C = 7*A+A == 8*A == A << 3
%C = add i32 %B, %A ; <i32> [#uses=1]
ret i32 %C
}
int %test7(int %A) {
%B = mul int 7, %A
%C = add int %A, %B ; C = A+7*A == 8*A == A << 3
ret int %C
define i32 @test7(i32 %A) {
%B = mul i32 7, %A ; <i32> [#uses=1]
; C = A+7*A == 8*A == A << 3
%C = add i32 %A, %B ; <i32> [#uses=1]
ret i32 %C
}
; (A & C1)+(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
int %test8(int %A, int %B) {
%A1 = and int %A, 7
%B1 = and int %B, 128
%C = add int %A1, %B1
ret int %C
define i32 @test8(i32 %A, i32 %B) {
%A1 = and i32 %A, 7 ; <i32> [#uses=1]
%B1 = and i32 %B, 128 ; <i32> [#uses=1]
%C = add i32 %A1, %B1 ; <i32> [#uses=1]
ret i32 %C
}
int %test9(int %A) {
%B = shl int %A, ubyte 4
%C = add int %B, %B ; === shl int %A, 5
ret int %C
define i32 @test9(i32 %A) {
%B = shl i32 %A, 4 ; <i32> [#uses=2]
; === shl int %A, 5
%C = add i32 %B, %B ; <i32> [#uses=1]
ret i32 %C
}
bool %test10(ubyte %A, ubyte %b) {
%B = add ubyte %A, %b
%c = setne ubyte %B, 0 ; === A != -b
ret bool %c
define i1 @test10(i8 %A, i8 %b) {
%B = add i8 %A, %b ; <i8> [#uses=1]
; === A != -b
%c = icmp ne i8 %B, 0 ; <i1> [#uses=1]
ret i1 %c
}
bool %test11(ubyte %A) {
%B = add ubyte %A, 255
%c = setne ubyte %B, 0 ; === A != 1
ret bool %c
define i1 @test11(i8 %A) {
%B = add i8 %A, -1 ; <i8> [#uses=1]
; === A != 1
%c = icmp ne i8 %B, 0 ; <i1> [#uses=1]
ret i1 %c
}
int %test12(int %A, int %B) {
%C_OK = add int %B, %A ; Should be transformed into shl A, 1
br label %X
X:
%D = add int %C_OK, %A
ret int %D
define i32 @test12(i32 %A, i32 %B) {
; Should be transformed into shl A, 1
%C_OK = add i32 %B, %A ; <i32> [#uses=1]
br label %X
X: ; preds = %0
%D = add i32 %C_OK, %A ; <i32> [#uses=1]
ret i32 %D
}
int %test13(int %A, int %B, int %C) {
%D_OK = add int %A, %B
%E_OK = add int %D_OK, %C
%F = add int %E_OK, %A ;; shl A, 1
ret int %F
define i32 @test13(i32 %A, i32 %B, i32 %C) {
%D_OK = add i32 %A, %B ; <i32> [#uses=1]
%E_OK = add i32 %D_OK, %C ; <i32> [#uses=1]
;; shl A, 1
%F = add i32 %E_OK, %A ; <i32> [#uses=1]
ret i32 %F
}
uint %test14(uint %offset, uint %difference) {
%tmp.2 = and uint %difference, 3
%tmp.3_OK = add uint %tmp.2, %offset
%tmp.5.mask = and uint %difference, 4294967292
%tmp.8 = add uint %tmp.3_OK, %tmp.5.mask ; == add %offset, %difference
ret uint %tmp.8
define i32 @test14(i32 %offset, i32 %difference) {
%tmp.2 = and i32 %difference, 3 ; <i32> [#uses=1]
%tmp.3_OK = add i32 %tmp.2, %offset ; <i32> [#uses=1]
%tmp.5.mask = and i32 %difference, -4 ; <i32> [#uses=1]
; == add %offset, %difference
%tmp.8 = add i32 %tmp.3_OK, %tmp.5.mask ; <i32> [#uses=1]
ret i32 %tmp.8
}
ubyte %test15(ubyte %A) {
%B = add ubyte %A, 192 ; Does not effect result
%C = and ubyte %B, 16 ; Only one bit set
ret ubyte %C
define i8 @test15(i8 %A) {
; Does not effect result
%B = add i8 %A, -64 ; <i8> [#uses=1]
; Only one bit set
%C = and i8 %B, 16 ; <i8> [#uses=1]
ret i8 %C
}
ubyte %test16(ubyte %A) {
%B = add ubyte %A, 16 ; Turn this into a XOR
%C = and ubyte %B, 16 ; Only one bit set
ret ubyte %C
define i8 @test16(i8 %A) {
; Turn this into a XOR
%B = add i8 %A, 16 ; <i8> [#uses=1]
; Only one bit set
%C = and i8 %B, 16 ; <i8> [#uses=1]
ret i8 %C
}
int %test17(int %A) {
%B = xor int %A, -1
%C = add int %B, 1 ; == sub int 0, %A
ret int %C
define i32 @test17(i32 %A) {
%B = xor i32 %A, -1 ; <i32> [#uses=1]
; == sub int 0, %A
%C = add i32 %B, 1 ; <i32> [#uses=1]
ret i32 %C
}
ubyte %test18(ubyte %A) {
%B = xor ubyte %A, 255
%C = add ubyte %B, 17 ; == sub ubyte 16, %A
ret ubyte %C
define i8 @test18(i8 %A) {
%B = xor i8 %A, -1 ; <i8> [#uses=1]
; == sub ubyte 16, %A
%C = add i8 %B, 17 ; <i8> [#uses=1]
ret i8 %C
}
int %test19(bool %C) {
%A = select bool %C, int 1000, int 10
%V = add int %A, 123
ret int %V
define i32 @test19(i1 %C) {
%A = select i1 %C, i32 1000, i32 10 ; <i32> [#uses=1]
%V = add i32 %A, 123 ; <i32> [#uses=1]
ret i32 %V
}
int %test20(int %x) {
%tmp.2 = xor int %x, -2147483648
define i32 @test20(i32 %x) {
%tmp.2 = xor i32 %x, -2147483648 ; <i32> [#uses=1]
;; Add of sign bit -> xor of sign bit.
%tmp.4 = add int %tmp.2, -2147483648
ret int %tmp.4
%tmp.4 = add i32 %tmp.2, -2147483648 ; <i32> [#uses=1]
ret i32 %tmp.4
}
bool %test21(uint %x) {
%t = add uint %x, 4
%y = seteq uint %t, 123
ret bool %y
define i1 @test21(i32 %x) {
%t = add i32 %x, 4 ; <i32> [#uses=1]
%y = icmp eq i32 %t, 123 ; <i1> [#uses=1]
ret i1 %y
}
int %test22(uint %V) {
%V2 = add uint %V, 10
switch uint %V2, label %Default [
uint 20, label %Lab1
uint 30, label %Lab2
]
Default:
ret int 123
Lab1:
ret int 12312
Lab2:
ret int 1231231
define i32 @test22(i32 %V) {
%V2 = add i32 %V, 10 ; <i32> [#uses=1]
switch i32 %V2, label %Default [
i32 20, label %Lab1
i32 30, label %Lab2
]
Default: ; preds = %0
ret i32 123
Lab1: ; preds = %0
ret i32 12312
Lab2: ; preds = %0
ret i32 1231231
}
int %test23(bool %C, int %a) {
define i32 @test23(i1 %C, i32 %a) {
entry:
br bool %C, label %endif, label %else
br i1 %C, label %endif, label %else
else:
else: ; preds = %entry
br label %endif
endif:
%b.0 = phi int [ 0, %entry ], [ 1, %else ]
%tmp.4 = add int %b.0, 1
ret int %tmp.4
endif: ; preds = %else, %entry
%b.0 = phi i32 [ 0, %entry ], [ 1, %else ] ; <i32> [#uses=1]
%tmp.4 = add i32 %b.0, 1 ; <i32> [#uses=1]
ret i32 %tmp.4
}
int %test24(int %A) {
%B = add int %A, 1
%C = shl int %B, ubyte 1
%D = sub int %C, 2
ret int %D ;; A << 1
define i32 @test24(i32 %A) {
%B = add i32 %A, 1 ; <i32> [#uses=1]
%C = shl i32 %B, 1 ; <i32> [#uses=1]
%D = sub i32 %C, 2 ; <i32> [#uses=1]
ret i32 %D
}
long %test25(long %Y) {
%tmp.4 = shl long %Y, ubyte 2
%tmp.12 = shl long %Y, ubyte 2
%tmp.8 = add long %tmp.4, %tmp.12 ;; Y << 3
ret long %tmp.8
define i64 @test25(i64 %Y) {
%tmp.4 = shl i64 %Y, 2 ; <i64> [#uses=1]
%tmp.12 = shl i64 %Y, 2 ; <i64> [#uses=1]
%tmp.8 = add i64 %tmp.4, %tmp.12 ; <i64> [#uses=1]
ret i64 %tmp.8
}
int %test26(int %A, int %B) {
%C = add int %A, %B
%D = sub int %C, %B
ret int %D
define i32 @test26(i32 %A, i32 %B) {
%C = add i32 %A, %B ; <i32> [#uses=1]
%D = sub i32 %C, %B ; <i32> [#uses=1]
ret i32 %D
}
int %test27(bool %C, int %X, int %Y) {
%A = add int %X, %Y
%B = add int %Y, 123
%C = select bool %C, int %A, int %B ;; Fold add through select.
%D = sub int %C, %Y
ret int %D
define i32 @test27(i1 %C, i32 %X, i32 %Y) {
%A = add i32 %X, %Y ; <i32> [#uses=1]
%B = add i32 %Y, 123 ; <i32> [#uses=1]
;; Fold add through select.
%C.upgrd.1 = select i1 %C, i32 %A, i32 %B ; <i32> [#uses=1]
%D = sub i32 %C.upgrd.1, %Y ; <i32> [#uses=1]
ret i32 %D
}
int %test28(int %X) {
%Y = add int %X, 1234
%Z = sub int 42, %Y
ret int %Z
define i32 @test28(i32 %X) {
%Y = add i32 %X, 1234 ; <i32> [#uses=1]
%Z = sub i32 42, %Y ; <i32> [#uses=1]
ret i32 %Z
}
uint %test29(uint %X, uint %x) {
%tmp.2 = sub uint %X, %x
%tmp.2.mask = and uint %tmp.2, 63 ; <uint> [#uses=1]
%tmp.6 = add uint %tmp.2.mask, %x ; <uint> [#uses=1]
%tmp.7 = and uint %tmp.6, 63 ; <uint> [#uses=1]
%tmp.9 = and uint %tmp.2, 4294967232 ; <uint> [#uses=1]
%tmp.10 = or uint %tmp.7, %tmp.9 ; <uint> [#uses=1]
ret uint %tmp.10
define i32 @test29(i32 %X, i32 %x) {
%tmp.2 = sub i32 %X, %x ; <i32> [#uses=2]
%tmp.2.mask = and i32 %tmp.2, 63 ; <i32> [#uses=1]
%tmp.6 = add i32 %tmp.2.mask, %x ; <i32> [#uses=1]
%tmp.7 = and i32 %tmp.6, 63 ; <i32> [#uses=1]
%tmp.9 = and i32 %tmp.2, -64 ; <i32> [#uses=1]
%tmp.10 = or i32 %tmp.7, %tmp.9 ; <i32> [#uses=1]
ret i32 %tmp.10
}
long %test30(long %x) {
%tmp.2 = xor long %x, -9223372036854775808
define i64 @test30(i64 %x) {
%tmp.2 = xor i64 %x, -9223372036854775808 ; <i64> [#uses=1]
;; Add of sign bit -> xor of sign bit.
%tmp.4 = add long %tmp.2, -9223372036854775808
ret long %tmp.4
%tmp.4 = add i64 %tmp.2, -9223372036854775808 ; <i64> [#uses=1]
ret i64 %tmp.4
}
int %test31(int %A) {
%B = add int %A, 4
%C = mul int %B, 5
%D = sub int %C, 20
ret int %D
define i32 @test31(i32 %A) {
%B = add i32 %A, 4 ; <i32> [#uses=1]
%C = mul i32 %B, 5 ; <i32> [#uses=1]
%D = sub i32 %C, 20 ; <i32> [#uses=1]
ret i32 %D
}
int %test32(int %A) {
%B = add int %A, 4
%C = shl int %B, ubyte 2
%D = sub int %C, 16
ret int %D
define i32 @test32(i32 %A) {
%B = add i32 %A, 4 ; <i32> [#uses=1]
%C = shl i32 %B, 2 ; <i32> [#uses=1]
%D = sub i32 %C, 16 ; <i32> [#uses=1]
ret i32 %D
}
ubyte %test33(ubyte %A) { ;; OR A, 1
%B = and ubyte %A, 254
%C = add ubyte %B, 1
ret ubyte %C
define i8 @test33(i8 %A) {
%B = and i8 %A, -2 ; <i8> [#uses=1]
%C = add i8 %B, 1 ; <i8> [#uses=1]
ret i8 %C
}
ubyte %test34(ubyte %A) {
%B = add ubyte %A, 64 ;; dead
%C = and ubyte %B, 12
ret ubyte %C
define i8 @test34(i8 %A) {
%B = add i8 %A, 64 ; <i8> [#uses=1]
%C = and i8 %B, 12 ; <i8> [#uses=1]
ret i8 %C
}
int %test35(int %a) { ;; -> -1
%tmpnot = xor int %a, -1
%tmp2 = add int %tmpnot, %a
ret int %tmp2
define i32 @test35(i32 %a) {
%tmpnot = xor i32 %a, -1 ; <i32> [#uses=1]
%tmp2 = add i32 %tmpnot, %a ; <i32> [#uses=1]
ret i32 %tmp2
}

View File

@ -1,29 +1,31 @@
; Zero byte allocas should be deleted.
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: not grep alloca
; END.
declare void %use(...)
void %test() {
%X = alloca [0 x int]
call void(...)* %use([0 x int] *%X)
%Y = alloca int, uint 0
call void(...)* %use(int* %Y)
%Z = alloca {}
call void(...)* %use({}* %Z)
ret void
declare void @use(...)
define void @test() {
%X = alloca [0 x i32] ; <[0 x i32]*> [#uses=1]
call void (...)* @use( [0 x i32]* %X )
%Y = alloca i32, i32 0 ; <i32*> [#uses=1]
call void (...)* @use( i32* %Y )
%Z = alloca { } ; <{ }*> [#uses=1]
call void (...)* @use( { }* %Z )
ret void
}
void %test2() {
%A = alloca int ;; dead.
store int 123, int* %A
ret void
define void @test2() {
%A = alloca i32 ; <i32*> [#uses=1]
store i32 123, i32* %A
ret void
}
void %test3() {
%A = alloca {int} ;; dead.
%B = getelementptr {int}* %A, int 0, uint 0
store int 123, int* %B
ret void
define void @test3() {
%A = alloca { i32 } ; <{ i32 }*> [#uses=1]
%B = getelementptr { i32 }* %A, i32 0, i32 0 ; <i32*> [#uses=1]
store i32 123, i32* %B
ret void
}

View File

@ -1,11 +1,11 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: grep and | count 1
; Should be optimized to one and.
bool %test1(uint %a, uint %b) {
%tmp1 = and uint %a, 65280
%tmp3 = and uint %b, 65280
%tmp = setne uint %tmp1, %tmp3
ret bool %tmp
define i1 @test1(i32 %a, i32 %b) {
%tmp1 = and i32 %a, 65280 ; <i32> [#uses=1]
%tmp3 = and i32 %b, 65280 ; <i32> [#uses=1]
%tmp = icmp ne i32 %tmp1, %tmp3 ; <i1> [#uses=1]
ret i1 %tmp
}

View File

@ -9,48 +9,53 @@
;
; Which corresponds to test1.
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: not grep {or }
; END.
int %test1(int %X, int %Y) {
%A = and int %X, 7
%B = and int %Y, 8
%C = or int %A, %B
%D = and int %C, 7 ;; This cannot include any bits from %Y!
ret int %D
define i32 @test1(i32 %X, i32 %Y) {
%A = and i32 %X, 7 ; <i32> [#uses=1]
%B = and i32 %Y, 8 ; <i32> [#uses=1]
%C = or i32 %A, %B ; <i32> [#uses=1]
;; This cannot include any bits from %Y!
%D = and i32 %C, 7 ; <i32> [#uses=1]
ret i32 %D
}
int %test2(int %X, ubyte %Y) {
%B = cast ubyte %Y to int
%C = or int %X, %B
%D = and int %C, 65536 ;; This cannot include any bits from %Y!
ret int %D
define i32 @test2(i32 %X, i8 %Y) {
%B = zext i8 %Y to i32 ; <i32> [#uses=1]
%C = or i32 %X, %B ; <i32> [#uses=1]
;; This cannot include any bits from %Y!
%D = and i32 %C, 65536 ; <i32> [#uses=1]
ret i32 %D
}
int %test3(int %X, int %Y) {
%B = shl int %Y, ubyte 1
%C = or int %X, %B
%D = and int %C, 1 ;; This cannot include any bits from %Y!
ret int %D
define i32 @test3(i32 %X, i32 %Y) {
%B = shl i32 %Y, 1 ; <i32> [#uses=1]
%C = or i32 %X, %B ; <i32> [#uses=1]
;; This cannot include any bits from %Y!
%D = and i32 %C, 1 ; <i32> [#uses=1]
ret i32 %D
}
uint %test4(uint %X, uint %Y) {
%B = shr uint %Y, ubyte 31
%C = or uint %X, %B
%D = and uint %C, 2 ;; This cannot include any bits from %Y!
ret uint %D
define i32 @test4(i32 %X, i32 %Y) {
%B = lshr i32 %Y, 31 ; <i32> [#uses=1]
%C = or i32 %X, %B ; <i32> [#uses=1]
;; This cannot include any bits from %Y!
%D = and i32 %C, 2 ; <i32> [#uses=1]
ret i32 %D
}
int %or_test1(int %X, int %Y) {
%A = and int %X, 1
%B = or int %A, 1 ;; This cannot include any bits from X!
ret int %B
define i32 @or_test1(i32 %X, i32 %Y) {
%A = and i32 %X, 1 ; <i32> [#uses=1]
;; This cannot include any bits from X!
%B = or i32 %A, 1 ; <i32> [#uses=1]
ret i32 %B
}
ubyte %or_test2(ubyte %X, ubyte %Y) {
%A = shl ubyte %X, ubyte 7
%B = or ubyte %A, 128 ;; This cannot include any bits from X!
ret ubyte %B
define i8 @or_test2(i8 %X, i8 %Y) {
%A = shl i8 %X, 7 ; <i8> [#uses=1]
;; This cannot include any bits from X!
%B = or i8 %A, -128 ; <i8> [#uses=1]
ret i8 %B
}

View File

@ -1,229 +1,255 @@
; This test makes sure that these instructions are properly eliminated.
;
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep and
; END.
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep and
implementation
int %test1(int %A) {
%B = and int %A, 0 ; zero result
ret int %B
define i32 @test1(i32 %A) {
; zero result
%B = and i32 %A, 0 ; <i32> [#uses=1]
ret i32 %B
}
int %test2(int %A) {
%B = and int %A, -1 ; noop
ret int %B
define i32 @test2(i32 %A) {
; noop
%B = and i32 %A, -1 ; <i32> [#uses=1]
ret i32 %B
}
bool %test3(bool %A) {
%B = and bool %A, false ; always = false
ret bool %B
define i1 @test3(i1 %A) {
; always = false
%B = and i1 %A, false ; <i1> [#uses=1]
ret i1 %B
}
bool %test4(bool %A) {
%B = and bool %A, true ; noop
ret bool %B
define i1 @test4(i1 %A) {
; noop
%B = and i1 %A, true ; <i1> [#uses=1]
ret i1 %B
}
int %test5(int %A) {
%B = and int %A, %A
ret int %B
define i32 @test5(i32 %A) {
%B = and i32 %A, %A ; <i32> [#uses=1]
ret i32 %B
}
bool %test6(bool %A) {
%B = and bool %A, %A
ret bool %B
define i1 @test6(i1 %A) {
%B = and i1 %A, %A ; <i1> [#uses=1]
ret i1 %B
}
int %test7(int %A) { ; A & ~A == 0
%NotA = xor int %A, -1
%B = and int %A, %NotA
ret int %B
; A & ~A == 0
define i32 @test7(i32 %A) {
%NotA = xor i32 %A, -1 ; <i32> [#uses=1]
%B = and i32 %A, %NotA ; <i32> [#uses=1]
ret i32 %B
}
ubyte %test8(ubyte %A) { ; AND associates
%B = and ubyte %A, 3
%C = and ubyte %B, 4
ret ubyte %C
; AND associates
define i8 @test8(i8 %A) {
%B = and i8 %A, 3 ; <i8> [#uses=1]
%C = and i8 %B, 4 ; <i8> [#uses=1]
ret i8 %C
}
bool %test9(int %A) {
%B = and int %A, -2147483648 ; Test of sign bit, convert to setle %A, 0
%C = setne int %B, 0
ret bool %C
define i1 @test9(i32 %A) {
; Test of sign bit, convert to setle %A, 0
%B = and i32 %A, -2147483648 ; <i32> [#uses=1]
%C = icmp ne i32 %B, 0 ; <i1> [#uses=1]
ret i1 %C
}
bool %test9(uint %A) {
%B = and uint %A, 2147483648 ; Test of sign bit, convert to setle %A, 0
%C = setne uint %B, 0
ret bool %C
define i1 @test9a(i32 %A) {
; Test of sign bit, convert to setle %A, 0
%B = and i32 %A, -2147483648 ; <i32> [#uses=1]
%C = icmp ne i32 %B, 0 ; <i1> [#uses=1]
ret i1 %C
}
uint %test10(uint %A) {
%B = and uint %A, 12
%C = xor uint %B, 15
%D = and uint %C, 1 ; (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
ret uint %D
define i32 @test10(i32 %A) {
%B = and i32 %A, 12 ; <i32> [#uses=1]
%C = xor i32 %B, 15 ; <i32> [#uses=1]
; (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
%D = and i32 %C, 1 ; <i32> [#uses=1]
ret i32 %D
}
uint %test11(uint %A, uint* %P) {
%B = or uint %A, 3
%C = xor uint %B, 12
store uint %C, uint* %P ; additional use of C
%D = and uint %C, 3 ; %C = and uint %B, 3 --> 3
ret uint %D
define i32 @test11(i32 %A, i32* %P) {
%B = or i32 %A, 3 ; <i32> [#uses=1]
%C = xor i32 %B, 12 ; <i32> [#uses=2]
; additional use of C
store i32 %C, i32* %P
; %C = and uint %B, 3 --> 3
%D = and i32 %C, 3 ; <i32> [#uses=1]
ret i32 %D
}
bool %test12(uint %A, uint %B) {
%C1 = setlt uint %A, %B
%C2 = setle uint %A, %B
%D = and bool %C1, %C2 ; (A < B) & (A <= B) === (A < B)
ret bool %D
define i1 @test12(i32 %A, i32 %B) {
%C1 = icmp ult i32 %A, %B ; <i1> [#uses=1]
%C2 = icmp ule i32 %A, %B ; <i1> [#uses=1]
; (A < B) & (A <= B) === (A < B)
%D = and i1 %C1, %C2 ; <i1> [#uses=1]
ret i1 %D
}
bool %test13(uint %A, uint %B) {
%C1 = setlt uint %A, %B
%C2 = setgt uint %A, %B
%D = and bool %C1, %C2 ; (A < B) & (A > B) === false
ret bool %D
define i1 @test13(i32 %A, i32 %B) {
%C1 = icmp ult i32 %A, %B ; <i1> [#uses=1]
%C2 = icmp ugt i32 %A, %B ; <i1> [#uses=1]
; (A < B) & (A > B) === false
%D = and i1 %C1, %C2 ; <i1> [#uses=1]
ret i1 %D
}
bool %test14(ubyte %A) {
%B = and ubyte %A, 128
%C = setne ubyte %B, 0
ret bool %C
define i1 @test14(i8 %A) {
%B = and i8 %A, -128 ; <i8> [#uses=1]
%C = icmp ne i8 %B, 0 ; <i1> [#uses=1]
ret i1 %C
}
ubyte %test15(ubyte %A) {
%B = shr ubyte %A, ubyte 7
%C = and ubyte %B, 2 ; Always equals zero
ret ubyte %C
define i8 @test15(i8 %A) {
%B = lshr i8 %A, 7 ; <i8> [#uses=1]
; Always equals zero
%C = and i8 %B, 2 ; <i8> [#uses=1]
ret i8 %C
}
ubyte %test16(ubyte %A) {
%B = shl ubyte %A, ubyte 2
%C = and ubyte %B, 3
ret ubyte %C
define i8 @test16(i8 %A) {
%B = shl i8 %A, 2 ; <i8> [#uses=1]
%C = and i8 %B, 3 ; <i8> [#uses=1]
ret i8 %C
}
sbyte %test17(sbyte %X, sbyte %Y) { ;; ~(~X & Y) --> (X | ~Y)
%B = xor sbyte %X, -1
%C = and sbyte %B, %Y
%D = xor sbyte %C, -1
ret sbyte %D
;; ~(~X & Y) --> (X | ~Y)
define i8 @test17(i8 %X, i8 %Y) {
%B = xor i8 %X, -1 ; <i8> [#uses=1]
%C = and i8 %B, %Y ; <i8> [#uses=1]
%D = xor i8 %C, -1 ; <i8> [#uses=1]
ret i8 %D
}
bool %test18(int %A) {
%B = and int %A, -128
%C = setne int %B, 0 ;; C >= 128
ret bool %C
define i1 @test18(i32 %A) {
%B = and i32 %A, -128 ; <i32> [#uses=1]
;; C >= 128
%C = icmp ne i32 %B, 0 ; <i1> [#uses=1]
ret i1 %C
}
bool %test18a(ubyte %A) {
%B = and ubyte %A, 254
%C = seteq ubyte %B, 0
ret bool %C
define i1 @test18a(i8 %A) {
%B = and i8 %A, -2 ; <i8> [#uses=1]
%C = icmp eq i8 %B, 0 ; <i1> [#uses=1]
ret i1 %C
}
int %test19(int %A) {
%B = shl int %A, ubyte 3
%C = and int %B, -2 ;; Clearing a zero bit
ret int %C
define i32 @test19(i32 %A) {
%B = shl i32 %A, 3 ; <i32> [#uses=1]
;; Clearing a zero bit
%C = and i32 %B, -2 ; <i32> [#uses=1]
ret i32 %C
}
ubyte %test20(ubyte %A) {
%C = shr ubyte %A, ubyte 7
%D = and ubyte %C, 1 ;; Unneeded
ret ubyte %D
define i8 @test20(i8 %A) {
%C = lshr i8 %A, 7 ; <i8> [#uses=1]
;; Unneeded
%D = and i8 %C, 1 ; <i8> [#uses=1]
ret i8 %D
}
bool %test22(int %A) {
%B = seteq int %A, 1
%C = setge int %A, 3
%D = and bool %B, %C ;; False
ret bool %D
define i1 @test22(i32 %A) {
%B = icmp eq i32 %A, 1 ; <i1> [#uses=1]
%C = icmp sge i32 %A, 3 ; <i1> [#uses=1]
;; false
%D = and i1 %B, %C ; <i1> [#uses=1]
ret i1 %D
}
bool %test23(int %A) {
%B = setgt int %A, 1
%C = setle int %A, 2
%D = and bool %B, %C ;; A == 2
ret bool %D
define i1 @test23(i32 %A) {
%B = icmp sgt i32 %A, 1 ; <i1> [#uses=1]
%C = icmp sle i32 %A, 2 ; <i1> [#uses=1]
;; A == 2
%D = and i1 %B, %C ; <i1> [#uses=1]
ret i1 %D
}
bool %test24(int %A) {
%B = setgt int %A, 1
%C = setne int %A, 2
%D = and bool %B, %C ;; A > 2
ret bool %D
define i1 @test24(i32 %A) {
%B = icmp sgt i32 %A, 1 ; <i1> [#uses=1]
%C = icmp ne i32 %A, 2 ; <i1> [#uses=1]
;; A > 2
%D = and i1 %B, %C ; <i1> [#uses=1]
ret i1 %D
}
bool %test25(int %A) {
%B = setge int %A, 50
%C = setlt int %A, 100
%D = and bool %B, %C ;; (A-50) <u 50
ret bool %D
define i1 @test25(i32 %A) {
%B = icmp sge i32 %A, 50 ; <i1> [#uses=1]
%C = icmp slt i32 %A, 100 ; <i1> [#uses=1]
;; (A-50) <u 50
%D = and i1 %B, %C ; <i1> [#uses=1]
ret i1 %D
}
bool %test26(int %A) {
%B = setne int %A, 50
%C = setne int %A, 51
%D = and bool %B, %C ;; (A-50) > 1
ret bool %D
define i1 @test26(i32 %A) {
%B = icmp ne i32 %A, 50 ; <i1> [#uses=1]
%C = icmp ne i32 %A, 51 ; <i1> [#uses=1]
;; (A-50) > 1
%D = and i1 %B, %C ; <i1> [#uses=1]
ret i1 %D
}
ubyte %test27(ubyte %A) {
%B = and ubyte %A, 4
%C = sub ubyte %B, 16
%D = and ubyte %C, 240 ;; 0xF0
%E = add ubyte %D, 16
ret ubyte %E
define i8 @test27(i8 %A) {
%B = and i8 %A, 4 ; <i8> [#uses=1]
%C = sub i8 %B, 16 ; <i8> [#uses=1]
;; 0xF0
%D = and i8 %C, -16 ; <i8> [#uses=1]
%E = add i8 %D, 16 ; <i8> [#uses=1]
ret i8 %E
}
int %test28(int %X) { ;; This is juse a zero extending shr.
%Y = shr int %X, ubyte 24 ;; Sign extend
%Z = and int %Y, 255 ;; Mask out sign bits
ret int %Z
;; This is juse a zero extending shr.
define i32 @test28(i32 %X) {
;; Sign extend
%Y = ashr i32 %X, 24 ; <i32> [#uses=1]
;; Mask out sign bits
%Z = and i32 %Y, 255 ; <i32> [#uses=1]
ret i32 %Z
}
int %test29(ubyte %X) {
%Y = cast ubyte %X to int
%Z = and int %Y, 255 ;; Zero extend makes this unneeded.
ret int %Z
define i32 @test29(i8 %X) {
%Y = zext i8 %X to i32 ; <i32> [#uses=1]
;; Zero extend makes this unneeded.
%Z = and i32 %Y, 255 ; <i32> [#uses=1]
ret i32 %Z
}
int %test30(bool %X) {
%Y = cast bool %X to int
%Z = and int %Y, 1
ret int %Z
define i32 @test30(i1 %X) {
%Y = zext i1 %X to i32 ; <i32> [#uses=1]
%Z = and i32 %Y, 1 ; <i32> [#uses=1]
ret i32 %Z
}
uint %test31(bool %X) {
%Y = cast bool %X to uint
%Z = shl uint %Y, ubyte 4
%A = and uint %Z, 16
ret uint %A
define i32 @test31(i1 %X) {
%Y = zext i1 %X to i32 ; <i32> [#uses=1]
%Z = shl i32 %Y, 4 ; <i32> [#uses=1]
%A = and i32 %Z, 16 ; <i32> [#uses=1]
ret i32 %A
}
uint %test32(uint %In) {
%Y = and uint %In, 16
%Z = shr uint %Y, ubyte 2
%A = and uint %Z, 1
ret uint %A
define i32 @test32(i32 %In) {
%Y = and i32 %In, 16 ; <i32> [#uses=1]
%Z = lshr i32 %Y, 2 ; <i32> [#uses=1]
%A = and i32 %Z, 1 ; <i32> [#uses=1]
ret i32 %A
}
uint %test33(uint %b) { ;; Code corresponding to one-bit bitfield ^1.
%tmp.4.mask = and uint %b, 1
%tmp.10 = xor uint %tmp.4.mask, 1
%tmp.12 = and uint %b, 4294967294
%tmp.13 = or uint %tmp.12, %tmp.10
ret uint %tmp.13
;; Code corresponding to one-bit bitfield ^1.
define i32 @test33(i32 %b) {
%tmp.4.mask = and i32 %b, 1 ; <i32> [#uses=1]
%tmp.10 = xor i32 %tmp.4.mask, 1 ; <i32> [#uses=1]
%tmp.12 = and i32 %b, -2 ; <i32> [#uses=1]
%tmp.13 = or i32 %tmp.12, %tmp.10 ; <i32> [#uses=1]
ret i32 %tmp.13
}
int %test34(int %A, int %B) {
%tmp.2 = or int %B, %A
%tmp.4 = and int %tmp.2, %B
ret int %tmp.4
define i32 @test34(i32 %A, i32 %B) {
%tmp.2 = or i32 %B, %A ; <i32> [#uses=1]
%tmp.4 = and i32 %tmp.2, %B ; <i32> [#uses=1]
ret i32 %tmp.4
}

View File

@ -1,26 +1,26 @@
; This file contains various testcases that require tracking whether bits are
; set or cleared by various instructions.
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -instcombine | llvm-dis |\
; RUN: llvm-as < %s | opt -instcombine -instcombine | llvm-dis |\
; RUN: not grep %ELIM
; Reduce down to a single XOR
int %test3(int %B) {
%ELIMinc = and int %B, 1
%tmp.5 = xor int %ELIMinc, 1
%ELIM7 = and int %B, -2
%tmp.8 = or int %tmp.5, %ELIM7
ret int %tmp.8
define i32 @test3(i32 %B) {
%ELIMinc = and i32 %B, 1 ; <i32> [#uses=1]
%tmp.5 = xor i32 %ELIMinc, 1 ; <i32> [#uses=1]
%ELIM7 = and i32 %B, -2 ; <i32> [#uses=1]
%tmp.8 = or i32 %tmp.5, %ELIM7 ; <i32> [#uses=1]
ret i32 %tmp.8
}
; Finally, a bigger case where we chain things together. This corresponds to
; incrementing a single-bit bitfield, which should become just an xor.
int %test4(int %B) {
%ELIM3 = shl int %B, ubyte 31
%ELIM4 = shr int %ELIM3, ubyte 31
%inc = add int %ELIM4, 1
%ELIM5 = and int %inc, 1
%ELIM7 = and int %B, -2
%tmp.8 = or int %ELIM5, %ELIM7
ret int %tmp.8
define i32 @test4(i32 %B) {
%ELIM3 = shl i32 %B, 31 ; <i32> [#uses=1]
%ELIM4 = ashr i32 %ELIM3, 31 ; <i32> [#uses=1]
%inc = add i32 %ELIM4, 1 ; <i32> [#uses=1]
%ELIM5 = and i32 %inc, 1 ; <i32> [#uses=1]
%ELIM7 = and i32 %B, -2 ; <i32> [#uses=1]
%tmp.8 = or i32 %ELIM5, %ELIM7 ; <i32> [#uses=1]
ret i32 %tmp.8
}

View File

@ -1,29 +1,30 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -simplifycfg | llvm-dis |\
; RUN: llvm-as < %s | opt -instcombine -simplifycfg | llvm-dis |\
; RUN: not grep {call void %abort}
%b_rec.0 = external global int
@b_rec.0 = external global i32 ; <i32*> [#uses=2]
void %_Z12h000007_testv(uint *%P) {
define void @_Z12h000007_testv(i32* %P) {
entry:
%tmp.2 = load int* %b_rec.0 ; <int> [#uses=1]
%tmp.9 = or int %tmp.2, -989855744 ; <int> [#uses=2]
%tmp.16 = and int %tmp.9, -805306369 ; <int> [#uses=2]
%tmp.17 = and int %tmp.9, -973078529 ; <int> [#uses=1]
store int %tmp.17, int* %b_rec.0
%tmp.17.shrunk = cast int %tmp.16 to uint ; <uint> [#uses=1]
%tmp.22 = and uint %tmp.17.shrunk, 3221225472 ; <uint> [#uses=1]
%tmp.23 = seteq uint %tmp.22, 3221225472 ; <bool> [#uses=1]
br bool %tmp.23, label %endif.0, label %then.0
%tmp.2 = load i32* @b_rec.0 ; <i32> [#uses=1]
%tmp.9 = or i32 %tmp.2, -989855744 ; <i32> [#uses=2]
%tmp.16 = and i32 %tmp.9, -805306369 ; <i32> [#uses=2]
%tmp.17 = and i32 %tmp.9, -973078529 ; <i32> [#uses=1]
store i32 %tmp.17, i32* @b_rec.0
%tmp.17.shrunk = bitcast i32 %tmp.16 to i32 ; <i32> [#uses=1]
%tmp.22 = and i32 %tmp.17.shrunk, -1073741824 ; <i32> [#uses=1]
%tmp.23 = icmp eq i32 %tmp.22, -1073741824 ; <i1> [#uses=1]
br i1 %tmp.23, label %endif.0, label %then.0
then.0: ; preds = %entry
tail call void %abort( )
tail call void @abort( )
unreachable
endif.0: ; preds = %entry
%tmp.17.shrunk2 = cast int %tmp.16 to uint ; <uint> [#uses=1]
%tmp.27.mask = and uint %tmp.17.shrunk2, 100663295 ; <uint> [#uses=1]
store uint %tmp.27.mask, uint* %P
%tmp.17.shrunk2 = bitcast i32 %tmp.16 to i32 ; <i32> [#uses=1]
%tmp.27.mask = and i32 %tmp.17.shrunk2, 100663295 ; <i32> [#uses=1]
store i32 %tmp.27.mask, i32* %P
ret void
}
declare void %abort()
declare void @abort()

View File

@ -1,28 +1,29 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: grep ret | count 3
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: not grep call.*bswap
bool %test1(ushort %tmp2) {
%tmp10 = call ushort %llvm.bswap.i16( ushort %tmp2 )
%tmp = seteq ushort %tmp10, 1
ret bool %tmp
define i1 @test1(i16 %tmp2) {
%tmp10 = call i16 @llvm.bswap.i16( i16 %tmp2 ) ; <i16> [#uses=1]
%tmp = icmp eq i16 %tmp10, 1 ; <i1> [#uses=1]
ret i1 %tmp
}
bool %test2(uint %tmp) {
%tmp34 = tail call uint %llvm.bswap.i32( uint %tmp )
%tmp = seteq uint %tmp34, 1
ret bool %tmp
define i1 @test2(i32 %tmp) {
%tmp34 = tail call i32 @llvm.bswap.i32( i32 %tmp ) ; <i32> [#uses=1]
%tmp.upgrd.1 = icmp eq i32 %tmp34, 1 ; <i1> [#uses=1]
ret i1 %tmp.upgrd.1
}
declare uint %llvm.bswap.i32(uint)
declare i32 @llvm.bswap.i32(i32)
bool %test3(ulong %tmp) {
%tmp34 = tail call ulong %llvm.bswap.i64( ulong %tmp )
%tmp = seteq ulong %tmp34, 1
ret bool %tmp
define i1 @test3(i64 %tmp) {
%tmp34 = tail call i64 @llvm.bswap.i64( i64 %tmp ) ; <i64> [#uses=1]
%tmp.upgrd.2 = icmp eq i64 %tmp34, 1 ; <i1> [#uses=1]
ret i1 %tmp.upgrd.2
}
declare ulong %llvm.bswap.i64(ulong)
declare i64 @llvm.bswap.i64(i64)
declare i16 @llvm.bswap.i16(i16)
declare ushort %llvm.bswap.i16(ushort)

View File

@ -1,62 +1,57 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: grep {call.*llvm.bswap} | count 5
; END.
uint %test1(uint %i) {
%tmp1 = shr uint %i, ubyte 24 ; <uint> [#uses=1]
%tmp3 = shr uint %i, ubyte 8 ; <uint> [#uses=1]
%tmp4 = and uint %tmp3, 65280 ; <uint> [#uses=1]
%tmp5 = or uint %tmp1, %tmp4 ; <uint> [#uses=1]
%tmp7 = shl uint %i, ubyte 8 ; <uint> [#uses=1]
%tmp8 = and uint %tmp7, 16711680 ; <uint> [#uses=1]
%tmp9 = or uint %tmp5, %tmp8 ; <uint> [#uses=1]
%tmp11 = shl uint %i, ubyte 24 ; <uint> [#uses=1]
%tmp12 = or uint %tmp9, %tmp11 ; <uint> [#uses=1]
ret uint %tmp12
define i32 @test1(i32 %i) {
%tmp1 = lshr i32 %i, 24 ; <i32> [#uses=1]
%tmp3 = lshr i32 %i, 8 ; <i32> [#uses=1]
%tmp4 = and i32 %tmp3, 65280 ; <i32> [#uses=1]
%tmp5 = or i32 %tmp1, %tmp4 ; <i32> [#uses=1]
%tmp7 = shl i32 %i, 8 ; <i32> [#uses=1]
%tmp8 = and i32 %tmp7, 16711680 ; <i32> [#uses=1]
%tmp9 = or i32 %tmp5, %tmp8 ; <i32> [#uses=1]
%tmp11 = shl i32 %i, 24 ; <i32> [#uses=1]
%tmp12 = or i32 %tmp9, %tmp11 ; <i32> [#uses=1]
ret i32 %tmp12
}
uint %test2(uint %arg) {
%tmp2 = shl uint %arg, ubyte 24 ; <uint> [#uses=1]
%tmp4 = shl uint %arg, ubyte 8 ; <uint> [#uses=1]
%tmp5 = and uint %tmp4, 16711680 ; <uint> [#uses=1]
%tmp6 = or uint %tmp2, %tmp5 ; <uint> [#uses=1]
%tmp8 = shr uint %arg, ubyte 8 ; <uint> [#uses=1]
%tmp9 = and uint %tmp8, 65280 ; <uint> [#uses=1]
%tmp10 = or uint %tmp6, %tmp9 ; <uint> [#uses=1]
%tmp12 = shr uint %arg, ubyte 24 ; <uint> [#uses=1]
%tmp14 = or uint %tmp10, %tmp12 ; <uint> [#uses=1]
ret uint %tmp14
define i32 @test2(i32 %arg) {
%tmp2 = shl i32 %arg, 24 ; <i32> [#uses=1]
%tmp4 = shl i32 %arg, 8 ; <i32> [#uses=1]
%tmp5 = and i32 %tmp4, 16711680 ; <i32> [#uses=1]
%tmp6 = or i32 %tmp2, %tmp5 ; <i32> [#uses=1]
%tmp8 = lshr i32 %arg, 8 ; <i32> [#uses=1]
%tmp9 = and i32 %tmp8, 65280 ; <i32> [#uses=1]
%tmp10 = or i32 %tmp6, %tmp9 ; <i32> [#uses=1]
%tmp12 = lshr i32 %arg, 24 ; <i32> [#uses=1]
%tmp14 = or i32 %tmp10, %tmp12 ; <i32> [#uses=1]
ret i32 %tmp14
}
ushort %test3(ushort %s) {
%tmp2 = shr ushort %s, ubyte 8
%tmp4 = shl ushort %s, ubyte 8
%tmp5 = or ushort %tmp2, %tmp4
ret ushort %tmp5
define i16 @test3(i16 %s) {
%tmp2 = lshr i16 %s, 8 ; <i16> [#uses=1]
%tmp4 = shl i16 %s, 8 ; <i16> [#uses=1]
%tmp5 = or i16 %tmp2, %tmp4 ; <i16> [#uses=1]
ret i16 %tmp5
}
ushort %test4(ushort %s) {
%tmp2 = shr ushort %s, ubyte 8
%tmp4 = shl ushort %s, ubyte 8
%tmp5 = or ushort %tmp4, %tmp2
ret ushort %tmp5
define i16 @test4(i16 %s) {
%tmp2 = lshr i16 %s, 8 ; <i16> [#uses=1]
%tmp4 = shl i16 %s, 8 ; <i16> [#uses=1]
%tmp5 = or i16 %tmp4, %tmp2 ; <i16> [#uses=1]
ret i16 %tmp5
}
; unsigned short test5(unsigned short a) {
; return ((a & 0xff00) >> 8 | (a & 0x00ff) << 8);
;}
ushort %test5(ushort %a) {
%tmp = zext ushort %a to int
%tmp1 = and int %tmp, 65280
%tmp2 = ashr int %tmp1, ubyte 8
%tmp2 = trunc int %tmp2 to short
%tmp4 = and int %tmp, 255
%tmp5 = shl int %tmp4, ubyte 8
%tmp5 = trunc int %tmp5 to short
%tmp = or short %tmp2, %tmp5
%tmp6 = bitcast short %tmp to ushort
%tmp6 = zext ushort %tmp6 to int
%retval = trunc int %tmp6 to ushort
ret ushort %retval
define i16 @test5(i16 %a) {
%tmp = zext i16 %a to i32 ; <i32> [#uses=2]
%tmp1 = and i32 %tmp, 65280 ; <i32> [#uses=1]
%tmp2 = ashr i32 %tmp1, 8 ; <i32> [#uses=1]
%tmp2.upgrd.1 = trunc i32 %tmp2 to i16 ; <i16> [#uses=1]
%tmp4 = and i32 %tmp, 255 ; <i32> [#uses=1]
%tmp5 = shl i32 %tmp4, 8 ; <i32> [#uses=1]
%tmp5.upgrd.2 = trunc i32 %tmp5 to i16 ; <i16> [#uses=1]
%tmp.upgrd.3 = or i16 %tmp2.upgrd.1, %tmp5.upgrd.2 ; <i16> [#uses=1]
%tmp6 = bitcast i16 %tmp.upgrd.3 to i16 ; <i16> [#uses=1]
%tmp6.upgrd.4 = zext i16 %tmp6 to i32 ; <i32> [#uses=1]
%retval = trunc i32 %tmp6.upgrd.4 to i16 ; <i16> [#uses=1]
ret i16 %retval
}

View File

@ -1,16 +1,14 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: grep call | not grep bitcast
target endian = little
target pointersize = 32
target datalayout = "e-p:32:32"
target triple = "i686-pc-linux-gnu"
implementation ; Functions:
int %main() {
define i32 @main() {
entry:
%tmp = call int cast (sbyte* (int*)* %ctime to int (int*)*)( int* null )
ret int %tmp
%tmp = call i32 bitcast (i8* (i32*)* @ctime to i32 (i32*)*)( i32* null ) ; <i32> [#uses=1]
ret i32 %tmp
}
declare sbyte* %ctime(int*)
declare i8* @ctime(i32*)

View File

@ -1,17 +1,19 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis
; RUN: llvm-as < %s | opt -instcombine | llvm-dis
declare void %llvm.memmove.i32(sbyte*, sbyte*, uint, uint)
declare void %llvm.memcpy.i32(sbyte*, sbyte*, uint, uint)
declare void %llvm.memset.i32(sbyte*, ubyte, uint, uint)
@X = global i8 0 ; <i8*> [#uses=3]
@Y = global i8 12 ; <i8*> [#uses=2]
%X = global sbyte 0
%Y = global sbyte 12
declare void @llvm.memmove.i32(i8*, i8*, i32, i32)
void %zero_byte_test() {
; These process zero bytes, so they are a noop.
call void %llvm.memmove.i32(sbyte* %X, sbyte* %Y, uint 0, uint 100)
call void %llvm.memcpy.i32(sbyte* %X, sbyte* %Y, uint 0, uint 100)
call void %llvm.memset.i32(sbyte* %X, ubyte 123, uint 0, uint 100)
ret void
declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)
declare void @llvm.memset.i32(i8*, i8, i32, i32)
define void @zero_byte_test() {
; These process zero bytes, so they are a noop.
call void @llvm.memmove.i32( i8* @X, i8* @Y, i32 0, i32 100 )
call void @llvm.memcpy.i32( i8* @X, i8* @Y, i32 0, i32 100 )
call void @llvm.memset.i32( i8* @X, i8 123, i32 0, i32 100 )
ret void
}

View File

@ -1,28 +1,36 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: not grep {setne\|setle\|setge}
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: not grep {icmp ne\|icmp ule\|icmp uge}
int %test1(uint %X, uint %Y) {
%C = setne uint %X, %Y
br bool %C, label %T, label %F
T:
ret int 12
F:
ret int 123
define i32 @test1(i32 %X, i32 %Y) {
%C = icmp ne i32 %X, %Y ; <i1> [#uses=1]
br i1 %C, label %T, label %F
T: ; preds = %0
ret i32 12
F: ; preds = %0
ret i32 123
}
int %test2(uint %X, uint %Y) {
%C = setle uint %X, %Y
br bool %C, label %T, label %F
T:
ret int 12
F:
ret int 123
define i32 @test2(i32 %X, i32 %Y) {
%C = icmp ule i32 %X, %Y ; <i1> [#uses=1]
br i1 %C, label %T, label %F
T: ; preds = %0
ret i32 12
F: ; preds = %0
ret i32 123
}
int %test3(uint %X, uint %Y) {
%C = setge uint %X, %Y
br bool %C, label %T, label %F
T:
ret int 12
F:
ret int 123
define i32 @test3(i32 %X, i32 %Y) {
%C = icmp uge i32 %X, %Y ; <i1> [#uses=1]
br i1 %C, label %T, label %F
T: ; preds = %0
ret i32 12
F: ; preds = %0
ret i32 123
}

View File

@ -1,16 +1,17 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: not grep bitcast
bool %test1(uint %val) {
%t1 = bitcast uint %val to int
%t2 = and int %t1, 1
%t3 = trunc int %t2 to bool
ret bool %t3
define i1 @test1(i32 %val) {
%t1 = bitcast i32 %val to i32 ; <i32> [#uses=1]
%t2 = and i32 %t1, 1 ; <i32> [#uses=1]
%t3 = trunc i32 %t2 to i1 ; <i1> [#uses=1]
ret i1 %t3
}
short %test1(uint %val) {
%t1 = bitcast uint %val to int
%t2 = and int %t1, 1
%t3 = trunc int %t2 to short
ret short %t3
define i16 @test1.upgrd.1(i32 %val) {
%t1 = bitcast i32 %val to i32 ; <i32> [#uses=1]
%t2 = and i32 %t1, 1 ; <i32> [#uses=1]
%t3 = trunc i32 %t2 to i16 ; <i16> [#uses=1]
ret i16 %t3
}

View File

@ -1,9 +1,9 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: not grep ubyte
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: not grep i8
int %test1(uint %X) {
%Y = cast uint %X to ubyte ;; Turn into an AND
%Z = cast ubyte %Y to int
ret int %Z
define i32 @test1(i32 %X) {
%Y = trunc i32 %X to i8 ; <i8> [#uses=1]
%Z = zext i8 %Y to i32 ; <i32> [#uses=1]
ret i32 %Z
}

View File

@ -1,23 +1,20 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -globaldce | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine -globaldce | llvm-dis | \
; RUN: not grep Array
; Pulling the cast out of the load allows us to eliminate the load, and then
; the whole array.
%unop = type {int }
%op = type {float}
%op = type { float }
%unop = type { i32 }
@Array = internal constant [1 x %op* (%op*)*] [ %op* (%op*)* @foo ] ; <[1 x %op* (%op*)*]*> [#uses=1]
%Array = internal constant [1 x %op* (%op*)*] [ %op* (%op*)* %foo ]
implementation
%op* %foo(%op* %X) {
ret %op* %X
define %op* @foo(%op* %X) {
ret %op* %X
}
%unop* %caller(%op* %O) {
%tmp = load %unop* (%op*)** cast ([1 x %op* (%op*)*]* %Array to %unop* (%op*)**)
%tmp.2 = call %unop* (%op*)* %tmp(%op* %O)
ret %unop* %tmp.2
define %unop* @caller(%op* %O) {
%tmp = load %unop* (%op*)** bitcast ([1 x %op* (%op*)*]* @Array to %unop* (%op*)**); <%unop* (%op*)*> [#uses=1]
%tmp.2 = call %unop* %tmp( %op* %O ) ; <%unop*> [#uses=1]
ret %unop* %tmp.2
}

View File

@ -1,13 +1,15 @@
; test that casted mallocs get converted to malloc of the right type
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: not grep bitcast
; The target datalayout is important for this test case. We have to tell
; instcombine that the ABI alignment for a long is 4-bytes, not 8, otherwise
; it won't do the transform.
target datalayout = "e-i64:32:64"
int* %test(uint %size) {
%X = malloc long, uint %size
%ret = bitcast long* %X to int*
ret int* %ret
define i32* @test(i32 %size) {
%X = malloc i64, i32 %size ; <i64*> [#uses=1]
%ret = bitcast i64* %X to i32* ; <i32*> [#uses=1]
ret i32* %ret
}

View File

@ -1,10 +1,11 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -mem2reg | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine -mem2reg | llvm-dis | \
; RUN: not grep load
int %test1(uint* %P) {
%A = alloca uint
store uint 123, uint* %A
%Q = cast uint* %A to int* ; Cast the result of the load not the source
%V = load int* %Q
ret int %V
define i32 @test1(i32* %P) {
%A = alloca i32 ; <i32*> [#uses=2]
store i32 123, i32* %A
; Cast the result of the load not the source
%Q = bitcast i32* %A to i32* ; <i32*> [#uses=1]
%V = load i32* %Q ; <i32> [#uses=1]
ret i32 %V
}

View File

@ -1,49 +1,51 @@
; This tests for various complex cast elimination cases instcombine should
; handle.
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | notcast
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | notcast
bool %test1(int %X) {
%A = cast int %X to uint
%c = setne uint %A, 12 ; Convert to setne int %X, 12
ret bool %c
define i1 @test1(i32 %X) {
%A = bitcast i32 %X to i32 ; <i32> [#uses=1]
; Convert to setne int %X, 12
%c = icmp ne i32 %A, 12 ; <i1> [#uses=1]
ret i1 %c
}
bool %test2(int %X, int %Y) {
%A = cast int %X to uint
%B = cast int %Y to uint
%c = setne uint %A, %B ; Convert to setne int %X, %Y
ret bool %c
define i1 @test2(i32 %X, i32 %Y) {
%A = bitcast i32 %X to i32 ; <i32> [#uses=1]
%B = bitcast i32 %Y to i32 ; <i32> [#uses=1]
; Convert to setne int %X, %Y
%c = icmp ne i32 %A, %B ; <i1> [#uses=1]
ret i1 %c
}
int %test4(int %A) {
%B = cast int %A to uint
%C = shl uint %B, ubyte 2
%D = cast uint %C to int
ret int %D
define i32 @test4(i32 %A) {
%B = bitcast i32 %A to i32 ; <i32> [#uses=1]
%C = shl i32 %B, 2 ; <i32> [#uses=1]
%D = bitcast i32 %C to i32 ; <i32> [#uses=1]
ret i32 %D
}
short %test5(short %A) {
%B = cast short %A to uint
%C = and uint %B, 15
%D = cast uint %C to short
ret short %D
define i16 @test5(i16 %A) {
%B = sext i16 %A to i32 ; <i32> [#uses=1]
%C = and i32 %B, 15 ; <i32> [#uses=1]
%D = trunc i32 %C to i16 ; <i16> [#uses=1]
ret i16 %D
}
bool %test6(bool %A) {
%B = cast bool %A to int
%C = setne int %B, 0
ret bool %C
define i1 @test6(i1 %A) {
%B = zext i1 %A to i32 ; <i32> [#uses=1]
%C = icmp ne i32 %B, 0 ; <i1> [#uses=1]
ret i1 %C
}
bool %test6a(bool %A) {
%B = cast bool %A to int
%C = setne int %B, -1 ; Always true!
ret bool %C
define i1 @test6a(i1 %A) {
%B = zext i1 %A to i32 ; <i32> [#uses=1]
%C = icmp ne i32 %B, -1 ; <i1> [#uses=1]
ret i1 %C
}
bool %test7(sbyte* %A) {
%B = cast sbyte* %A to int*
%C = seteq int* %B, null
ret bool %C
define i1 @test7(i8* %A) {
%B = bitcast i8* %A to i32* ; <i32*> [#uses=1]
%C = icmp eq i32* %B, null ; <i1> [#uses=1]
ret i1 %C
}

View File

@ -1,20 +1,19 @@
; Tests to make sure elimination of casts is working correctly
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | notcast
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | notcast
target pointersize = 32
target datalayout = "p:32:32"
implementation
sbyte* %test1(sbyte* %t) {
%tmpc = cast sbyte* %t to uint
%tmpa = add uint %tmpc, 32
%tv = cast uint %tmpa to sbyte*
ret sbyte* %tv
define i8* @test1(i8* %t) {
%tmpc = ptrtoint i8* %t to i32 ; <i32> [#uses=1]
%tmpa = add i32 %tmpc, 32 ; <i32> [#uses=1]
%tv = inttoptr i32 %tmpa to i8* ; <i8*> [#uses=1]
ret i8* %tv
}
bool %test2(sbyte* %a, sbyte* %b) {
%tmpa = cast sbyte* %a to uint
%tmpb = cast sbyte* %b to uint
%r = seteq uint %tmpa, %tmpb
ret bool %r
define i1 @test2(i8* %a, i8* %b) {
%tmpa = ptrtoint i8* %a to i32 ; <i32> [#uses=1]
%tmpb = ptrtoint i8* %b to i32 ; <i32> [#uses=1]
%r = icmp eq i32 %tmpa, %tmpb ; <i1> [#uses=1]
ret i1 %r
}

View File

@ -1,14 +1,15 @@
; Test some floating point casting cases
; RUN: llvm-upgrade %s -o - | llvm-as | opt -instcombine | llvm-dis | notcast
; RUN: llvm-upgrade %s -o - | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as %s -o - | opt -instcombine | llvm-dis | notcast
; RUN: llvm-as %s -o - | opt -instcombine | llvm-dis | \
; RUN: egrep {ret i8 \(-1\)\|\(255\)}
sbyte %test1() {
%x = fptoui float 255.0 to sbyte
ret sbyte %x
define i8 @test1() {
%x = fptoui float 2.550000e+02 to i8 ; <i8> [#uses=1]
ret i8 %x
}
ubyte %test2() {
%x = fptosi float -1.0 to ubyte
ret ubyte %x
define i8 @test2() {
%x = fptosi float -1.000000e+00 to i8 ; <i8> [#uses=1]
ret i8 %x
}

View File

@ -1,34 +1,31 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: not grep getelementptr
; END.
bool %test1(short* %P, int %I, int %J) {
%X = getelementptr short* %P, int %I
%Y = getelementptr short* %P, int %J
%C = setlt short* %X, %Y
ret bool %C
define i1 @test1(i16* %P, i32 %I, i32 %J) {
%X = getelementptr i16* %P, i32 %I ; <i16*> [#uses=1]
%Y = getelementptr i16* %P, i32 %J ; <i16*> [#uses=1]
%C = icmp ult i16* %X, %Y ; <i1> [#uses=1]
ret i1 %C
}
bool %test2(short* %P, int %I) {
%X = getelementptr short* %P, int %I
%C = setlt short* %X, %P
ret bool %C
define i1 @test2(i16* %P, i32 %I) {
%X = getelementptr i16* %P, i32 %I ; <i16*> [#uses=1]
%C = icmp ult i16* %X, %P ; <i1> [#uses=1]
ret i1 %C
}
int %test3(int* %P, int %A, int %B) {
%tmp.4 = getelementptr int* %P, int %A ; <int*> [#uses=1]
%tmp.9 = getelementptr int* %P, int %B ; <int*> [#uses=1]
%tmp.10 = seteq int* %tmp.4, %tmp.9 ; <bool> [#uses=1]
%tmp.11 = cast bool %tmp.10 to int ; <int> [#uses=1]
ret int %tmp.11
define i32 @test3(i32* %P, i32 %A, i32 %B) {
%tmp.4 = getelementptr i32* %P, i32 %A ; <i32*> [#uses=1]
%tmp.9 = getelementptr i32* %P, i32 %B ; <i32*> [#uses=1]
%tmp.10 = icmp eq i32* %tmp.4, %tmp.9 ; <i1> [#uses=1]
%tmp.11 = zext i1 %tmp.10 to i32 ; <i32> [#uses=1]
ret i32 %tmp.11
}
int %test4(int* %P, int %A, int %B) {
%tmp.4 = getelementptr int* %P, int %A ; <int*> [#uses=1]
%tmp.6 = seteq int* %tmp.4, %P ; <bool> [#uses=1]
%tmp.7 = cast bool %tmp.6 to int ; <int> [#uses=1]
ret int %tmp.7
define i32 @test4(i32* %P, i32 %A, i32 %B) {
%tmp.4 = getelementptr i32* %P, i32 %A ; <i32*> [#uses=1]
%tmp.6 = icmp eq i32* %tmp.4, %P ; <i1> [#uses=1]
%tmp.7 = zext i1 %tmp.6 to i32 ; <i32> [#uses=1]
ret i32 %tmp.7
}

View File

@ -1,11 +1,11 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: notcast {} {getelementptr.*}
%G = external global [3 x sbyte]
@G = external global [3 x i8] ; <[3 x i8]*> [#uses=1]
implementation
ubyte *%foo(uint %Idx) {
%tmp = getelementptr ubyte* cast ([3 x sbyte]* %G to ubyte*), uint %Idx
ret ubyte* %tmp
define i8* @foo(i32 %Idx) {
%gep.upgrd.1 = zext i32 %Idx to i64 ; <i64> [#uses=1]
%tmp = getelementptr i8* getelementptr ([3 x i8]* @G, i32 0, i32 0), i64 %gep.upgrd.1 ; <i8*> [#uses=1]
ret i8* %tmp
}

View File

@ -1,14 +1,15 @@
; Test folding of constantexpr geps into normal geps.
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -gcse -instcombine | \
; RUN: llvm-as < %s | opt -instcombine -gcse -instcombine | \
; RUN: llvm-dis | not grep getelementptr
%Array = external global [40 x int]
@Array = external global [40 x i32] ; <[40 x i32]*> [#uses=2]
int %test(long %X) {
%A = getelementptr int* getelementptr ([40 x int]* %Array, long 0, long 0), long %X
%B = getelementptr [40 x int]* %Array, long 0, long %X
%a = cast int* %A to int
%b = cast int* %B to int
%c = sub int %a, %b
ret int %c
define i32 @test(i64 %X) {
%A = getelementptr i32* getelementptr ([40 x i32]* @Array, i64 0, i64 0), i64 %X ; <i32*> [#uses=1]
%B = getelementptr [40 x i32]* @Array, i64 0, i64 %X ; <i32*> [#uses=1]
%a = ptrtoint i32* %A to i32 ; <i32> [#uses=1]
%b = ptrtoint i32* %B to i32 ; <i32> [#uses=1]
%c = sub i32 %a, %b ; <i32> [#uses=1]
ret i32 %c
}

View File

@ -1,10 +1,9 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep trunc
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep trunc
target endian = little
target pointersize = 32
target datalayout = "e-p:32:32"
int* %test(int* %X, long %Idx) {
; Should insert a cast to int on this target
%R = getelementptr int* %X, long %Idx
ret int* %R
define i32* @test(i32* %X, i64 %Idx) {
%R = getelementptr i32* %X, i64 %Idx ; <i32*> [#uses=1]
ret i32* %R
}

View File

@ -1,17 +1,17 @@
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: %prcontext div 1 | grep then:
;; This tests that the div is hoisted into the then block.
int %foo(bool %C, int %A, int %B) {
define i32 @foo(i1 %C, i32 %A, i32 %B) {
entry:
br bool %C, label %then, label %endif
br i1 %C, label %then, label %endif
then:
br label %endif
then: ; preds = %entry
br label %endif
endif:
%X = phi int [%A, %then], [15, %entry]
%Y = div int %X, 42
ret int %Y
endif: ; preds = %then, %entry
%X = phi i32 [ %A, %then ], [ 15, %entry ] ; <i32> [#uses=1]
%Y = sdiv i32 %X, 42 ; <i32> [#uses=1]
ret i32 %Y
}

View File

@ -1,6 +1,7 @@
; This test makes sure that these instructions are properly eliminated.
;
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep icmp
; END.
@X = external global i32 ; <i32*> [#uses=2]

View File

@ -3,6 +3,7 @@
; been when a setcc is used with two casts.
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: not grep {br bool false}
; END.
define i32 @bug(i8 %inbuff) {
entry:

View File

@ -4,7 +4,7 @@
;
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: grep -v {icmp eq} | grep -v {icmp ne} | not grep icmp
; END.
define i1 @test1(i32 %A) {
; setne %A, 0

View File

@ -1,6 +1,7 @@
; This test makes sure that these instructions are properly eliminated.
;
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep sh
; END.
define i32 @test1(i32 %A) {
%B = shl i32 %A, 0 ; <i32> [#uses=1]

View File

@ -1,5 +1,6 @@
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: not grep {(and\|xor\|add\|shl\|shr)}
; END.
define i32 @test1(i32 %x) {
%tmp.1 = and i32 %x, 65535 ; <i32> [#uses=1]

View File

@ -4,6 +4,7 @@
; RUN: not grep insertelement
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: not grep extractelement
; END.
define <4 x float> @test(<4 x float> %tmp, <4 x float> %tmp1) {
%tmp4 = extractelement <4 x float> %tmp, i32 1 ; <float> [#uses=1]

View File

@ -2,6 +2,7 @@
;
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
; RUN: not grep {xor }
; END.
@G1 = global i32 0 ; <i32*> [#uses=1]
@G2 = global i32 0 ; <i32*> [#uses=1]