Skip to content

Commit 2547971

Browse files
committed
Revert "Canonicalize GEPs"
This reverts commit 23cc55f.
1 parent b84448f commit 2547971

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

compiler/rustc_codegen_ssa/src/mir/place.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -422,18 +422,10 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
422422
layout.size
423423
};
424424

425-
let llval = {
426-
let pointee_layout = layout;
427-
let bytes = pointee_layout.size.align_to(pointee_layout.align.abi).bytes();
428-
let rhs = if bytes == 1 {
429-
llindex
430-
} else {
431-
let lhs = llindex;
432-
let rhs = bx.cx().const_usize(bytes);
433-
bx.unchecked_umul(lhs, rhs)
434-
};
435-
bx.inbounds_ptradd(self.val.llval, rhs)
436-
};
425+
let llval = bx.inbounds_gep(bx.cx().backend_type(self.layout), self.val.llval, &[
426+
bx.cx().const_usize(0),
427+
llindex,
428+
]);
437429
let align = self.val.align.restrict_for_offset(offset);
438430
PlaceValue::new_sized(llval, align).with_type(layout)
439431
}

compiler/rustc_codegen_ssa/src/mir/rvalue.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -925,15 +925,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
925925
// so offsetting a pointer to ZST is a noop.
926926
lhs
927927
} else {
928-
let bytes = pointee_layout.size.align_to(pointee_layout.align.abi).bytes();
929-
let rhs = if bytes == 1 {
930-
rhs
931-
} else {
932-
let lhs = rhs;
933-
let rhs = bx.cx().const_usize(bytes);
934-
bx.unchecked_umul(lhs, rhs)
935-
};
936-
bx.inbounds_ptradd(lhs, rhs)
928+
let llty = bx.cx().backend_type(pointee_layout);
929+
bx.inbounds_gep(llty, lhs, &[rhs])
937930
}
938931
}
939932
mir::BinOp::Shl | mir::BinOp::ShlUnchecked => {

0 commit comments

Comments
 (0)