https://bugs.llvm.org/show_bug.cgi?id=35709
Bug ID: 35709
Summary: Missed optimization in math expression: (x+x)/x == 2
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: LLVM Codegen
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
clang (trunk) with '-O3 -std=c++17 -ffast-math -funsafe-math-optimizations' for
this code:
int test(int x)
{
return (x+x)/x;
}
generates:
test(int): # @test(int)
lea eax, [rdi + rdi]
cdq
idiv edi
ret
Why? In this case we can return simply 2. Because there are only two corner
cases: when x is 0 and we have division by zero (it's UB), and when x+x is
integer overflow (it's also UB).
So we can simply optimize it. There are a lot of similar cases.
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs