Skip to content

Commit 721c592

Browse files
committed
Changed checked unsinged add to use the canonical form of the intrinsic
1 parent 96cfc75 commit 721c592

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -550,13 +550,14 @@ 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-
554-
Uint(U8) => "llvm.uadd.with.overflow.i8",
555-
Uint(U16) => "llvm.uadd.with.overflow.i16",
556-
Uint(U32) => "llvm.uadd.with.overflow.i32",
557-
Uint(U64) => "llvm.uadd.with.overflow.i64",
558-
Uint(U128) => "llvm.uadd.with.overflow.i128",
559-
553+
Uint(_) => {
554+
// Emit add and icmp instead of llvm.sadd.with.overflow.
555+
// LLVM will attempt to reform llvm.sadd.with.overflow
556+
// in the backend if profitable.
557+
let sum = self.add(lhs, rhs);
558+
let cmp = self.icmp(IntPredicate::IntULT, sum, lhs);
559+
return (sum, cmp);
560+
}
560561
_ => unreachable!(),
561562
},
562563
OverflowOp::Sub => match new_kind {

0 commit comments

Comments
 (0)