Bug 30967 - Extra sign/zero extend with word comparison result
Summary: Extra sign/zero extend with word comparison result
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: ---
Assignee: Segher Boessenkool
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2007-02-26 11:41 UTC by Andrew Pinski
Modified: 2015-05-16 17:57 UTC (History)
3 users (show)

See Also:
Host:
Target: powerpc64-apple-darwin
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-05-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2007-02-26 11:41:58 UTC
Testcase:
int f1(int a, int b)
{
  return a == b;
}

------
We produce right now:
_f1:
        xor r4,r3,r4
        cntlzw r4,r4  <--- sign never 1
        srwi r4,r4,5  <--- upper bits defined as 0
        extsw r3,r4
        blr

The sign extend is incorrect as r4's sign will never be 1 and all the upper bits will always be zero because of srwi.
we have the same issue if the return value is unsigned int also in that there is an extra zero extend.

This is even with -fsee.
Comment 1 Andrew Pinski 2007-02-26 23:20:57 UTC
I think this is a case where combine (and other passes) don't know that eq is always signed extended (when the true is not -1):
(insn 9 8 10 2 (set (reg:SI 123)
        (eq:SI (reg:SI 3 3 [ a ])
            (reg:SI 4 4 [ b ]))) 471 {*eqsi} (nil)
    (expr_list:REG_DEAD (reg:DI 3 3 [ a ])
        (expr_list:REG_DEAD (reg:DI 4 4 [ b ])
            (nil))))

(note 10 9 16 2 NOTE_INSN_DELETED)

(insn 16 10 22 2 (set (reg/i:DI 3 3 [ <result> ])
        (sign_extend:DI (reg:SI 123))) 27 {*rs6000.md:393} (insn_list:REG_DEP_TRUE 9 (nil))
    (expr_list:REG_DEAD (reg:SI 123)
        (nil)))
Comment 2 Andrew Pinski 2010-03-02 19:14:19 UTC
Still happens on the trunk as of today.
Comment 3 Segher Boessenkool 2015-05-13 12:44:42 UTC
Still happening.  The problem now is that eq:SI is costed as one insn
(which it is not), but eq:DI as three.
Comment 4 Segher Boessenkool 2015-05-13 19:14:39 UTC
Author: segher
Date: Wed May 13 19:14:07 2015
New Revision: 223174

URL: https://gcc.gnu.org/viewcvs?rev=223174&root=gcc&view=rev
Log:
	PR rtl-optimization/30967
	* config/rs6000/rs6000.c (rs6000_rtx_costs): Don't consider
	destination mode for the cost of scc patterns.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/rs6000/rs6000.c
Comment 5 Segher Boessenkool 2015-05-13 19:51:55 UTC
Fixed on trunk.  No backport planned.
Comment 6 Segher Boessenkool 2015-05-16 17:57:27 UTC
Author: segher
Date: Sat May 16 17:56:55 2015
New Revision: 223250

URL: https://gcc.gnu.org/viewcvs?rev=223250&root=gcc&view=rev
Log:
	Backport from mainline
	2015-05-13  Segher Boessenkool  <segher@kernel.crashing.org>

	PR rtl-optimization/30967
	* config/rs6000/rs6000.c (rs6000_rtx_costs): Don't consider
	destination mode for the cost of scc patterns.

Modified:
    branches/gcc-5-branch/gcc/ChangeLog
    branches/gcc-5-branch/gcc/config/rs6000/rs6000.c