mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-15 07:34:33 +00:00
6cdf2ea98e
gep to explicit addressing, we know that none of the intermediate computation overflows. This could use review: it seems that the shifts certainly wouldn't overflow, but could the intermediate adds overflow if there is a negative index? Previously the testcase would instcombine to: define i1 @test(i64 %i) { %p1.idx.mask = and i64 %i, 4611686018427387903 %cmp = icmp eq i64 %p1.idx.mask, 1000 ret i1 %cmp } now we get: define i1 @test(i64 %i) { %cmp = icmp eq i64 %i, 1000 ret i1 %cmp } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125271 91177308-0d34-0410-b5e6-96231b3b80d8
237 lines
4.8 KiB
LLVM
237 lines
4.8 KiB
LLVM
; RUN: opt < %s -instcombine -S | 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-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
|
|
|
|
define i32 @test1(i32 %X) {
|
|
entry:
|
|
icmp slt i32 %X, 0 ; <i1>:0 [#uses=1]
|
|
zext i1 %0 to i32 ; <i32>:1 [#uses=1]
|
|
ret i32 %1
|
|
; CHECK: @test1
|
|
; CHECK: lshr i32 %X, 31
|
|
; CHECK-NEXT: ret i32
|
|
}
|
|
|
|
define i32 @test2(i32 %X) {
|
|
entry:
|
|
icmp ult i32 %X, -2147483648 ; <i1>:0 [#uses=1]
|
|
zext i1 %0 to i32 ; <i32>:1 [#uses=1]
|
|
ret i32 %1
|
|
; CHECK: @test2
|
|
; CHECK: lshr i32 %X, 31
|
|
; CHECK-NEXT: xor i32
|
|
; CHECK-NEXT: ret i32
|
|
}
|
|
|
|
define i32 @test3(i32 %X) {
|
|
entry:
|
|
icmp slt i32 %X, 0 ; <i1>:0 [#uses=1]
|
|
sext i1 %0 to i32 ; <i32>:1 [#uses=1]
|
|
ret i32 %1
|
|
; CHECK: @test3
|
|
; CHECK: ashr i32 %X, 31
|
|
; CHECK-NEXT: ret i32
|
|
}
|
|
|
|
define i32 @test4(i32 %X) {
|
|
entry:
|
|
icmp ult i32 %X, -2147483648 ; <i1>:0 [#uses=1]
|
|
sext i1 %0 to i32 ; <i32>:1 [#uses=1]
|
|
ret i32 %1
|
|
; CHECK: @test4
|
|
; CHECK: ashr i32 %X, 31
|
|
; CHECK-NEXT: xor i32
|
|
; CHECK-NEXT: ret i32
|
|
}
|
|
|
|
; PR4837
|
|
define <2 x i1> @test5(<2 x i64> %x) {
|
|
entry:
|
|
%V = icmp eq <2 x i64> %x, undef
|
|
ret <2 x i1> %V
|
|
; CHECK: @test5
|
|
; CHECK: ret <2 x i1> <i1 true, i1 true>
|
|
}
|
|
|
|
define i32 @test6(i32 %a, i32 %b) {
|
|
%c = icmp sle i32 %a, -1
|
|
%d = zext i1 %c to i32
|
|
%e = sub i32 0, %d
|
|
%f = and i32 %e, %b
|
|
ret i32 %f
|
|
; CHECK: @test6
|
|
; CHECK-NEXT: ashr i32 %a, 31
|
|
; CHECK-NEXT: %f = and i32 %e, %b
|
|
; CHECK-NEXT: ret i32 %f
|
|
}
|
|
|
|
|
|
define i1 @test7(i32 %x) {
|
|
entry:
|
|
%a = add i32 %x, -1
|
|
%b = icmp ult i32 %a, %x
|
|
ret i1 %b
|
|
; CHECK: @test7
|
|
; CHECK: %b = icmp ne i32 %x, 0
|
|
; CHECK: ret i1 %b
|
|
}
|
|
|
|
define i1 @test8(i32 %x){
|
|
entry:
|
|
%a = add i32 %x, -1
|
|
%b = icmp eq i32 %a, %x
|
|
ret i1 %b
|
|
; CHECK: @test8
|
|
; CHECK: ret i1 false
|
|
}
|
|
|
|
define i1 @test9(i32 %x) {
|
|
entry:
|
|
%a = add i32 %x, -2
|
|
%b = icmp ugt i32 %x, %a
|
|
ret i1 %b
|
|
; CHECK: @test9
|
|
; CHECK: icmp ugt i32 %x, 1
|
|
; CHECK: ret i1 %b
|
|
}
|
|
|
|
define i1 @test10(i32 %x){
|
|
entry:
|
|
%a = add i32 %x, -1
|
|
%b = icmp slt i32 %a, %x
|
|
ret i1 %b
|
|
|
|
; CHECK: @test10
|
|
; CHECK: %b = icmp ne i32 %x, -2147483648
|
|
; CHECK: ret i1 %b
|
|
}
|
|
|
|
define i1 @test11(i32 %x) {
|
|
%a = add nsw i32 %x, 8
|
|
%b = icmp slt i32 %x, %a
|
|
ret i1 %b
|
|
; CHECK: @test11
|
|
; CHECK: ret i1 true
|
|
}
|
|
|
|
; PR6195
|
|
define i1 @test12(i1 %A) {
|
|
%S = select i1 %A, i64 -4294967295, i64 8589934591
|
|
%B = icmp ne i64 bitcast (<2 x i32> <i32 1, i32 -1> to i64), %S
|
|
ret i1 %B
|
|
; CHECK: @test12
|
|
; CHECK-NEXT: %B = select i1
|
|
; CHECK-NEXT: ret i1 %B
|
|
}
|
|
|
|
; PR6481
|
|
define i1 @test13(i8 %X) nounwind readnone {
|
|
entry:
|
|
%cmp = icmp slt i8 undef, %X
|
|
ret i1 %cmp
|
|
; CHECK: @test13
|
|
; CHECK: ret i1 false
|
|
}
|
|
|
|
define i1 @test14(i8 %X) nounwind readnone {
|
|
entry:
|
|
%cmp = icmp slt i8 undef, -128
|
|
ret i1 %cmp
|
|
; CHECK: @test14
|
|
; CHECK: ret i1 false
|
|
}
|
|
|
|
define i1 @test15() nounwind readnone {
|
|
entry:
|
|
%cmp = icmp eq i8 undef, -128
|
|
ret i1 %cmp
|
|
; CHECK: @test15
|
|
; CHECK: ret i1 undef
|
|
}
|
|
|
|
define i1 @test16() nounwind readnone {
|
|
entry:
|
|
%cmp = icmp ne i8 undef, -128
|
|
ret i1 %cmp
|
|
; CHECK: @test16
|
|
; CHECK: ret i1 undef
|
|
}
|
|
|
|
define i1 @test17(i32 %x) nounwind {
|
|
%shl = shl i32 1, %x
|
|
%and = and i32 %shl, 8
|
|
%cmp = icmp eq i32 %and, 0
|
|
ret i1 %cmp
|
|
; CHECK: @test17
|
|
; CHECK-NEXT: %cmp = icmp ne i32 %x, 3
|
|
}
|
|
|
|
|
|
define i1 @test18(i32 %x) nounwind {
|
|
%sh = lshr i32 8, %x
|
|
%and = and i32 %sh, 1
|
|
%cmp = icmp eq i32 %and, 0
|
|
ret i1 %cmp
|
|
; CHECK: @test18
|
|
; CHECK-NEXT: %cmp = icmp ne i32 %x, 3
|
|
}
|
|
|
|
define i1 @test19(i32 %x) nounwind {
|
|
%shl = shl i32 1, %x
|
|
%and = and i32 %shl, 8
|
|
%cmp = icmp eq i32 %and, 8
|
|
ret i1 %cmp
|
|
; CHECK: @test19
|
|
; CHECK-NEXT: %cmp = icmp eq i32 %x, 3
|
|
}
|
|
|
|
define i1 @test20(i32 %x) nounwind {
|
|
%shl = shl i32 1, %x
|
|
%and = and i32 %shl, 8
|
|
%cmp = icmp ne i32 %and, 0
|
|
ret i1 %cmp
|
|
; CHECK: @test20
|
|
; CHECK-NEXT: %cmp = icmp eq i32 %x, 3
|
|
}
|
|
|
|
define i1 @test21(i8 %x, i8 %y) {
|
|
; CHECK: @test21
|
|
; CHECK-NOT: or i8
|
|
; CHECK: icmp ugt
|
|
%A = or i8 %x, 1
|
|
%B = icmp ugt i8 %A, 3
|
|
ret i1 %B
|
|
}
|
|
|
|
define i1 @test22(i8 %x, i8 %y) {
|
|
; CHECK: @test22
|
|
; CHECK-NOT: or i8
|
|
; CHECK: icmp ult
|
|
%A = or i8 %x, 1
|
|
%B = icmp ult i8 %A, 4
|
|
ret i1 %B
|
|
}
|
|
|
|
; PR2740
|
|
; CHECK: @test23
|
|
; CHECK: icmp sgt i32 %x, 1328634634
|
|
define i1 @test23(i32 %x) nounwind {
|
|
%i3 = sdiv i32 %x, -1328634635
|
|
%i4 = icmp eq i32 %i3, -1
|
|
ret i1 %i4
|
|
}
|
|
|
|
@X = global [1000 x i32] zeroinitializer
|
|
|
|
; PR8882
|
|
; CHECK: @test24
|
|
; CHECK: %cmp = icmp eq i64 %i, 1000
|
|
; CHECK: ret i1 %cmp
|
|
define i1 @test24(i64 %i) {
|
|
%p1 = getelementptr inbounds i32* getelementptr inbounds ([1000 x i32]* @X, i64 0, i64 0), i64 %i
|
|
%cmp = icmp eq i32* %p1, getelementptr inbounds ([1000 x i32]* @X, i64 1, i64 0)
|
|
ret i1 %cmp
|
|
}
|
|
|