[llvm] 27f6091 - [ConstraintElimination] Fix nested GEP check.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 1 07:44:19 PDT 2022
Author: Florian Hahn
Date: 2022-11-01T14:43:42Z
New Revision: 27f6091bb025972e4255bccb74afcc0ebf3ef90e
URL: https://github.com/llvm/llvm-project/commit/27f6091bb025972e4255bccb74afcc0ebf3ef90e
DIFF: https://github.com/llvm/llvm-project/commit/27f6091bb025972e4255bccb74afcc0ebf3ef90e.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
index fc3b2481f57ec..94b890e5660da 100644
--- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp
@@ -220,7 +220,7 @@ decomposeGEP(GetElementPtrInst &GEP,
// Handle the (gep (gep ....), C) case by incrementing the constant
// coefficient of the inner GEP, if C is a constant.
auto *InnerGEP = dyn_cast<GetElementPtrInst>(GEP.getPointerOperand());
- if (InnerGEP && InnerGEP->getNumOperands() == 2 &&
+ if (InnerGEP && GEP.getNumOperands() == 2 &&
isa<ConstantInt>(GEP.getOperand(1))) {
APInt Offset = cast<ConstantInt>(GEP.getOperand(1))->getValue();
auto Result = decompose(InnerGEP, Preconditions, IsSigned, DL);
diff --git a/llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll b/llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll
index 13faebeae2f1c..6191193f5b7a7 100644
--- a/llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll
+++ b/llvm/test/Transforms/ConstraintElimination/gep-add-multiple-indices.ll
@@ -9,7 +9,7 @@ define i1 @test_outer_gep_last_index_no_overflow_all_inbounds(ptr %dst) {
; 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
+; CHECK-NEXT: ret i1 [[C_1]]
;
%dst.0 = getelementptr inbounds ptr, ptr %dst, i64 0
%upper = getelementptr inbounds ptr, ptr %dst, i64 2
@@ -24,7 +24,7 @@ define i1 @test_outer_gep_last_index_overflow_all_inbounds(ptr %dst) {
; 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
+; CHECK-NEXT: ret i1 [[C]]
;
%dst.0 = getelementptr inbounds ptr, ptr %dst, i64 0
%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) {
; 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]]
+; 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
@@ -56,7 +56,7 @@ define i1 @test_inner_gep_multiple_indices_uge_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 uge ptr [[GEP_1]], [[DST_0]]
-; CHECK-NEXT: ret i1 [[C]]
+; 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
@@ -72,7 +72,7 @@ define i1 @test_inner_gep_multiple_indices_ult_false_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 2
; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
-; CHECK-NEXT: ret i1 [[C]]
+; CHECK-NEXT: ret i1 false
;
entry:
%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) {
; 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]]
+; CHECK-NEXT: ret i1 true
;
entry:
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
More information about the llvm-commits
mailing list