From: Florian Hahn Date: Tue, 1 Nov 2022 14:17:38 +0000 (+0000) Subject: [ConstraintElimination] Add tests for nested GEPs with multiple indices. X-Git-Tag: upstream/17.0.6~28862 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d4210800ca67ed0c355556e3e6431cee1df9777e;p=platform%2Fupstream%2Fllvm.git [ConstraintElimination] Add tests for nested GEPs with multiple indices. --- 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 0000000..13faebe --- /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 +}