Bug 21237 - [4.0 Regression] unnecessary __cmpdi2 usage?
Summary: [4.0 Regression] unnecessary __cmpdi2 usage?
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.0.1
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2005-04-26 16:44 UTC by Pawel Sikora
Modified: 2005-05-14 00:48 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc-*-*
Build:
Known to work: 3.3.3 4.1.0
Known to fail: 4.0.0
Last reconfirmed: 2005-04-26 23:07:07


Attachments
testcase (94.90 KB, application/octet-stream)
2005-04-26 16:46 UTC, Pawel Sikora
Details
asm dump (28.71 KB, application/octet-stream)
2005-04-26 16:48 UTC, Pawel Sikora
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Pawel Sikora 2005-04-26 16:44:59 UTC
in function cryptcompress_truncate() from reiserfs4 patch  
compiler uses __cmpdi2 for old_size vs new_size (64 bit) comparision:  
  
 result = (old_size < new_size ? cryptcompress_append_hole(inode, new_size) :  
    prune_cryptcompress(inode, new_size, update_sd, aidx));  
  
in another case for simple foo() method gcc inlines __cmpdi2 equivalent:  
  
int foo(long long x, long long y) { return (x < y); }  
  
foo:    cmpw 7,5,3  
        li 0,0  
        bgt- 7,.L3  
        cmplw 6,6,4  
        beq- 7,.L6  
.L2:    mr 3,0  
        blr  
.L6:    ble- 6,.L2  
.L3:    li 0,1  
        mr 3,0  
        blr  
  
what decides which variant is chosen? 
is it possible to force inlining? 
 
# gcc-4.0.0+pr20973+pr21173
Comment 1 Pawel Sikora 2005-04-26 16:46:47 UTC
Created attachment 8745 [details]
testcase
Comment 2 Pawel Sikora 2005-04-26 16:48:38 UTC
Created attachment 8746 [details]
asm dump
Comment 3 Andrew Pinski 2005-04-26 23:07:06 UTC
Confirmed, reduced testcase:
int g(long long a, long long b)
{
  a -= b;
  return !a;
}

You were looking at the wrong function as we inline a function into cryptcompress_truncate which 
causes this.

One issue is when we go and expand (a - b) == 0, we expand it to cmpdi for some reason instead of 
inlining cmpdi.
Comment 4 Pawel Sikora 2005-04-28 18:04:12 UTC
__cmdi2 isn't used with -O0 but it is with -O1. 
Comment 5 David Edelsohn 2005-05-07 20:24:45 UTC
i386 synthesizes a DImode compare for 32-bit mode in target-dependent code. 
PowerPC probably needs to do the same.
Comment 6 GCC Commits 2005-05-09 14:46:26 UTC
Subject: Bug 21237

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	dje@gcc.gnu.org	2005-05-09 14:45:59

Modified files:
	gcc            : ChangeLog 

Log message:
	PR middle-end/21237
	* dojump.c (do_jump, MINUS_EXPR): Build NE_EXPR and fall through
	to NE_EXPR case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.8673&r2=2.8674

Comment 7 GCC Commits 2005-05-14 00:46:20 UTC
Subject: Bug 21237

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	dje@gcc.gnu.org	2005-05-14 00:46:01

Modified files:
	gcc            : ChangeLog dojump.c 

Log message:
	PR middle-end/21237
	* dojump.c (do_jump, MINUS_EXPR): Build NE_EXPR and fall through
	to NE_EXPR case.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=2.7592.2.244&r2=2.7592.2.245
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/dojump.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.37&r2=1.37.8.1

Comment 8 David Edelsohn 2005-05-14 00:48:53 UTC
backported patch