From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25857 invoked by alias); 8 Apr 2014 20:09:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 25845 invoked by uid 89); 8 Apr 2014 20:09:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: qmta10.emeryville.ca.mail.comcast.net Received: from qmta10.emeryville.ca.mail.comcast.net (HELO qmta10.emeryville.ca.mail.comcast.net) (76.96.30.17) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 08 Apr 2014 20:09:14 +0000 Received: from omta22.emeryville.ca.mail.comcast.net ([76.96.30.89]) by qmta10.emeryville.ca.mail.comcast.net with comcast id nSzb1n0051vN32cAAY9CUb; Tue, 08 Apr 2014 20:09:12 +0000 Received: from up.mrs.kithrup.com ([24.4.193.248]) by omta22.emeryville.ca.mail.comcast.net with comcast id nY9B1n00K5N1HX48iY9CNk; Tue, 08 Apr 2014 20:09:12 +0000 From: Mike Stump Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: shift/extract SHIFT_COUNT_TRUNCATED combine bug Date: Tue, 08 Apr 2014 20:09:00 -0000 Message-Id: <8F47DDC3-F9FE-4E94-90F7-3A16A3FD47CE@comcast.net> Cc: Richard Sandiford , Eric Botcazou To: GCC Patches Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) X-IsSubscribed: yes X-SW-Source: 2014-04/txt/msg00395.txt.bz2 Something broke in the compiler to cause combine to incorrectly optimize: (insn 12 11 13 3 (set (reg:SI 604 [ D.6102 ]) (lshiftrt:SI (subreg/s/u:SI (reg/v:DI 601 [ x ]) 0) (reg:SI 602 [ D.6103 ]))) t.c:47 4436 {lshrsi3} (expr_list:REG_DEAD (reg:SI 602 [ D.6103 ]) (nil))) (insn 13 12 14 3 (set (reg:SI 605) (and:SI (reg:SI 604 [ D.6102 ]) (const_int 1 [0x1]))) t.c:47 3658 {andsi3} (expr_list:REG_DEAD (reg:SI 604 [ D.6102 ]) (nil))) (insn 14 13 15 3 (set (reg:DI 599 [ D.6102 ]) (zero_extend:DI (reg:SI 605))) t.c:47 4616 {zero_extendsidi2} (expr_list:REG_DEAD (reg:SI 605) (nil))) into: (insn 11 10 12 3 (set (reg:SI 602 [ D.6103 ]) (not:SI (subreg:SI (reg:DI 595 [ D.6102 ]) 0))) t.c:47 3732 {one_cm= plsi2} (expr_list:REG_DEAD (reg:DI 595 [ D.6102 ]) (nil))) (note 12 11 13 3 NOTE_INSN_DELETED) (note 13 12 14 3 NOTE_INSN_DELETED) (insn 14 13 15 3 (set (reg:DI 599 [ D.6102 ]) (zero_extract:DI (reg/v:DI 601 [ x ]) (const_int 1 [0x1]) (reg:SI 602 [ D.6103 ]))) t.c:47 4668 {c2_extzvdi} (expr_list:REG_DEAD (reg:SI 602 [ D.6103 ]) (nil))) This shows up in: FAIL: gcc.c-torture/execute/builtin-bitops-1.c execution, -Og -g for me. diff --git a/gcc/combine.c b/gcc/combine.c index 708691f..c1f50ff 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -7245,6 +7245,18 @@ make_extraction (enum machine_mode mode, rtx inner, = HOST_WIDE_INT pos, extraction_mode =3D insn.field_mode; } =20 + /* On a SHIFT_COUNT_TRUNCATED machine, we can't promote the mode of + the extract to a larger size on a variable extract, as previously + the position might have been optimized to change a bit of the + index of the starting bit that would have been ignored before, + but, with a larger mode, will then not be. If we wanted to do + this, we'd have to mask out those bits or prove that those bits + are 0. */ + if (SHIFT_COUNT_TRUNCATED + && pos_rtx + && GET_MODE_BITSIZE (extraction_mode) > GET_MODE_BITSIZE (mode)) + extraction_mode =3D mode; + /* Never narrow an object, since that might not be safe. */ =20 if (mode !=3D VOIDmode is sufficient to never widen variable extracts on SHIFT_COUNT_TRUNCATED mac= hines. So, the question is, how did people expect this to work? I didn=92= t spot what changed recently to cause the bad code-gen. The optimization o= f sub into not is ok, despite how funny it looks, because is feeds into ext= ract which we know by SHIFT_COUNT_TRUNCATED is safe. Is the patch a reasonable way to fix this?