[llvm] 2de8f1f - [ConstraintElim] Add chained GEP tests with multiple indices/diff types.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 1 08:51:47 PST 2022


Author: Florian Hahn
Date: 2022-12-01T16:51:40Z
New Revision: 2de8f1f652ff9b9147a2ba4c797e30595910627e

URL: https://github.com/llvm/llvm-project/commit/2de8f1f652ff9b9147a2ba4c797e30595910627e
DIFF: https://github.com/llvm/llvm-project/commit/2de8f1f652ff9b9147a2ba4c797e30595910627e.diff

LOG: [ConstraintElim] Add chained GEP tests with multiple indices/diff types.

Extend test coverage for chained GEPs.

Added: 
    

Modified: 
    llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll
    llvm/test/Transforms/ConstraintElimination/gep-sub.ll

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll b/llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll
index 6191193f5b7a7..c85841b4c68d2 100644
--- a/llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll
+++ b/llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll
@@ -3,8 +3,8 @@
 
 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
 
-define i1 @test_outer_gep_last_index_no_overflow_all_inbounds(ptr %dst) {
-; CHECK-LABEL: @test_outer_gep_last_index_no_overflow_all_inbounds(
+define i1 @test_outer_gep_last_index_no_overflow_all_inbounds_1(ptr %dst) {
+; CHECK-LABEL: @test_outer_gep_last_index_no_overflow_all_inbounds_1(
 ; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds ptr, ptr [[DST:%.*]], i64 0
 ; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds ptr, ptr [[DST]], i64 2
 ; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST_0]], i64 1, i64 1
@@ -18,6 +18,21 @@ define i1 @test_outer_gep_last_index_no_overflow_all_inbounds(ptr %dst) {
   ret i1 %c.1
 }
 
+define i1 @test_outer_gep_last_index_no_overflow_all_inbounds_2(ptr %dst) {
+; CHECK-LABEL: @test_outer_gep_last_index_no_overflow_all_inbounds_2(
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds ptr, ptr [[DST:%.*]], i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds ptr, ptr [[DST]], i64 3
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST_0]], i64 1, i64 1
+; CHECK-NEXT:    [[C_1:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 [[C_1]]
+;
+  %dst.0 = getelementptr inbounds ptr, ptr %dst, i64 0
+  %upper = getelementptr inbounds ptr, ptr %dst, i64 3
+  %gep.1 = getelementptr inbounds [2 x i32] , ptr %dst.0, i64 1, i64 1
+  %c.1 = icmp ult ptr %gep.1, %upper
+  ret i1 %c.1
+}
+
 define i1 @test_outer_gep_last_index_overflow_all_inbounds(ptr %dst) {
 ; CHECK-LABEL: @test_outer_gep_last_index_overflow_all_inbounds(
 ; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds ptr, ptr [[DST:%.*]], i64 0
@@ -39,14 +54,12 @@ define i1 @test_inner_gep_multiple_indices_ult_true_all_inbounds(ptr %dst) {
 ; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
 ; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 1
 ; CHECK-NEXT:    [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
-; CHECK-NEXT:    [[C_2:%.*]] = icmp uge ptr [[GEP_1]], [[DST_0]]
 ; CHECK-NEXT:    ret i1 true
 ;
   %dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
   %upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 2
   %gep.1 = getelementptr inbounds i32, ptr %dst.0, i64 1
   %c = icmp ult ptr %gep.1, %upper
-  %c.2 = icmp uge ptr %gep.1, %dst.0
   ret i1 %c
 }
 
@@ -183,3 +196,144 @@ entry:
   %c = icmp ult i32* %gep.1, %upper
   ret i1 %c
 }
+
+define i1 @test_inner_gep_multi_index(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multi_index(
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds ptr, ptr [[DST:%.*]], i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds ptr, ptr [[DST]], i64 2
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST_0]], i64 1, i64 1
+; CHECK-NEXT:    [[C_1:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 [[C_1]]
+;
+  %dst.0 = getelementptr inbounds ptr, ptr %dst, i64 0
+  %upper = getelementptr inbounds ptr, ptr %dst, i64 2
+  %gep.1 = getelementptr inbounds [2 x i32] , ptr %dst.0, i64 1, i64 1
+  %c.1 = icmp ult ptr %gep.1, %upper
+  ret i1 %c.1
+}
+
+define i1 @test_inner_gep_multi_index_outer_gep_last_index_no_overflow_all_inbounds(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multi_index_outer_gep_last_index_no_overflow_all_inbounds(
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds ptr, ptr [[DST]], i64 2
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST_0]], i64 1, i64 1
+; CHECK-NEXT:    [[C_1:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 [[C_1]]
+;
+  %dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
+  %upper = getelementptr inbounds ptr, ptr %dst, i64 2
+  %gep.1 = getelementptr inbounds [2 x i32] , ptr %dst.0, i64 1, i64 1
+  %c.1 = icmp ult ptr %gep.1, %upper
+  ret i1 %c.1
+}
+
+define i1 @test_inner_gep_multi_index_no_overflow_all_inbounds_1(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multi_index_no_overflow_all_inbounds_1(
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 1
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 2
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 1
+; CHECK-NEXT:    [[C_1:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 false
+;
+  %dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 1
+  %upper = getelementptr inbounds i32, ptr %dst, i64 2
+  %gep.1 = getelementptr inbounds i32, ptr %dst.0, i64 1
+  %c.1 = icmp ult ptr %gep.1, %upper
+  ret i1 %c.1
+}
+
+define i1 @test_inner_gep_multi_index_no_overflow_all_inbounds_2(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multi_index_no_overflow_all_inbounds_2(
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 1, i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 2
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 1
+; CHECK-NEXT:    [[C_1:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 false
+;
+  %dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 1, i64 0
+  %upper = getelementptr inbounds i32, ptr %dst, i64 2
+  %gep.1 = getelementptr inbounds i32, ptr %dst.0, i64 1
+  %c.1 = icmp ult ptr %gep.1, %upper
+  ret i1 %c.1
+}
+
+define i1 @test_inner_gep_multi_index_no_overflow_all_inbounds_3(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multi_index_no_overflow_all_inbounds_3(
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 1, i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 3
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 1
+; CHECK-NEXT:    [[C_1:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 false
+;
+  %dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 1, i64 0
+  %upper = getelementptr inbounds i32, ptr %dst, i64 3
+  %gep.1 = getelementptr inbounds i32, ptr %dst.0, i64 1
+  %c.1 = icmp ult ptr %gep.1, %upper
+  ret i1 %c.1
+}
+
+define i1 @test_inner_gep_multi_index_no_overflow_all_inbounds_4(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multi_index_no_overflow_all_inbounds_4(
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 1, i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 4
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 1
+; CHECK-NEXT:    [[C_1:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 true
+;
+  %dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 1, i64 0
+  %upper = getelementptr inbounds i32, ptr %dst, i64 4
+  %gep.1 = getelementptr inbounds i32, ptr %dst.0, i64 1
+  %c.1 = icmp ult ptr %gep.1, %upper
+  ret i1 %c.1
+}
+
+define i1 @test_inner_gep_multi_index_no_overflow_all_inbounds_5(i64 %off, ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multi_index_no_overflow_all_inbounds_5(
+; CHECK-NEXT:    [[OFF_ULT:%.*]] = icmp ule i64 [[OFF:%.*]], 2
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 2, i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 5
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 1
+; CHECK-NEXT:    [[C_1:%.*]] = icmp ule ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 true
+;
+  %off.ult = icmp ule i64 %off, 2
+  %dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 2, i64 0
+  %upper = getelementptr inbounds i32, ptr %dst, i64 5
+  %gep.1 = getelementptr inbounds i32, ptr %dst.0, i64 1
+  %c.1 = icmp ule ptr %gep.1, %upper
+  ret i1 %c.1
+}
+
+define i1 @test_inner_gep_multi_index_no_overflow_all_inbounds_6(i64 %off, ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multi_index_no_overflow_all_inbounds_6(
+; CHECK-NEXT:    [[OFF_ULT:%.*]] = icmp ule i64 [[OFF:%.*]], 2
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 2, i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 5
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 1
+; CHECK-NEXT:    [[C_1:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 false
+;
+  %off.ult = icmp ule i64 %off, 2
+  %dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 2, i64 0
+  %upper = getelementptr inbounds i32, ptr %dst, i64 5
+  %gep.1 = getelementptr inbounds i32, ptr %dst.0, i64 1
+  %c.1 = icmp ult ptr %gep.1, %upper
+  ret i1 %c.1
+}
+
+define i1 @test_inner_gep_multi_index_no_overflow_all_inbounds_7(i64 %off, ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multi_index_no_overflow_all_inbounds_7(
+; CHECK-NEXT:    [[OFF_ULT:%.*]] = icmp ule i64 [[OFF:%.*]], 2
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 2, i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds i32, ptr [[DST]], i64 [[OFF]]
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 1
+; CHECK-NEXT:    [[C_1:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 [[C_1]]
+;
+  %off.ult = icmp ule i64 %off, 2
+  %dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 2, i64 0
+  %upper = getelementptr inbounds i32, ptr %dst, i64 %off
+  %gep.1 = getelementptr inbounds i32, ptr %dst.0, i64 1
+  %c.1 = icmp ult ptr %gep.1, %upper
+  ret i1 %c.1
+}

diff  --git a/llvm/test/Transforms/ConstraintElimination/gep-sub.ll b/llvm/test/Transforms/ConstraintElimination/gep-sub.ll
index 8f629676db14d..be83e7b91a4d7 100644
--- a/llvm/test/Transforms/ConstraintElimination/gep-sub.ll
+++ b/llvm/test/Transforms/ConstraintElimination/gep-sub.ll
@@ -519,3 +519,61 @@ entry:
   %res = icmp ult ptr %gep.sub.2, %lower
   ret i1 %res
 }
+
+define i1 @gep_i16_sub_1_uge_inbounds(ptr %dst, ptr %lower) {
+; CHECK-LABEL: @gep_i16_sub_1_uge_inbounds(
+; CHECK-NEXT:    [[PRE:%.*]] = icmp uge ptr [[DST:%.*]], [[LOWER:%.*]]
+; CHECK-NEXT:    call void @llvm.assume(i1 [[PRE]])
+; CHECK-NEXT:    [[DST_ADD_3:%.*]] = getelementptr inbounds i8, ptr [[DST]], i64 3
+; CHECK-NEXT:    [[DST_SUB_1:%.*]] = getelementptr inbounds i16, ptr [[DST_ADD_3]], i64 -1
+; CHECK-NEXT:    [[CMP_SUB_1:%.*]] = icmp ule ptr [[DST_SUB_1]], [[LOWER]]
+; CHECK-NEXT:    [[DST_SUB_2:%.*]] = getelementptr inbounds i16, ptr [[DST_ADD_3]], i64 -2
+; CHECK-NEXT:    [[CMP_SUB_2:%.*]] = icmp ule ptr [[DST_SUB_2]], [[DST]]
+; CHECK-NEXT:    [[RES_1:%.*]] = xor i1 false, true
+; CHECK-NEXT:    [[DST_SUB_3:%.*]] = getelementptr inbounds i16, ptr [[DST_ADD_3]], i64 -3
+; CHECK-NEXT:    [[CMP_SUB_3:%.*]] = icmp ule ptr [[DST_SUB_3]], [[LOWER]]
+; CHECK-NEXT:    [[RES_2:%.*]] = xor i1 [[RES_1]], [[CMP_SUB_3]]
+; CHECK-NEXT:    ret i1 [[RES_2]]
+;
+  %pre = icmp uge ptr %dst, %lower
+  call void @llvm.assume(i1 %pre)
+  %dst.add.3 = getelementptr inbounds i8, ptr %dst, i64 3
+  %dst.sub.1 = getelementptr inbounds i16, ptr %dst.add.3, i64 -1
+  %cmp.sub.1 = icmp ule ptr %dst.sub.1, %lower
+  %dst.sub.2 = getelementptr inbounds i16, ptr %dst.add.3, i64 -2
+  %cmp.sub.2 = icmp ule ptr %dst.sub.2, %dst
+  %res.1 = xor i1 %cmp.sub.1, %cmp.sub.2
+  %dst.sub.3 = getelementptr inbounds i16, ptr %dst.add.3, i64 -3
+  %cmp.sub.3 = icmp ule ptr %dst.sub.3, %lower
+  %res.2 = xor i1 %res.1, %cmp.sub.3
+  ret i1 %res.2
+}
+
+define i1 @gep_i16_sub_1_uge_inbounds_var_idx(ptr %dst, i64 %off) {
+; CHECK-LABEL: @gep_i16_sub_1_uge_inbounds_var_idx(
+; CHECK-NEXT:    [[OFF_UGE:%.*]] = icmp sge i64 [[OFF:%.*]], 1
+; CHECK-NEXT:    call void @llvm.assume(i1 [[OFF_UGE]])
+; CHECK-NEXT:    [[DST_ADD_3:%.*]] = getelementptr inbounds i8, ptr [[DST:%.*]], i64 [[OFF]]
+; CHECK-NEXT:    [[DST_SUB_1:%.*]] = getelementptr inbounds i16, ptr [[DST_ADD_3]], i32 -1
+; CHECK-NEXT:    [[CMP_SUB_1:%.*]] = icmp ule ptr [[DST_SUB_1]], [[DST]]
+; CHECK-NEXT:    [[DST_SUB_2:%.*]] = getelementptr inbounds i16, ptr [[DST_ADD_3]], i64 -2
+; CHECK-NEXT:    [[CMP_SUB_2:%.*]] = icmp ule ptr [[DST_SUB_2]], [[DST]]
+; CHECK-NEXT:    [[RES_1:%.*]] = xor i1 [[CMP_SUB_1]], [[CMP_SUB_2]]
+; CHECK-NEXT:    [[DST_SUB_3:%.*]] = getelementptr inbounds i16, ptr [[DST_ADD_3]], i64 -3
+; CHECK-NEXT:    [[CMP_SUB_3:%.*]] = icmp ule ptr [[DST_SUB_3]], [[DST]]
+; CHECK-NEXT:    [[RES_2:%.*]] = xor i1 [[RES_1]], [[CMP_SUB_3]]
+; CHECK-NEXT:    ret i1 [[RES_2]]
+;
+  %off.uge = icmp sge i64 %off, 1
+  call void @llvm.assume(i1 %off.uge)
+  %dst.add.3 = getelementptr inbounds i8, ptr %dst, i64 %off
+  %dst.sub.1 = getelementptr inbounds i16, ptr %dst.add.3, i32 -1
+  %cmp.sub.1 = icmp ule ptr %dst.sub.1, %dst
+  %dst.sub.2 = getelementptr inbounds i16, ptr %dst.add.3, i64 -2
+  %cmp.sub.2 = icmp ule ptr %dst.sub.2, %dst
+  %res.1 = xor i1 %cmp.sub.1, %cmp.sub.2
+  %dst.sub.3 = getelementptr inbounds i16, ptr %dst.add.3, i64 -3
+  %cmp.sub.3 = icmp ule ptr %dst.sub.3, %dst
+  %res.2 = xor i1 %res.1, %cmp.sub.3
+  ret i1 %res.2
+}


        


More information about the llvm-commits mailing list