mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-24 21:42:54 +02:00
c7e872f52f
This was split off of http://reviews.llvm.org/D13040 to make it easier to test the correctness of the implication logic. For the moment, this only handles a single easy case which shows up when eliminating and combining range checks. In the (near) future, I plan to extend this for other cases which show up in range checks, but I wanted to make those changes incrementally once the framework was in place. At the moment, the implication logic will be used by three places. One in InstSimplify (this review) and two in SimplifyCFG (http://reviews.llvm.org/D13040 & http://reviews.llvm.org/D13070). Can anyone think of other locations this style of reasoning would make sense? Differential Revision: http://reviews.llvm.org/D13074 llvm-svn: 248719
78 lines
2.0 KiB
LLVM
78 lines
2.0 KiB
LLVM
; RUN: opt -S %s -instsimplify | FileCheck %s
|
|
|
|
; A ==> A -> true
|
|
define i1 @test(i32 %length.i, i32 %i) {
|
|
; CHECK-LABEL: @test
|
|
; CHECK: ret i1 true
|
|
%var29 = icmp slt i32 %i, %length.i
|
|
%res = icmp uge i1 %var29, %var29
|
|
ret i1 %res
|
|
}
|
|
|
|
; i +_{nsw} C_{>0} <s L ==> i <s L -> true
|
|
define i1 @test2(i32 %length.i, i32 %i) {
|
|
; CHECK-LABEL: @test2
|
|
; CHECK: ret i1 true
|
|
%iplus1 = add nsw i32 %i, 1
|
|
%var29 = icmp slt i32 %i, %length.i
|
|
%var30 = icmp slt i32 %iplus1, %length.i
|
|
%res = icmp ule i1 %var30, %var29
|
|
ret i1 %res
|
|
}
|
|
|
|
; i + C_{>0} <s L ==> i <s L -> unknown without the nsw
|
|
define i1 @test2_neg(i32 %length.i, i32 %i) {
|
|
; CHECK-LABEL: @test2_neg
|
|
; CHECK: ret i1 %res
|
|
%iplus1 = add i32 %i, 1
|
|
%var29 = icmp slt i32 %i, %length.i
|
|
%var30 = icmp slt i32 %iplus1, %length.i
|
|
%res = icmp ule i1 %var30, %var29
|
|
ret i1 %res
|
|
}
|
|
|
|
; sle is not implication
|
|
define i1 @test2_neg2(i32 %length.i, i32 %i) {
|
|
; CHECK-LABEL: @test2_neg2
|
|
; CHECK: ret i1 %res
|
|
%iplus1 = add i32 %i, 1
|
|
%var29 = icmp slt i32 %i, %length.i
|
|
%var30 = icmp slt i32 %iplus1, %length.i
|
|
%res = icmp sle i1 %var30, %var29
|
|
ret i1 %res
|
|
}
|
|
|
|
; The binary operator has to be an add
|
|
define i1 @test2_neg3(i32 %length.i, i32 %i) {
|
|
; CHECK-LABEL: @test2_neg3
|
|
; CHECK: ret i1 %res
|
|
%iplus1 = sub nsw i32 %i, 1
|
|
%var29 = icmp slt i32 %i, %length.i
|
|
%var30 = icmp slt i32 %iplus1, %length.i
|
|
%res = icmp ule i1 %var30, %var29
|
|
ret i1 %res
|
|
}
|
|
|
|
; i +_{nsw} C_{>0} <s L ==> i <s L -> true
|
|
; With an inverted conditional (ule B A rather than canonical ugt A B
|
|
define i1 @test3(i32 %length.i, i32 %i) {
|
|
; CHECK-LABEL: @test3
|
|
; CHECK: ret i1 true
|
|
%iplus1 = add nsw i32 %i, 1
|
|
%var29 = icmp slt i32 %i, %length.i
|
|
%var30 = icmp slt i32 %iplus1, %length.i
|
|
%res = icmp uge i1 %var29, %var30
|
|
ret i1 %res
|
|
}
|
|
|
|
; i +_{nuw} C_{>0} <u L ==> i <u L
|
|
define i1 @test4(i32 %length.i, i32 %i) {
|
|
; CHECK-LABEL: @test4
|
|
; CHECK: ret i1 true
|
|
%iplus1 = add nuw i32 %i, 1
|
|
%var29 = icmp ult i32 %i, %length.i
|
|
%var30 = icmp ult i32 %iplus1, %length.i
|
|
%res = icmp ule i1 %var30, %var29
|
|
ret i1 %res
|
|
}
|