rustc generates badly optimized for wrapping_div #34634
Closed
Description
pub fn f(x: i32, y: i32) -> i32 {
x.wrapping_div(y)
}
Gives:
_ZN8rust_out1f17h164f16efff59de66E:
pushq %rax
.Ltmp0:
cmpl $-2147483648, %edi
jne .LBB0_2
movl $-2147483648, %eax
cmpl $-1, %esi
je .LBB0_5
.LBB0_2:
cmpl $-1, %esi
je .LBB0_6
testl %esi, %esi
jne .LBB0_4
leaq panic_loc7436(%rip), %rdi
callq _ZN4core9panicking5panic17h907815f47e914305E@PLT
.LBB0_6:
cmpl $-2147483648, %edi
je .LBB0_7
.LBB0_4:
movl %edi, %eax
cltd
idivl %esi
.LBB0_5:
popq %rcx
retq
.LBB0_7:
leaq panic_loc7440(%rip), %rdi
callq _ZN4core9panicking5panic17h907815f47e914305E@PLT
Specifically, .LBB0_7 is unreachable, but LLVM can't quite figure that out. It's probably possible to write wrapping_div in a way which avoids this problem.
Metadata
Assignees
Labels
Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlArea: Code generationCategory: An issue proposing an enhancement or a PR with one.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Issue: Problems and improvements with respect to performance of generated code.