Skip to content

Commit b4d1a60

Browse files
committed
[SeparateConstOffsetFromGEP] Check correct index for non-negativity
We were checking the index of GEP twice, instead of checking both GEP and PtrGEP.
1 parent 31c9038 commit b4d1a60

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ bool SeparateConstOffsetFromGEP::reorderGEP(GetElementPtrInst *GEP,
10011001
auto KnownGEPIdx = computeKnownBits(GEPIdx->get(), *DL);
10021002
IsChainInBounds &= KnownGEPIdx.isNonNegative();
10031003
if (IsChainInBounds) {
1004-
auto PtrGEPIdx = GEP->indices().begin();
1004+
auto PtrGEPIdx = PtrGEP->indices().begin();
10051005
auto KnownPtrGEPIdx = computeKnownBits(PtrGEPIdx->get(), *DL);
10061006
IsChainInBounds &= KnownPtrGEPIdx.isNonNegative();
10071007
}

llvm/test/Transforms/SeparateConstOffsetFromGEP/NVPTX/lower-gep-reorder.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ define void @inboundsPossiblyNegative2(ptr %in.ptr, i64 %in.idx1) {
8080
; CHECK-LABEL: define void @inboundsPossiblyNegative2(
8181
; CHECK-SAME: ptr [[IN_PTR:%.*]], i64 [[IN_IDX1:%.*]]) {
8282
; CHECK-NEXT: [[IN_IDX1_NNEG:%.*]] = and i64 [[IN_IDX1]], 9223372036854775807
83-
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds <2 x i8>, ptr [[IN_PTR]], i64 [[IN_IDX1_NNEG]]
84-
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds <2 x i8>, ptr [[TMP0]], i64 -1
83+
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr <2 x i8>, ptr [[IN_PTR]], i64 [[IN_IDX1_NNEG]]
84+
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr <2 x i8>, ptr [[TMP1]], i64 -1
8585
; CHECK-NEXT: ret void
8686
;
8787
%in.idx1.nneg = and i64 %in.idx1, 9223372036854775807

0 commit comments

Comments
 (0)