[llvm] a093942 - [ConstProp][JumpThreading] add more test coverage for potential nullptr folds; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 8 06:00:27 PST 2021
Author: Sanjay Patel
Date: 2021-03-08T08:53:59-05:00
New Revision: a093942c287501484481384dd03686ffaa5fc98e
URL: https://github.com/llvm/llvm-project/commit/a093942c287501484481384dd03686ffaa5fc98e
DIFF: https://github.com/llvm/llvm-project/commit/a093942c287501484481384dd03686ffaa5fc98e.diff
LOG: [ConstProp][JumpThreading] add more test coverage for potential nullptr folds; NFC
See D98150.
Added:
Modified:
llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll
llvm/test/Transforms/JumpThreading/thread-two-bbs.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll b/llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll
index 5ee8e7a4983b..57aea106ace3 100644
--- a/llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll
+++ b/llvm/test/Transforms/InstSimplify/ConstProp/icmp-null.ll
@@ -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
+}
diff --git a/llvm/test/Transforms/JumpThreading/thread-two-bbs.ll b/llvm/test/Transforms/JumpThreading/thread-two-bbs.ll
index be4f6d7e0896..fd4ec0012f11 100644
--- a/llvm/test/Transforms/JumpThreading/thread-two-bbs.ll
+++ b/llvm/test/Transforms/JumpThreading/thread-two-bbs.ll
@@ -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:%.*]]
More information about the llvm-commits
mailing list