Skip to content

Commit 396a763

Browse files
committed
Emit getelementptr nuw for SliceExp for static array with const lower
bound
1 parent a235955 commit 396a763

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

gen/toir.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,16 @@ class ToElemVisitor : public Visitor {
12931293
}
12941294

12951295
// offset by lower
1296-
eptr = DtoGEP1(DtoMemType(etype->nextOf()), getBasePointer(), vlo, "lowerbound");
1297-
1296+
#if LDC_LLVM_VER >= 2000
1297+
llvm::GEPNoWrapFlags nw = llvm::GEPNoWrapFlags::inBounds();
1298+
if (!needCheckUpper && !needCheckLower)
1299+
nw |= llvm::GEPNoWrapFlags::noUnsignedWrap();
1300+
#endif
1301+
eptr = DtoGEP1(DtoMemType(etype->nextOf()), getBasePointer(), vlo, "lowerbound"
1302+
#if LDC_LLVM_VER >= 2000
1303+
, nullptr, nw
1304+
#endif
1305+
);
12981306
// adjust length
12991307
elen = p->ir->CreateSub(vup, vlo);
13001308
}

tests/codegen/inbounds.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int foo10(int[] a, int i) {
7979
// SliceExp for static array with const lower bound
8080
// CHECK-LABEL: @foo11
8181
int[] foo11(ref int[3] a) {
82-
// CHECK: getelementptr inbounds i32, ptr
82+
// CHECK: getelementptr inbounds{{( nuw)?}} i32, ptr
8383
return a[1 .. $];
8484
}
8585

0 commit comments

Comments
 (0)