Skip to content

Commit ffc4850

Browse files
committed
Changed the checked unsinged add to use a simpler, but slighly slower implementation in debug mode.
1 parent 96cfc75 commit ffc4850

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,17 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
550550
Int(I32) => "llvm.sadd.with.overflow.i32",
551551
Int(I64) => "llvm.sadd.with.overflow.i64",
552552
Int(I128) => "llvm.sadd.with.overflow.i128",
553-
553+
Uint(_) if self.cx.sess().opts.optimize == OptLevel::No => {
554+
let sum = self.add(lhs, rhs);
555+
let ord = self.or(lhs, rhs);
556+
let cmp = self.icmp(IntPredicate::IntULT, sum, ord);
557+
return (sum, cmp);
558+
}
554559
Uint(U8) => "llvm.uadd.with.overflow.i8",
555560
Uint(U16) => "llvm.uadd.with.overflow.i16",
556561
Uint(U32) => "llvm.uadd.with.overflow.i32",
557562
Uint(U64) => "llvm.uadd.with.overflow.i64",
558563
Uint(U128) => "llvm.uadd.with.overflow.i128",
559-
560564
_ => unreachable!(),
561565
},
562566
OverflowOp::Sub => match new_kind {

0 commit comments

Comments
 (0)