mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
10e28ca6b1
Try to convert two compares of a signed range check into a single unsigned compare. Examples: (icmp sge x, 0) & (icmp slt x, n) --> icmp ult x, n (icmp slt x, 0) | (icmp sgt x, n) --> icmp ugt x, n git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223224 91177308-0d34-0410-b5e6-96231b3b80d8
160 lines
3.7 KiB
LLVM
160 lines
3.7 KiB
LLVM
; RUN: opt < %s -instcombine -S | FileCheck %s
|
|
|
|
; Check simplification of
|
|
; (icmp sgt x, -1) & (icmp sgt/sge n, x) --> icmp ugt/uge n, x
|
|
|
|
; CHECK-LABEL: define i1 @test_and1
|
|
; CHECK: [[R:%[0-9]+]] = icmp ugt i32 %nn, %x
|
|
; CHECK: ret i1 [[R]]
|
|
define i1 @test_and1(i32 %x, i32 %n) {
|
|
%nn = and i32 %n, 2147483647
|
|
%a = icmp sge i32 %x, 0
|
|
%b = icmp slt i32 %x, %nn
|
|
%c = and i1 %a, %b
|
|
ret i1 %c
|
|
}
|
|
|
|
; CHECK-LABEL: define i1 @test_and2
|
|
; CHECK: [[R:%[0-9]+]] = icmp uge i32 %nn, %x
|
|
; CHECK: ret i1 [[R]]
|
|
define i1 @test_and2(i32 %x, i32 %n) {
|
|
%nn = and i32 %n, 2147483647
|
|
%a = icmp sgt i32 %x, -1
|
|
%b = icmp sle i32 %x, %nn
|
|
%c = and i1 %a, %b
|
|
ret i1 %c
|
|
}
|
|
|
|
; CHECK-LABEL: define i1 @test_and3
|
|
; CHECK: [[R:%[0-9]+]] = icmp ugt i32 %nn, %x
|
|
; CHECK: ret i1 [[R]]
|
|
define i1 @test_and3(i32 %x, i32 %n) {
|
|
%nn = and i32 %n, 2147483647
|
|
%a = icmp sgt i32 %nn, %x
|
|
%b = icmp sge i32 %x, 0
|
|
%c = and i1 %a, %b
|
|
ret i1 %c
|
|
}
|
|
|
|
; CHECK-LABEL: define i1 @test_and4
|
|
; CHECK: [[R:%[0-9]+]] = icmp uge i32 %nn, %x
|
|
; CHECK: ret i1 [[R]]
|
|
define i1 @test_and4(i32 %x, i32 %n) {
|
|
%nn = and i32 %n, 2147483647
|
|
%a = icmp sge i32 %nn, %x
|
|
%b = icmp sge i32 %x, 0
|
|
%c = and i1 %a, %b
|
|
ret i1 %c
|
|
}
|
|
|
|
; CHECK-LABEL: define i1 @test_or1
|
|
; CHECK: [[R:%[0-9]+]] = icmp ule i32 %nn, %x
|
|
; CHECK: ret i1 [[R]]
|
|
define i1 @test_or1(i32 %x, i32 %n) {
|
|
%nn = and i32 %n, 2147483647
|
|
%a = icmp slt i32 %x, 0
|
|
%b = icmp sge i32 %x, %nn
|
|
%c = or i1 %a, %b
|
|
ret i1 %c
|
|
}
|
|
|
|
; CHECK-LABEL: define i1 @test_or2
|
|
; CHECK: [[R:%[0-9]+]] = icmp ult i32 %nn, %x
|
|
; CHECK: ret i1 [[R]]
|
|
define i1 @test_or2(i32 %x, i32 %n) {
|
|
%nn = and i32 %n, 2147483647
|
|
%a = icmp sle i32 %x, -1
|
|
%b = icmp sgt i32 %x, %nn
|
|
%c = or i1 %a, %b
|
|
ret i1 %c
|
|
}
|
|
|
|
; CHECK-LABEL: define i1 @test_or3
|
|
; CHECK: [[R:%[0-9]+]] = icmp ule i32 %nn, %x
|
|
; CHECK: ret i1 [[R]]
|
|
define i1 @test_or3(i32 %x, i32 %n) {
|
|
%nn = and i32 %n, 2147483647
|
|
%a = icmp sle i32 %nn, %x
|
|
%b = icmp slt i32 %x, 0
|
|
%c = or i1 %a, %b
|
|
ret i1 %c
|
|
}
|
|
|
|
; CHECK-LABEL: define i1 @test_or4
|
|
; CHECK: [[R:%[0-9]+]] = icmp ult i32 %nn, %x
|
|
; CHECK: ret i1 [[R]]
|
|
define i1 @test_or4(i32 %x, i32 %n) {
|
|
%nn = and i32 %n, 2147483647
|
|
%a = icmp slt i32 %nn, %x
|
|
%b = icmp slt i32 %x, 0
|
|
%c = or i1 %a, %b
|
|
ret i1 %c
|
|
}
|
|
|
|
; Negative tests
|
|
|
|
; CHECK-LABEL: define i1 @negative1
|
|
; CHECK: %a = icmp
|
|
; CHECK: %b = icmp
|
|
; CHECK: %c = and i1 %a, %b
|
|
; CHECK: ret i1 %c
|
|
define i1 @negative1(i32 %x, i32 %n) {
|
|
%nn = and i32 %n, 2147483647
|
|
%a = icmp slt i32 %x, %nn
|
|
%b = icmp sgt i32 %x, 0 ; should be: icmp sge
|
|
%c = and i1 %a, %b
|
|
ret i1 %c
|
|
}
|
|
|
|
; CHECK-LABEL: define i1 @negative2
|
|
; CHECK: %a = icmp
|
|
; CHECK: %b = icmp
|
|
; CHECK: %c = and i1 %a, %b
|
|
; CHECK: ret i1 %c
|
|
define i1 @negative2(i32 %x, i32 %n) {
|
|
%a = icmp slt i32 %x, %n ; n can be negative
|
|
%b = icmp sge i32 %x, 0
|
|
%c = and i1 %a, %b
|
|
ret i1 %c
|
|
}
|
|
|
|
; CHECK-LABEL: define i1 @negative3
|
|
; CHECK: %a = icmp
|
|
; CHECK: %b = icmp
|
|
; CHECK: %c = and i1 %a, %b
|
|
; CHECK: ret i1 %c
|
|
define i1 @negative3(i32 %x, i32 %y, i32 %n) {
|
|
%nn = and i32 %n, 2147483647
|
|
%a = icmp slt i32 %x, %nn
|
|
%b = icmp sge i32 %y, 0 ; should compare %x and not %y
|
|
%c = and i1 %a, %b
|
|
ret i1 %c
|
|
}
|
|
|
|
; CHECK-LABEL: define i1 @negative4
|
|
; CHECK: %a = icmp
|
|
; CHECK: %b = icmp
|
|
; CHECK: %c = and i1 %a, %b
|
|
; CHECK: ret i1 %c
|
|
define i1 @negative4(i32 %x, i32 %n) {
|
|
%nn = and i32 %n, 2147483647
|
|
%a = icmp ne i32 %x, %nn ; should be: icmp slt/sle
|
|
%b = icmp sge i32 %x, 0
|
|
%c = and i1 %a, %b
|
|
ret i1 %c
|
|
}
|
|
|
|
; CHECK-LABEL: define i1 @negative5
|
|
; CHECK: %a = icmp
|
|
; CHECK: %b = icmp
|
|
; CHECK: %c = or i1 %a, %b
|
|
; CHECK: ret i1 %c
|
|
define i1 @negative5(i32 %x, i32 %n) {
|
|
%nn = and i32 %n, 2147483647
|
|
%a = icmp slt i32 %x, %nn
|
|
%b = icmp sge i32 %x, 0
|
|
%c = or i1 %a, %b ; should be: and
|
|
ret i1 %c
|
|
}
|
|
|