From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7609 invoked by alias); 14 May 2012 22:49:31 -0000 Received: (qmail 7539 invoked by uid 22791); 14 May 2012 22:49:27 -0000 X-SWARE-Spam-Status: No, hits=-3.6 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 May 2012 22:49:11 +0000 From: "meadori at codesourcery dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug rtl-optimization/53352] New: Incorrect CSE optimization on RTL expressions with a paradoxical subreg Date: Mon, 14 May 2012 22:52:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: rtl-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: meadori at codesourcery dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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: 2012-05/txt/msg01479.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53352 Bug #: 53352 Summary: Incorrect CSE optimization on RTL expressions with a paradoxical subreg Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: rtl-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: meadori@codesourcery.com Host: GNU/Linux Target: arm-none-linux-gnueabi The attached reproduction case exhibits what I believe to be a bug in the CSE pass. The problem can be reproduced from the mainline at r187470. The compiler was built for arm-none-linux-gnueabi and the reproduction case was compiled with -O3. Out of the gate the expanded RTL of interest looks like: (insn 12 11 13 3 (set (reg:SI 140) (lshiftrt:SI (reg/v:SI 135 [ tmp1 ]) (const_int 16 [0x10]))) (nil)) (insn 13 12 14 3 (set (reg:QI 141) (subreg:QI (reg:SI 140) 0)) (nil)) (insn 14 13 15 3 (set (reg:SI 142) (subreg:SI (reg:QI 141) 0)) (nil)) (insn 15 14 16 3 (set (reg:SI 134 [ tmp1$2 ]) (and:SI (reg:SI 142) (const_int 255 [0xff]))) (nil)) ... (insn 29 28 30 3 (set (reg:SI 0 r0) (const_int 0 [0])) (nil)) after "cse1" things look like: (insn 12 11 13 2 (set (reg:SI 140) (const_int 65280 [0xff00])) (nil)) (insn 13 12 14 2 (set (reg:QI 141) (subreg:QI (reg:SI 140) 0)) (expr_list:REG_EQUAL (const_int 0 [0]) (nil))) ;; This is *not* equal to zero because the upper ;; two bytes are undefined. (insn 14 13 15 2 (set (reg:SI 142) (subreg:SI (reg:QI 141) 0)) (expr_list:REG_EQUAL (const_int 0 [0]) (nil))) (insn 15 14 16 2 (set (reg:SI 134 [ tmp1$2 ]) (reg:SI 142)) (expr_list:REG_EQUAL (const_int 0 [0]) (nil))) ... (insn 29 28 30 2 (set (reg:SI 0 r0) (reg:SI 142)) (expr_list:REG_EQUAL (const_int 0 [0]) (nil))) I believe the REG_EQUAL note on the set involving a paradoxical subreg is incorrect. It eventually causes 0xFF00 to be passed to the function 'foo'. I doesn't look like 'equiv_constant' handles the paradoxical subreg case correctly. I fixed it as follows and am testing the patch now: Index: gcc/cse.c =================================================================== --- gcc/cse.c (revision 187470) +++ gcc/cse.c (working copy) @@ -3786,8 +3786,11 @@ } } - /* Otherwise see if we already have a constant for the inner REG. */ + /* Otherwise see if we already have a constant for the inner REG. + Don't bother with paradoxical subregs because we have no way + of knowing what the upper bytes are. */ if (REG_P (SUBREG_REG (x)) + && (GET_MODE_SIZE (mode) <= GET_MODE_SIZE (imode)) && (new_rtx = equiv_constant (SUBREG_REG (x))) != 0) return simplify_subreg (mode, new_rtx, imode, SUBREG_BYTE (x));