Skip to content

Commit 27f6091

Browse files
committed
[ConstraintElimination] Fix nested GEP check.
At the moment, the implementation requires that the outer GEP has a single index, the inner GEP can have an arbitrary indices, because the general `decompose` helper is used.
1 parent bfd1395 commit 27f6091

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

llvm/lib/Transforms/Scalar/ConstraintElimination.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ decomposeGEP(GetElementPtrInst &GEP,
220220
// Handle the (gep (gep ....), C) case by incrementing the constant
221221
// coefficient of the inner GEP, if C is a constant.
222222
auto *InnerGEP = dyn_cast<GetElementPtrInst>(GEP.getPointerOperand());
223-
if (InnerGEP && InnerGEP->getNumOperands() == 2 &&
223+
if (InnerGEP && GEP.getNumOperands() == 2 &&
224224
isa<ConstantInt>(GEP.getOperand(1))) {
225225
APInt Offset = cast<ConstantInt>(GEP.getOperand(1))->getValue();
226226
auto Result = decompose(InnerGEP, Preconditions, IsSigned, DL);

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ define i1 @test_outer_gep_last_index_no_overflow_all_inbounds(ptr %dst) {
99
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds ptr, ptr [[DST]], i64 2
1010
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST_0]], i64 1, i64 1
1111
; CHECK-NEXT: [[C_1:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
12-
; CHECK-NEXT: ret i1 true
12+
; CHECK-NEXT: ret i1 [[C_1]]
1313
;
1414
%dst.0 = getelementptr inbounds ptr, ptr %dst, i64 0
1515
%upper = getelementptr inbounds ptr, ptr %dst, i64 2
@@ -24,7 +24,7 @@ define i1 @test_outer_gep_last_index_overflow_all_inbounds(ptr %dst) {
2424
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds ptr, ptr [[DST]], i64 2
2525
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST_0]], i64 1, i64 2
2626
; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
27-
; CHECK-NEXT: ret i1 true
27+
; CHECK-NEXT: ret i1 [[C]]
2828
;
2929
%dst.0 = getelementptr inbounds ptr, ptr %dst, i64 0
3030
%upper = getelementptr inbounds ptr, ptr %dst, i64 2
@@ -40,7 +40,7 @@ define i1 @test_inner_gep_multiple_indices_ult_true_all_inbounds(ptr %dst) {
4040
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 1
4141
; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
4242
; CHECK-NEXT: [[C_2:%.*]] = icmp uge ptr [[GEP_1]], [[DST_0]]
43-
; CHECK-NEXT: ret i1 [[C]]
43+
; CHECK-NEXT: ret i1 true
4444
;
4545
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
4646
%upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 2
@@ -56,7 +56,7 @@ define i1 @test_inner_gep_multiple_indices_uge_true_all_inbounds(ptr %dst) {
5656
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
5757
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 1
5858
; CHECK-NEXT: [[C:%.*]] = icmp uge ptr [[GEP_1]], [[DST_0]]
59-
; CHECK-NEXT: ret i1 [[C]]
59+
; CHECK-NEXT: ret i1 true
6060
;
6161
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
6262
%upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 2
@@ -72,7 +72,7 @@ define i1 @test_inner_gep_multiple_indices_ult_false_all_inbounds(ptr %dst) {
7272
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
7373
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 2
7474
; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
75-
; CHECK-NEXT: ret i1 [[C]]
75+
; CHECK-NEXT: ret i1 false
7676
;
7777
entry:
7878
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
@@ -89,7 +89,7 @@ define i1 @test_inner_gep_multiple_indices_uge_true_all_inbounds_2(ptr %dst) {
8989
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
9090
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 2
9191
; CHECK-NEXT: [[C:%.*]] = icmp uge ptr [[GEP_1]], [[DST_0]]
92-
; CHECK-NEXT: ret i1 [[C]]
92+
; CHECK-NEXT: ret i1 true
9393
;
9494
entry:
9595
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0

0 commit comments

Comments
 (0)