[llvm] b4d1a60 - [SeparateConstOffsetFromGEP] Check correct index for non-negativity
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed May 15 19:59:20 PDT 2024
Author: Nikita Popov
Date: 2024-05-16T11:59:07+09:00
New Revision: b4d1a606c7492d827aff6ff0c1c109adff1253b9
URL: https://github.com/llvm/llvm-project/commit/b4d1a606c7492d827aff6ff0c1c109adff1253b9
DIFF: https://github.com/llvm/llvm-project/commit/b4d1a606c7492d827aff6ff0c1c109adff1253b9.diff
LOG: [SeparateConstOffsetFromGEP] Check correct index for non-negativity
We were checking the index of GEP twice, instead of checking both
GEP and PtrGEP.
Added:
Modified:
llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
llvm/test/Transforms/SeparateConstOffsetFromGEP/NVPTX/lower-gep-reorder.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
index 1a9eaf28f6e47..7ac1f43b7b6ac 100644
--- a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
+++ b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
@@ -1001,7 +1001,7 @@ bool SeparateConstOffsetFromGEP::reorderGEP(GetElementPtrInst *GEP,
auto KnownGEPIdx = computeKnownBits(GEPIdx->get(), *DL);
IsChainInBounds &= KnownGEPIdx.isNonNegative();
if (IsChainInBounds) {
- auto PtrGEPIdx = GEP->indices().begin();
+ auto PtrGEPIdx = PtrGEP->indices().begin();
auto KnownPtrGEPIdx = computeKnownBits(PtrGEPIdx->get(), *DL);
IsChainInBounds &= KnownPtrGEPIdx.isNonNegative();
}
diff --git a/llvm/test/Transforms/SeparateConstOffsetFromGEP/NVPTX/lower-gep-reorder.ll b/llvm/test/Transforms/SeparateConstOffsetFromGEP/NVPTX/lower-gep-reorder.ll
index ec1cbb9e61c03..23b4a4f788ae6 100644
--- a/llvm/test/Transforms/SeparateConstOffsetFromGEP/NVPTX/lower-gep-reorder.ll
+++ b/llvm/test/Transforms/SeparateConstOffsetFromGEP/NVPTX/lower-gep-reorder.ll
@@ -80,8 +80,8 @@ define void @inboundsPossiblyNegative2(ptr %in.ptr, i64 %in.idx1) {
; CHECK-LABEL: define void @inboundsPossiblyNegative2(
; CHECK-SAME: ptr [[IN_PTR:%.*]], i64 [[IN_IDX1:%.*]]) {
; CHECK-NEXT: [[IN_IDX1_NNEG:%.*]] = and i64 [[IN_IDX1]], 9223372036854775807
-; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds <2 x i8>, ptr [[IN_PTR]], i64 [[IN_IDX1_NNEG]]
-; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds <2 x i8>, ptr [[TMP0]], i64 -1
+; CHECK-NEXT: [[TMP1:%.*]] = getelementptr <2 x i8>, ptr [[IN_PTR]], i64 [[IN_IDX1_NNEG]]
+; CHECK-NEXT: [[TMP2:%.*]] = getelementptr <2 x i8>, ptr [[TMP1]], i64 -1
; CHECK-NEXT: ret void
;
%in.idx1.nneg = and i64 %in.idx1, 9223372036854775807
More information about the llvm-commits
mailing list