[ConstProp][JumpThreading] add more test coverage for potential nullptr folds; NFC

See D98150.
This commit is contained in:
Sanjay Patel 2021-03-08 08:39:56 -05:00
parent b9f169fb7d
commit a093942c28
2 changed files with 80 additions and 2 deletions

View File

@ -32,3 +32,27 @@ define i1 @ult_constexpr_null(i8* %x) {
%cmp = icmp ult i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), null
ret i1 %cmp
}
define i1 @ule_constexpr_null(i8* %x) {
; CHECK-LABEL: @ule_constexpr_null(
; CHECK-NEXT: ret i1 icmp ule (i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), i8 (...)* null)
;
%cmp = icmp ule i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), null
ret i1 %cmp
}
define i1 @slt_constexpr_null(i8* %x) {
; CHECK-LABEL: @slt_constexpr_null(
; CHECK-NEXT: ret i1 icmp slt (i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), i8 (...)* null)
;
%cmp = icmp slt i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), null
ret i1 %cmp
}
define i1 @ult_constexpr_constexpr_one(i8* %x) {
; CHECK-LABEL: @ult_constexpr_constexpr_one(
; CHECK-NEXT: ret i1 icmp ult (i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), i8 (...)* inttoptr (i32 1 to i8 (...)*))
;
%cmp = icmp ult i8 (...)* bitcast (i1 (i8*)* @ugt_null_constexpr to i8 (...)*), inttoptr (i32 1 to i8 (...)*)
ret i1 %cmp
}

View File

@ -137,8 +137,62 @@ exit:
;
; as "true", causing jump threading to a wrong destination.
define void @foo3(i8* %arg1, i8* %arg2) {
; CHECK-LABEL: @foo3(
define void @icmp_ult_null_constexpr(i8* %arg1, i8* %arg2) {
; CHECK-LABEL: @icmp_ult_null_constexpr(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8* [[ARG1:%.*]], null
; CHECK-NEXT: br i1 [[CMP1]], label [[BB_BAR1:%.*]], label [[BB_END:%.*]]
; CHECK: bb_bar1:
; CHECK-NEXT: call void @bar(i32 1)
; CHECK-NEXT: br label [[BB_END]]
; CHECK: bb_end:
; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i8* [[ARG2:%.*]], null
; CHECK-NEXT: br i1 [[CMP2]], label [[BB_CONT:%.*]], label [[BB_BAR2:%.*]]
; CHECK: bb_bar2:
; CHECK-NEXT: call void @bar(i32 2)
; CHECK-NEXT: br label [[BB_EXIT:%.*]]
; CHECK: bb_cont:
; CHECK-NEXT: [[CMP3:%.*]] = icmp ult i8* [[ARG1]], inttoptr (i64 4 to i8*)
; CHECK-NEXT: br i1 [[CMP3]], label [[BB_EXIT]], label [[BB_BAR3:%.*]]
; CHECK: bb_bar3:
; CHECK-NEXT: call void @bar(i32 3)
; CHECK-NEXT: br label [[BB_EXIT]]
; CHECK: bb_exit:
; CHECK-NEXT: ret void
;
entry:
%cmp1 = icmp eq i8* %arg1, null
br i1 %cmp1, label %bb_bar1, label %bb_end
bb_bar1:
call void @bar(i32 1)
br label %bb_end
bb_end:
%cmp2 = icmp ne i8* %arg2, null
br i1 %cmp2, label %bb_cont, label %bb_bar2
bb_bar2:
call void @bar(i32 2)
br label %bb_exit
bb_cont:
%cmp3 = icmp ult i8* %arg1, inttoptr (i64 4 to i8*)
br i1 %cmp3, label %bb_exit, label %bb_bar3
bb_bar3:
call void @bar(i32 3)
br label %bb_exit
bb_exit:
ret void
}
; TODO: This is a special-case of the above pattern:
; Null is guaranteed to be unsigned <= all values.
define void @icmp_ule_null_constexpr(i8* %arg1, i8* %arg2) {
; CHECK-LABEL: @icmp_ule_null_constexpr(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i8* [[ARG1:%.*]], null
; CHECK-NEXT: br i1 [[CMP1]], label [[BB_BAR1:%.*]], label [[BB_END:%.*]]