Avoid iadd for ptr const val with zero offset

This commit is contained in:
bjorn3 2020-10-12 12:03:18 +02:00
parent cd2fc77b0e
commit 2f2d3b2fd4
1 changed files with 7 additions and 4 deletions

View File

@ -225,10 +225,13 @@ pub(crate) fn trans_const_value<'tcx>(
}
None => bug!("missing allocation {:?}", ptr.alloc_id),
};
let val = fx
.bcx
.ins()
.iadd_imm(base_addr, i64::try_from(ptr.offset.bytes()).unwrap());
let val = if ptr.offset.bytes() != 0 {
fx.bcx
.ins()
.iadd_imm(base_addr, i64::try_from(ptr.offset.bytes()).unwrap())
} else {
base_addr
};
return CValue::by_val(val, layout);
}
}