[llvm] 0b57465 - [ConstraintElim] Add additional GEP subtraction tests.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 21 10:58:32 PDT 2022
Author: Florian Hahn
Date: 2022-10-21T18:58:15+01:00
New Revision: 0b574650d6db498e4c3b0cf8d4818db577d45b02
URL: https://github.com/llvm/llvm-project/commit/0b574650d6db498e4c3b0cf8d4818db577d45b02
DIFF: https://github.com/llvm/llvm-project/commit/0b574650d6db498e4c3b0cf8d4818db577d45b02.diff
LOG: [ConstraintElim] Add additional GEP subtraction tests.
Added:
Modified:
llvm/test/Transforms/ConstraintElimination/gep-sub.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/ConstraintElimination/gep-sub.ll b/llvm/test/Transforms/ConstraintElimination/gep-sub.ll
index 52ba926fd7342..8f629676db14d 100644
--- a/llvm/test/Transforms/ConstraintElimination/gep-sub.ll
+++ b/llvm/test/Transforms/ConstraintElimination/gep-sub.ll
@@ -342,6 +342,68 @@ define i1 @gep_sub_2_ult_var_idx(ptr %dst, ptr %upper, i8 %len, i8 %idx) {
ret i1 %cmp.idx
}
+define i1 @gep_sub_2_ult_var_idx_inbounds_len_sge_2(ptr %dst, ptr %upper, i8 %len, i8 %idx) {
+; CHECK-LABEL: @gep_sub_2_ult_var_idx_inbounds_len_sge_2(
+; CHECK-NEXT: [[SGE_2:%.*]] = icmp sge i8 [[LEN:%.*]], 2
+; CHECK-NEXT: call void @llvm.assume(i1 [[SGE_2]])
+; CHECK-NEXT: [[LEN_EXT:%.*]] = zext i8 [[LEN]] to i16
+; CHECK-NEXT: [[DST_ADD_LEN:%.*]] = getelementptr inbounds i8, ptr [[DST:%.*]], i16 [[LEN_EXT]]
+; CHECK-NEXT: [[DST_SUB_1:%.*]] = getelementptr inbounds i8, ptr [[DST_ADD_LEN]], i64 -1
+; CHECK-NEXT: [[CMP_SUB_1:%.*]] = icmp ult ptr [[DST_SUB_1]], [[UPPER:%.*]]
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_SUB_1]])
+; CHECK-NEXT: [[CMP_IDX_ULT_LEN:%.*]] = icmp ult i8 [[IDX:%.*]], [[LEN]]
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_IDX_ULT_LEN]])
+; CHECK-NEXT: [[IDX_EXT:%.*]] = zext i8 [[IDX]] to i16
+; CHECK-NEXT: [[DST_ADD_IDX:%.*]] = getelementptr inbounds i8, ptr [[DST]], i16 [[IDX_EXT]]
+; CHECK-NEXT: [[CMP_IDX:%.*]] = icmp ult ptr [[DST_ADD_IDX]], [[UPPER]]
+; CHECK-NEXT: ret i1 true
+;
+ %sge.2 = icmp sge i8 %len, 2
+ call void @llvm.assume(i1 %sge.2)
+ %len.ext = zext i8 %len to i16
+ %dst.add.len = getelementptr inbounds i8, ptr %dst, i16 %len.ext
+ %dst.sub.1 = getelementptr inbounds i8, ptr %dst.add.len, i64 -1
+ %cmp.sub.1 = icmp ult ptr %dst.sub.1, %upper
+ call void @llvm.assume(i1 %cmp.sub.1)
+ %cmp.idx.ult.len = icmp ult i8 %idx, %len
+ call void @llvm.assume(i1 %cmp.idx.ult.len)
+ %idx.ext = zext i8 %idx to i16
+ %dst.add.idx = getelementptr inbounds i8, ptr %dst, i16 %idx.ext
+ %cmp.idx = icmp ult ptr %dst.add.idx, %upper
+ ret i1 %cmp.idx
+}
+
+define i1 @gep_sub_2_ult_var_idx_inbounds_len_uge_2(ptr %dst, ptr %upper, i8 %len, i8 %idx) {
+; CHECK-LABEL: @gep_sub_2_ult_var_idx_inbounds_len_uge_2(
+; CHECK-NEXT: [[UGE_2:%.*]] = icmp uge i8 [[LEN:%.*]], 2
+; CHECK-NEXT: call void @llvm.assume(i1 [[UGE_2]])
+; CHECK-NEXT: [[LEN_EXT:%.*]] = zext i8 [[LEN]] to i16
+; CHECK-NEXT: [[DST_ADD_LEN:%.*]] = getelementptr inbounds i8, ptr [[DST:%.*]], i16 [[LEN_EXT]]
+; CHECK-NEXT: [[DST_SUB_1:%.*]] = getelementptr inbounds i8, ptr [[DST_ADD_LEN]], i64 -1
+; CHECK-NEXT: [[CMP_SUB_1:%.*]] = icmp ult ptr [[DST_SUB_1]], [[UPPER:%.*]]
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_SUB_1]])
+; CHECK-NEXT: [[CMP_IDX_ULT_LEN:%.*]] = icmp ult i8 [[IDX:%.*]], [[LEN]]
+; CHECK-NEXT: call void @llvm.assume(i1 [[CMP_IDX_ULT_LEN]])
+; CHECK-NEXT: [[IDX_EXT:%.*]] = zext i8 [[IDX]] to i16
+; CHECK-NEXT: [[DST_ADD_IDX:%.*]] = getelementptr inbounds i8, ptr [[DST]], i16 [[IDX_EXT]]
+; CHECK-NEXT: [[CMP_IDX:%.*]] = icmp ult ptr [[DST_ADD_IDX]], [[UPPER]]
+; CHECK-NEXT: ret i1 true
+;
+ %uge.2 = icmp uge i8 %len, 2
+ call void @llvm.assume(i1 %uge.2)
+ %len.ext = zext i8 %len to i16
+ %dst.add.len = getelementptr inbounds i8, ptr %dst, i16 %len.ext
+ %dst.sub.1 = getelementptr inbounds i8, ptr %dst.add.len, i64 -1
+ %cmp.sub.1 = icmp ult ptr %dst.sub.1, %upper
+ call void @llvm.assume(i1 %cmp.sub.1)
+ %cmp.idx.ult.len = icmp ult i8 %idx, %len
+ call void @llvm.assume(i1 %cmp.idx.ult.len)
+ %idx.ext = zext i8 %idx to i16
+ %dst.add.idx = getelementptr inbounds i8, ptr %dst, i16 %idx.ext
+ %cmp.idx = icmp ult ptr %dst.add.idx, %upper
+ ret i1 %cmp.idx
+}
+
define i1 @gep_sub_ult_var_idx_len_sgt_1(ptr %dst, ptr %upper, i8 %len, i8 %idx) {
; CHECK-LABEL: @gep_sub_ult_var_idx_len_sgt_1(
; CHECK-NEXT: [[SGT_1:%.*]] = icmp sgt i8 [[LEN:%.*]], 1
@@ -372,3 +434,88 @@ define i1 @gep_sub_ult_var_idx_len_sgt_1(ptr %dst, ptr %upper, i8 %len, i8 %idx)
%cmp.idx = icmp ult ptr %dst.add.idx, %upper
ret i1 %cmp.idx
}
+
+define i1 @gep_sub_1_ult_var_idx_lower_bound(ptr %lower, ptr %src, i8 %len) {
+; CHECK-LABEL: @gep_sub_1_ult_var_idx_lower_bound(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[SRC_UGE_LOWER:%.*]] = icmp uge ptr [[SRC:%.*]], [[LOWER:%.*]]
+; CHECK-NEXT: call void @llvm.assume(i1 [[SRC_UGE_LOWER]])
+; CHECK-NEXT: [[LEN_POS:%.*]] = icmp sge i8 [[LEN:%.*]], 0
+; CHECK-NEXT: call void @llvm.assume(i1 [[LEN_POS]])
+; CHECK-NEXT: [[GEP_LEN:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i8 [[LEN]]
+; CHECK-NEXT: [[GEP_SUB_1:%.*]] = getelementptr inbounds i8, ptr [[GEP_LEN]], i8 -1
+; CHECK-NEXT: [[RES:%.*]] = icmp ult ptr [[GEP_SUB_1]], [[LOWER]]
+; CHECK-NEXT: ret i1 [[RES]]
+;
+entry:
+ %src.uge.lower = icmp uge ptr %src, %lower
+ call void @llvm.assume(i1 %src.uge.lower)
+
+ %len.pos = icmp sge i8 %len, 0
+ call void @llvm.assume(i1 %len.pos)
+
+ %gep.len = getelementptr inbounds i8, ptr %src, i8 %len
+ %gep.sub.1 = getelementptr inbounds i8, ptr %gep.len, i8 -1
+ %res = icmp ult ptr %gep.sub.1, %lower
+ ret i1 %res
+}
+
+define i1 @gep_sub_1_ult_var_idx_lower_bound_len_ne_0(ptr %lower, ptr %src, i8 %len) {
+; CHECK-LABEL: @gep_sub_1_ult_var_idx_lower_bound_len_ne_0(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[LEN_NE_0:%.*]] = icmp ne i8 [[LEN:%.*]], 0
+; CHECK-NEXT: call void @llvm.assume(i1 [[LEN_NE_0]])
+; CHECK-NEXT: [[SRC_UGE_LOWER:%.*]] = icmp uge ptr [[SRC:%.*]], [[LOWER:%.*]]
+; CHECK-NEXT: call void @llvm.assume(i1 [[SRC_UGE_LOWER]])
+; CHECK-NEXT: [[LEN_POS:%.*]] = icmp sge i8 [[LEN]], 0
+; CHECK-NEXT: call void @llvm.assume(i1 [[LEN_POS]])
+; CHECK-NEXT: [[GEP_LEN:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i8 [[LEN]]
+; CHECK-NEXT: [[GEP_SUB_1:%.*]] = getelementptr inbounds i8, ptr [[GEP_LEN]], i8 -1
+; CHECK-NEXT: [[RES:%.*]] = icmp ult ptr [[GEP_SUB_1]], [[LOWER]]
+; CHECK-NEXT: ret i1 [[RES]]
+;
+entry:
+ %len.ne.0 = icmp ne i8 %len, 0
+ call void @llvm.assume(i1 %len.ne.0)
+
+ %src.uge.lower = icmp uge ptr %src, %lower
+ call void @llvm.assume(i1 %src.uge.lower)
+
+ %len.pos = icmp sge i8 %len, 0
+ call void @llvm.assume(i1 %len.pos)
+
+ %gep.len = getelementptr inbounds i8, ptr %src, i8 %len
+ %gep.sub.1 = getelementptr inbounds i8, ptr %gep.len, i8 -1
+ %res = icmp ult ptr %gep.sub.1, %lower
+ ret i1 %res
+}
+
+define i1 @gep_sub_2_ult_var_idx_lower_bound_len_ne_0(ptr %lower, ptr %src, i8 %len) {
+; CHECK-LABEL: @gep_sub_2_ult_var_idx_lower_bound_len_ne_0(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: [[LEN_NE_0:%.*]] = icmp ne i8 [[LEN:%.*]], 0
+; CHECK-NEXT: call void @llvm.assume(i1 [[LEN_NE_0]])
+; CHECK-NEXT: [[SRC_UGE_LOWER:%.*]] = icmp uge ptr [[SRC:%.*]], [[LOWER:%.*]]
+; CHECK-NEXT: call void @llvm.assume(i1 [[SRC_UGE_LOWER]])
+; CHECK-NEXT: [[LEN_POS:%.*]] = icmp sge i8 [[LEN]], 0
+; CHECK-NEXT: call void @llvm.assume(i1 [[LEN_POS]])
+; CHECK-NEXT: [[GEP_LEN:%.*]] = getelementptr inbounds i8, ptr [[SRC]], i8 [[LEN]]
+; CHECK-NEXT: [[GEP_SUB_2:%.*]] = getelementptr inbounds i8, ptr [[GEP_LEN]], i8 -2
+; CHECK-NEXT: [[RES:%.*]] = icmp ult ptr [[GEP_SUB_2]], [[LOWER]]
+; CHECK-NEXT: ret i1 [[RES]]
+;
+entry:
+ %len.ne.0 = icmp ne i8 %len, 0
+ call void @llvm.assume(i1 %len.ne.0)
+
+ %src.uge.lower = icmp uge ptr %src, %lower
+ call void @llvm.assume(i1 %src.uge.lower)
+
+ %len.pos = icmp sge i8 %len, 0
+ call void @llvm.assume(i1 %len.pos)
+
+ %gep.len = getelementptr inbounds i8, ptr %src, i8 %len
+ %gep.sub.2 = getelementptr inbounds i8, ptr %gep.len, i8 -2
+ %res = icmp ult ptr %gep.sub.2, %lower
+ ret i1 %res
+}
More information about the llvm-commits
mailing list