[llvm-bugs] [Bug 31028] New: Too much division
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Nov 15 13:58:34 PST 2016
https://llvm.org/bugs/show_bug.cgi?id=31028
Bug ID: 31028
Summary: Too much division
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: filcab at gmail.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Mentioned by Tillmann Karras.
The x86 backend emits too many idiv instructions for this function:
#include <inttypes.h>
int32_t f(int32_t a, int32_t b) {
if (a % b == 42)
return a / b;
return 3;
}
Codegen:
x86-64 (annotated):
patatino(int, int): # @patatino(int, int)
mov ecx, edi
mov eax, ecx
cdq
idiv esi # This gets us quotient in rax, remainder in rdx
mov eax, 3
cmp edx, 42
jne .LBB0_2
mov eax, ecx
cdq
idiv esi # This is useless since we already had the result
before
.LBB0_2:
ret
arm64 target (Only one divide. Different trick ("multiply-subtract"
instruction: msub)):
patatino(int, int): // @patatino(int, int)
mov w8, w0
sdiv w0, w8, w1
msub w8, w0, w1, w8
cmp w8, #42 // =42
b.eq .LBB0_2
orr w0, wzr, #0x3
.LBB0_2:
ret
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161115/3a486006/attachment.html>
More information about the llvm-bugs
mailing list