From 721c59232c88f7c6f1444b97cc5840108a500338 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kostrubiec?= Date: Fri, 7 Mar 2025 23:37:11 +0100 Subject: [PATCH] Changed checked unsinged add to use the canonical form of the intrinsic --- compiler/rustc_codegen_llvm/src/builder.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 3f20350d0efd5..d8240bed0e6d9 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -550,13 +550,14 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { Int(I32) => "llvm.sadd.with.overflow.i32", Int(I64) => "llvm.sadd.with.overflow.i64", Int(I128) => "llvm.sadd.with.overflow.i128", - - Uint(U8) => "llvm.uadd.with.overflow.i8", - Uint(U16) => "llvm.uadd.with.overflow.i16", - Uint(U32) => "llvm.uadd.with.overflow.i32", - Uint(U64) => "llvm.uadd.with.overflow.i64", - Uint(U128) => "llvm.uadd.with.overflow.i128", - + Uint(_) => { + // Emit add and icmp instead of llvm.sadd.with.overflow. + // LLVM will attempt to reform llvm.sadd.with.overflow + // in the backend if profitable. + let sum = self.add(lhs, rhs); + let cmp = self.icmp(IntPredicate::IntULT, sum, lhs); + return (sum, cmp); + } _ => unreachable!(), }, OverflowOp::Sub => match new_kind {