2009-11-26 10:17:34 +08:00
|
|
|
; RUN: opt < %s -gvn -instcombine -S |& FileCheck %s
|
2008-12-10 09:04:47 +08:00
|
|
|
; Make sure that basicaa thinks R and r are must aliases.
|
|
|
|
|
2009-11-26 10:17:34 +08:00
|
|
|
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
|
|
|
|
|
|
|
|
define i32 @test1(i8 * %P) {
|
2008-12-10 09:04:47 +08:00
|
|
|
entry:
|
|
|
|
%Q = bitcast i8* %P to {i32, i32}*
|
|
|
|
%R = getelementptr {i32, i32}* %Q, i32 0, i32 1
|
|
|
|
%S = load i32* %R
|
|
|
|
|
|
|
|
%q = bitcast i8* %P to {i32, i32}*
|
|
|
|
%r = getelementptr {i32, i32}* %q, i32 0, i32 1
|
|
|
|
%s = load i32* %r
|
|
|
|
|
|
|
|
%t = sub i32 %S, %s
|
|
|
|
ret i32 %t
|
2009-11-26 10:17:34 +08:00
|
|
|
; CHECK: @test1
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
|
|
|
|
|
|
|
define i32 @test2(i8 * %P) {
|
|
|
|
entry:
|
|
|
|
%Q = bitcast i8* %P to {i32, i32, i32}*
|
|
|
|
%R = getelementptr {i32, i32, i32}* %Q, i32 0, i32 1
|
|
|
|
%S = load i32* %R
|
|
|
|
|
|
|
|
%r = getelementptr {i32, i32, i32}* %Q, i32 0, i32 2
|
|
|
|
store i32 42, i32* %r
|
|
|
|
|
|
|
|
%s = load i32* %R
|
|
|
|
|
|
|
|
%t = sub i32 %S, %s
|
|
|
|
ret i32 %t
|
|
|
|
; CHECK: @test2
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
; This was a miscompilation.
|
|
|
|
define i32 @test3({float, {i32, i32, i32}}* %P) {
|
|
|
|
entry:
|
|
|
|
%P2 = getelementptr {float, {i32, i32, i32}}* %P, i32 0, i32 1
|
|
|
|
%R = getelementptr {i32, i32, i32}* %P2, i32 0, i32 1
|
|
|
|
%S = load i32* %R
|
|
|
|
|
|
|
|
%r = getelementptr {i32, i32, i32}* %P2, i32 0, i32 2
|
|
|
|
store i32 42, i32* %r
|
|
|
|
|
|
|
|
%s = load i32* %R
|
|
|
|
|
|
|
|
%t = sub i32 %S, %s
|
|
|
|
ret i32 %t
|
|
|
|
; CHECK: @test3
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
;; This is reduced from the SmallPtrSet constructor.
|
|
|
|
%SmallPtrSetImpl = type { i8**, i32, i32, i32, [1 x i8*] }
|
|
|
|
%SmallPtrSet64 = type { %SmallPtrSetImpl, [64 x i8*] }
|
|
|
|
|
|
|
|
define i32 @test4(%SmallPtrSet64* %P) {
|
|
|
|
entry:
|
|
|
|
%tmp2 = getelementptr inbounds %SmallPtrSet64* %P, i64 0, i32 0, i32 1
|
|
|
|
store i32 64, i32* %tmp2, align 8
|
|
|
|
%tmp3 = getelementptr inbounds %SmallPtrSet64* %P, i64 0, i32 0, i32 4, i64 64
|
|
|
|
store i8* null, i8** %tmp3, align 8
|
|
|
|
%tmp4 = load i32* %tmp2, align 8
|
|
|
|
ret i32 %tmp4
|
|
|
|
; CHECK: @test4
|
|
|
|
; CHECK: ret i32 64
|
2008-12-10 09:04:47 +08:00
|
|
|
}
|
2009-11-27 00:18:10 +08:00
|
|
|
|
|
|
|
; P[i] != p[i+1]
|
|
|
|
define i32 @test5(i32* %p, i64 %i) {
|
|
|
|
%pi = getelementptr i32* %p, i64 %i
|
|
|
|
%i.next = add i64 %i, 1
|
|
|
|
%pi.next = getelementptr i32* %p, i64 %i.next
|
|
|
|
%x = load i32* %pi
|
|
|
|
store i32 42, i32* %pi.next
|
|
|
|
%y = load i32* %pi
|
|
|
|
%z = sub i32 %x, %y
|
|
|
|
ret i32 %z
|
|
|
|
; CHECK: @test5
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
|
|
|
|
Teach basicaa that x|c == x+c when the c bits of x are clear. This
allows us to compile the example in readme.txt into:
LBB1_1: ## %bb
movl 4(%rdx,%rax), %ecx
movl %ecx, %esi
imull (%rdx,%rax), %esi
imull %esi, %ecx
movl %esi, 8(%rdx,%rax)
imull %ecx, %esi
movl %ecx, 12(%rdx,%rax)
movl %esi, 16(%rdx,%rax)
imull %ecx, %esi
movl %esi, 20(%rdx,%rax)
addq $16, %rax
cmpq $4000, %rax
jne LBB1_1
instead of:
LBB1_1:
movl (%rdx,%rax), %ecx
imull 4(%rdx,%rax), %ecx
movl %ecx, 8(%rdx,%rax)
imull 4(%rdx,%rax), %ecx
movl %ecx, 12(%rdx,%rax)
imull 8(%rdx,%rax), %ecx
movl %ecx, 16(%rdx,%rax)
imull 12(%rdx,%rax), %ecx
movl %ecx, 20(%rdx,%rax)
addq $16, %rax
cmpq $4000, %rax
jne LBB1_1
GCC (4.2) doesn't seem to be able to eliminate the loads in this
testcase either, it generates:
L2:
movl (%rdx), %eax
imull 4(%rdx), %eax
movl %eax, 8(%rdx)
imull 4(%rdx), %eax
movl %eax, 12(%rdx)
imull 8(%rdx), %eax
movl %eax, 16(%rdx)
imull 12(%rdx), %eax
movl %eax, 20(%rdx)
addl $4, %ecx
addq $16, %rdx
cmpl $1002, %ecx
jne L2
llvm-svn: 89952
2009-11-27 00:26:43 +08:00
|
|
|
; P[i] != p[(i*4)|1]
|
|
|
|
define i32 @test6(i32* %p, i64 %i1) {
|
|
|
|
%i = shl i64 %i1, 2
|
|
|
|
%pi = getelementptr i32* %p, i64 %i
|
|
|
|
%i.next = or i64 %i, 1
|
|
|
|
%pi.next = getelementptr i32* %p, i64 %i.next
|
|
|
|
%x = load i32* %pi
|
|
|
|
store i32 42, i32* %pi.next
|
|
|
|
%y = load i32* %pi
|
|
|
|
%z = sub i32 %x, %y
|
|
|
|
ret i32 %z
|
|
|
|
; CHECK: @test6
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
2009-11-27 00:18:10 +08:00
|
|
|
|
2009-11-27 01:00:01 +08:00
|
|
|
; P[1] != P[i*4]
|
|
|
|
define i32 @test7(i32* %p, i64 %i) {
|
|
|
|
%pi = getelementptr i32* %p, i64 1
|
|
|
|
%i.next = shl i64 %i, 2
|
|
|
|
%pi.next = getelementptr i32* %p, i64 %i.next
|
|
|
|
%x = load i32* %pi
|
|
|
|
store i32 42, i32* %pi.next
|
|
|
|
%y = load i32* %pi
|
|
|
|
%z = sub i32 %x, %y
|
|
|
|
ret i32 %z
|
|
|
|
; CHECK: @test7
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|
|
|
|
|
2009-11-27 02:53:33 +08:00
|
|
|
; P[zext(i)] != p[zext(i+1)]
|
|
|
|
; PR1143
|
|
|
|
define i32 @test8(i32* %p, i32 %i) {
|
|
|
|
%i1 = zext i32 %i to i64
|
|
|
|
%pi = getelementptr i32* %p, i64 %i1
|
|
|
|
%i.next = add i32 %i, 1
|
|
|
|
%i.next2 = zext i32 %i.next to i64
|
|
|
|
%pi.next = getelementptr i32* %p, i64 %i.next2
|
|
|
|
%x = load i32* %pi
|
|
|
|
store i32 42, i32* %pi.next
|
|
|
|
%y = load i32* %pi
|
|
|
|
%z = sub i32 %x, %y
|
|
|
|
ret i32 %z
|
|
|
|
; CHECK: @test8
|
|
|
|
; CHECK: ret i32 0
|
|
|
|
}
|