[Bug target/67089] New: [4.8/4.9/5/6 Regression] Integer overflow checks not optimized on x86/x86_64

2015-08-01 Thread m.mukovnikov at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67089

Bug ID: 67089
   Summary: [4.8/4.9/5/6 Regression] Integer overflow checks not
optimized on x86/x86_64
   Product: gcc
   Version: 5.2.1
Status: UNCONFIRMED
  Severity: minor
  Priority: P3
 Component: target
  Assignee: unassigned at gcc dot gnu.org
  Reporter: m.mukovnikov at gmail dot com
  Target Milestone: ---

Starting from 4.8.3, gcc does not optimize integer overflow and underflow
checks inserting a redundant cmp instruction in both 32-bit and 64-bit modes.
Having git-bisected the revisions, I found out r204088 (by pr58779) had added
such behavior.

--- example ---
extern void underflow(void) __attribute__((noreturn));
unsigned sub(unsigned a, unsigned b)
{
unsigned r = a - b;
if (r > a) underflow();
return r;
}
 gcc-4.8.2 -O1 
sub(unsigned int, unsigned int):
movl%edi, %eax
subl%esi, %eax /* CF is set on overflow */
jae .L4/* jae = jnb = jnc = 73h */
subq$8, %rsp
callunderflow()
.L4:
rep; ret
 gcc-4.8.3 -O1 
sub(unsigned int, unsigned int):
movl%edi, %eax
subl%esi, %eax
cmpl%eax, %edi  /* absolutely redundant */
jnb .L4
subq$8, %rsp
callunderflow()
.L4:
rep ret
---


[Bug target/67089] [4.8/4.9/5/6 Regression] Integer overflow checks not optimized on x86/x86_64

2015-08-03 Thread m.mukovnikov at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67089

--- Comment #2 from Mike  ---
(In reply to Uroš Bizjak from comment #1)
> We shouldn't do this, and it reflected in PR58779.
But can't we improve the logic to satisfy both pr58779 and pr67089? The
absolute metric is code quality, and with all due respect, the code can be
better in this very case.