[llvm] d421080 - [ConstraintElimination] Add tests for nested GEPs with multiple indices.

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 1 07:18:40 PDT 2022


Author: Florian Hahn
Date: 2022-11-01T14:17:38Z
New Revision: d4210800ca67ed0c355556e3e6431cee1df9777e

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

LOG: [ConstraintElimination] Add tests for nested GEPs with multiple indices.

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

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll b/llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll
new file mode 100644
index 0000000000000..13faebeae2f1c
--- /dev/null
+++ b/llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll
@@ -0,0 +1,185 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
+
+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(
+; 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 true
+;
+  %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_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
+; 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 2
+; CHECK-NEXT:    [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 true
+;
+  %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 2
+  %c = icmp ult ptr %gep.1, %upper
+  ret i1 %c
+}
+
+define i1 @test_inner_gep_multiple_indices_ult_true_all_inbounds(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multiple_indices_ult_true_all_inbounds(
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
+; 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 [[C]]
+;
+  %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
+}
+
+define i1 @test_inner_gep_multiple_indices_uge_true_all_inbounds(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multiple_indices_uge_true_all_inbounds(
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
+; 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 uge ptr [[GEP_1]], [[DST_0]]
+; CHECK-NEXT:    ret i1 [[C]]
+;
+  %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 uge ptr %gep.1, %dst.0
+  ret i1 %c
+}
+
+define i1 @test_inner_gep_multiple_indices_ult_false_all_inbounds(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multiple_indices_ult_false_all_inbounds(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
+; 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 2
+; CHECK-NEXT:    [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 [[C]]
+;
+entry:
+  %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 2
+  %c = icmp ult ptr %gep.1, %upper
+  ret i1 %c
+}
+
+define i1 @test_inner_gep_multiple_indices_uge_true_all_inbounds_2(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multiple_indices_uge_true_all_inbounds_2(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
+; 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 2
+; CHECK-NEXT:    [[C:%.*]] = icmp uge ptr [[GEP_1]], [[DST_0]]
+; CHECK-NEXT:    ret i1 [[C]]
+;
+entry:
+  %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 2
+  %c = icmp uge ptr %gep.1, %dst.0
+  ret i1 %c
+}
+
+define i1 @test_inner_gep_multiple_indices_ult_true_inc_gep_all_inbounds_overflow(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multiple_indices_ult_true_inc_gep_all_inbounds_overflow(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 6
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr i32, ptr [[DST_0]], i64 2
+; CHECK-NEXT:    [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 [[C]]
+;
+entry:
+  %dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
+  %upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 6
+  %gep.1 = getelementptr i32, i32* %dst.0, i64 2
+  %c = icmp ult i32* %gep.1, %upper
+  ret i1 %c
+}
+
+define i1 @test_inner_gep_multiple_indices_ult_true_inc_gep_not_inbounds(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multiple_indices_ult_true_inc_gep_not_inbounds(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr i32, ptr [[DST_0]], i64 1
+; CHECK-NEXT:    [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 [[C]]
+;
+entry:
+  %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 i32, ptr %dst.0, i64 1
+  %c = icmp ult i32* %gep.1, %upper
+  ret i1 %c
+}
+
+define i1 @test_inner_gep_multiple_indices_uge_true_inc_gep_not_inbounds(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multiple_indices_uge_true_inc_gep_not_inbounds(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr i32, ptr [[DST_0]], i64 1
+; CHECK-NEXT:    [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 [[C]]
+;
+entry:
+  %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 i32, ptr %dst.0, i64 1
+  %c = icmp ult i32* %gep.1, %upper
+  ret i1 %c
+}
+
+define i1 @test_inner_gep_multiple_indices_ult_false_inc_gep_not_inbounds(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multiple_indices_ult_false_inc_gep_not_inbounds(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr i32, ptr [[DST_0]], i64 2
+; CHECK-NEXT:    [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 [[C]]
+;
+entry:
+  %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 i32, i32* %dst.0, i64 2
+  %c = icmp ult i32* %gep.1, %upper
+  ret i1 %c
+}
+
+define i1 @test_inner_gep_multiple_indices_ult_true_inc_gep_not_inbounds_overflow(ptr %dst) {
+; CHECK-LABEL: @test_inner_gep_multiple_indices_ult_true_inc_gep_not_inbounds_overflow(
+; CHECK-NEXT:  entry:
+; CHECK-NEXT:    [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
+; CHECK-NEXT:    [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 5
+; CHECK-NEXT:    [[GEP_1:%.*]] = getelementptr i32, ptr [[DST_0]], i64 2
+; CHECK-NEXT:    [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
+; CHECK-NEXT:    ret i1 [[C]]
+;
+entry:
+  %dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
+  %upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 5
+  %gep.1 = getelementptr i32, i32* %dst.0, i64 2
+  %c = icmp ult i32* %gep.1, %upper
+  ret i1 %c
+}


        


More information about the llvm-commits mailing list