Skip to content

Commit 9e7b184

Browse files
committed
Also use gep inbounds nuw for index projections
1 parent 31cc4c0 commit 9e7b184

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Diff for: compiler/rustc_codegen_ssa/src/mir/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
423423
layout.size
424424
};
425425

426-
let llval = bx.inbounds_gep(bx.cx().backend_type(layout), self.val.llval, &[llindex]);
426+
let llval = bx.inbounds_nuw_gep(bx.cx().backend_type(layout), self.val.llval, &[llindex]);
427427
let align = self.val.align.restrict_for_offset(offset);
428428
PlaceValue::new_sized(llval, align).with_type(layout)
429429
}

Diff for: tests/codegen/gep-index.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct Foo(i32, i32);
1111
// CHECK-LABEL: @index_on_struct(
1212
#[no_mangle]
1313
fn index_on_struct(a: &[Foo], index: usize) -> &Foo {
14-
// CHECK: getelementptr inbounds %Foo, ptr %a.0, {{i64|i32}} %index
14+
// CHECK: getelementptr inbounds{{( nuw)?}} %Foo, ptr %a.0, {{i64|i32}} %index
1515
&a[index]
1616
}
1717

@@ -25,7 +25,7 @@ fn offset_on_struct(a: *const Foo, index: usize) -> *const Foo {
2525
// CHECK-LABEL: @index_on_i32(
2626
#[no_mangle]
2727
fn index_on_i32(a: &[i32], index: usize) -> &i32 {
28-
// CHECK: getelementptr inbounds i32, ptr %a.0, {{i64|i32}} %index
28+
// CHECK: getelementptr inbounds{{( nuw)?}} i32, ptr %a.0, {{i64|i32}} %index
2929
&a[index]
3030
}
3131

0 commit comments

Comments
 (0)