Skip to content

Commit aae8dfc

Browse files
committed
Emit getelementptr nuw for SliceExp for static array with const lower
bound
1 parent ad730d3 commit aae8dfc

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
@@ -1301,8 +1301,16 @@ class ToElemVisitor : public Visitor {
13011301
}
13021302

13031303
// offset by lower
1304-
eptr = DtoGEP1(DtoMemType(etype->nextOf()), getBasePointer(), vlo, "lowerbound");
1305-
1304+
#if LDC_LLVM_VER >= 2000
1305+
llvm::GEPNoWrapFlags nw = llvm::GEPNoWrapFlags::inBounds();
1306+
if (!needCheckUpper && !needCheckLower)
1307+
nw |= llvm::GEPNoWrapFlags::noUnsignedWrap();
1308+
#endif
1309+
eptr = DtoGEP1(DtoMemType(etype->nextOf()), getBasePointer(), vlo, "lowerbound"
1310+
#if LDC_LLVM_VER >= 2000
1311+
, nullptr, nw
1312+
#endif
1313+
);
13061314
// adjust length
13071315
elen = p->ir->CreateSub(vup, vlo);
13081316
}

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)