[CVP] Additional tests for comparison with offset (NFC)

Both icmps have an additional offset here. We would fold this if
the second one didn't.
This commit is contained in:
Nikita Popov 2020-09-20 21:50:21 +02:00
parent 445db89b53
commit 1a27238098
1 changed files with 46 additions and 3 deletions

View File

@ -7,6 +7,7 @@ target triple = "x86_64-apple-macosx10.10.0"
declare void @check1(i1) #1 declare void @check1(i1) #1
declare void @check2(i1) #1 declare void @check2(i1) #1
declare void @llvm.assume(i1)
; Make sure we propagate the value of %tmp35 to the true/false cases ; Make sure we propagate the value of %tmp35 to the true/false cases
@ -16,10 +17,10 @@ define void @test1(i64 %tmp35) {
; CHECK-NEXT: [[TMP36:%.*]] = icmp sgt i64 [[TMP35:%.*]], 0 ; CHECK-NEXT: [[TMP36:%.*]] = icmp sgt i64 [[TMP35:%.*]], 0
; CHECK-NEXT: br i1 [[TMP36]], label [[BB_TRUE:%.*]], label [[BB_FALSE:%.*]] ; CHECK-NEXT: br i1 [[TMP36]], label [[BB_TRUE:%.*]], label [[BB_FALSE:%.*]]
; CHECK: bb_true: ; CHECK: bb_true:
; CHECK-NEXT: tail call void @check1(i1 false) [[ATTR0:#.*]] ; CHECK-NEXT: tail call void @check1(i1 false) [[ATTR1:#.*]]
; CHECK-NEXT: unreachable ; CHECK-NEXT: unreachable
; CHECK: bb_false: ; CHECK: bb_false:
; CHECK-NEXT: tail call void @check2(i1 true) [[ATTR0]] ; CHECK-NEXT: tail call void @check2(i1 true) [[ATTR1]]
; CHECK-NEXT: unreachable ; CHECK-NEXT: unreachable
; ;
bb: bb:
@ -55,7 +56,7 @@ define void @test2(i64 %tmp35, i1 %inner_cmp) {
; CHECK-NEXT: tail call void @check1(i1 false) ; CHECK-NEXT: tail call void @check1(i1 false)
; CHECK-NEXT: unreachable ; CHECK-NEXT: unreachable
; CHECK: bb_false: ; CHECK: bb_false:
; CHECK-NEXT: tail call void @check2(i1 true) [[ATTR0]] ; CHECK-NEXT: tail call void @check2(i1 true) [[ATTR1]]
; CHECK-NEXT: unreachable ; CHECK-NEXT: unreachable
; ;
bb: bb:
@ -619,6 +620,48 @@ exit:
ret i1 %iv ret i1 %iv
} }
define i1 @test_br_cmp_with_offset(i64 %idx) {
; CHECK-LABEL: @test_br_cmp_with_offset(
; CHECK-NEXT: [[IDX_OFF1:%.*]] = add i64 [[IDX:%.*]], -5
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[IDX_OFF1]], 3
; CHECK-NEXT: br i1 [[CMP1]], label [[IF_TRUE:%.*]], label [[IF_FALSE:%.*]]
; CHECK: if.true:
; CHECK-NEXT: [[IDX_OFF2:%.*]] = add nsw i64 [[IDX]], -1
; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i64 [[IDX_OFF2]], 10
; CHECK-NEXT: ret i1 [[CMP2]]
; CHECK: if.false:
; CHECK-NEXT: ret i1 undef
;
%idx.off1 = add i64 %idx, -5
%cmp1 = icmp ult i64 %idx.off1, 3
br i1 %cmp1, label %if.true, label %if.false
if.true:
%idx.off2 = add i64 %idx, -1
%cmp2 = icmp ult i64 %idx.off2, 10
ret i1 %cmp2
if.false:
ret i1 undef
}
define i1 @test_assume_cmp_with_offset(i64 %idx) {
; CHECK-LABEL: @test_assume_cmp_with_offset(
; CHECK-NEXT: [[IDX_OFF1:%.*]] = add i64 [[IDX:%.*]], -5
; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[IDX_OFF1]], 3
; CHECK-NEXT: tail call void @llvm.assume(i1 [[CMP1]])
; CHECK-NEXT: [[IDX_OFF2:%.*]] = add i64 [[IDX]], -1
; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i64 [[IDX_OFF2]], 10
; CHECK-NEXT: ret i1 [[CMP2]]
;
%idx.off1 = add i64 %idx, -5
%cmp1 = icmp ult i64 %idx.off1, 3
tail call void @llvm.assume(i1 %cmp1)
%idx.off2 = add i64 %idx, -1
%cmp2 = icmp ult i64 %idx.off2, 10
ret i1 %cmp2
}
define void @test_cmp_phi(i8 %a) { define void @test_cmp_phi(i8 %a) {
; CHECK-LABEL: @test_cmp_phi( ; CHECK-LABEL: @test_cmp_phi(
; CHECK-NEXT: entry: ; CHECK-NEXT: entry: