From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23909 invoked by alias); 3 Jan 2010 06:04:40 -0000 Received: (qmail 20692 invoked by uid 48); 3 Jan 2010 06:04:26 -0000 Date: Sun, 03 Jan 2010 06:04:00 -0000 Subject: [Bug rtl-optimization/42586] New: load-modify-store on x86 should be single instruction X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "andi-gcc at firstfloor dot org" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-01/txt/msg00215.txt.bz2 Continuation from 42585 >>From one of the examples of http://embed.cs.utah.edu/embarrassing/dec_09/harvest/gcc-head_llvm-gcc-head/ struct _fat_ptr { unsigned char *curr; unsigned char *base; unsigned char *last_plus_one; }; int Cyc_string_ungetc (int ignore, struct _fat_ptr *sptr); int Cyc_string_ungetc (int ignore, struct _fat_ptr *sptr) { struct _fat_ptr *_T0; struct _fat_ptr *_T1; struct _fat_ptr _T2; int _T3; struct _fat_ptr _ans; int _change; { _T0 = sptr; _T1 = sptr; _T2 = *sptr; _T3 = -1; _ans = _T2; _change = -1; _ans.curr += 4294967295U; *sptr = _ans; return (0); } } when compiled with -O2 -m32 on 4.5.0 20091219 generates Cyc_string_ungetc: subl $32, %esp movl 40(%esp), %eax movl (%eax), %edx subl $1, %edx movl %edx, (%eax) xorl %eax, %eax addl $32, %esp ret Apart from the useless stack frame manipulation it should use subl $1,(%eax) not load-modify-store as recommended in the Intel/AMD optimization manuals for any modern CPU. I experimented with different -mtune=s (thinking it was maybe optimizing for Pentium5 where this made sense), but that didn't help (apart from turning the subl into a decl). The code snippet above is for -mtune=generic -m32 -- Summary: load-modify-store on x86 should be single instruction Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: andi-gcc at firstfloor dot org GCC host triplet: x86_64-linux GCC target triplet: x86_64-linux -m32 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42586