diff options
| author | bors <bors@rust-lang.org> | 2025-08-10 09:24:56 +0000 | 
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-08-10 09:24:56 +0000 | 
| commit | 7f7b8ef27d86c865a7ab20c7c42f50811c6a914d (patch) | |
| tree | 1f65ca0a40a5874ad7e9f69aacf30199cb6d8378 /compiler/rustc_codegen_llvm/src | |
| parent | 8712e4567551a2714efa66dac204ec7137bc5605 (diff) | |
| parent | 8831c5b9946561a37dc7ee6fd826ef1470e8f380 (diff) | |
| download | rust-7f7b8ef27d86c865a7ab20c7c42f50811c6a914d.tar.gz rust-7f7b8ef27d86c865a7ab20c7c42f50811c6a914d.zip | |
Auto merge of #145144 - scottmcm:unsigned_overflow_intr, r=nikic
Stop using uadd.with.overflow As discussed in [#t-compiler/llvm > `uadd.with.overflow` (again) @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/187780-t-compiler.2Fllvm/topic/.60uadd.2Ewith.2Eoverflow.60.20.28again.29/near/533041085), stop emitting `uadd.with.overflow` in favour of `add`+`icmp` instead. r? nikic
Diffstat (limited to 'compiler/rustc_codegen_llvm/src')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/builder.rs | 26 | 
1 files changed, 19 insertions, 7 deletions
| diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 32cdef075e7..917d07e3c61 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -557,13 +557,25 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { let (size, signed) = ty.int_size_and_signed(self.tcx); let width = size.bits(); - if oop == OverflowOp::Sub && !signed { - // Emit sub and icmp instead of llvm.usub.with.overflow. LLVM considers these - // to be the canonical form. It will attempt to reform llvm.usub.with.overflow - // in the backend if profitable. - let sub = self.sub(lhs, rhs); - let cmp = self.icmp(IntPredicate::IntULT, lhs, rhs); - return (sub, cmp); + if !signed { + match oop { + OverflowOp::Sub => { + // Emit sub and icmp instead of llvm.usub.with.overflow. LLVM considers these + // to be the canonical form. It will attempt to reform llvm.usub.with.overflow + // in the backend if profitable. + let sub = self.sub(lhs, rhs); + let cmp = self.icmp(IntPredicate::IntULT, lhs, rhs); + return (sub, cmp); + } + OverflowOp::Add => { + // Like with sub above, using icmp is the preferred form. See + // <https://rust-lang.zulipchat.com/#narrow/channel/187780-t-compiler.2Fllvm/topic/.60uadd.2Ewith.2Eoverflow.60.20.28again.29/near/533041085> + let add = self.add(lhs, rhs); + let cmp = self.icmp(IntPredicate::IntULT, add, lhs); + return (add, cmp); + } + OverflowOp::Mul => {} + } } let oop_str = match oop { | 
