From patchwork Wed Jun 30 18:45:31 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 57446 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 371C6B6EF2 for ; Thu, 1 Jul 2010 04:45:47 +1000 (EST) Received: (qmail 31550 invoked by alias); 30 Jun 2010 18:45:42 -0000 Received: (qmail 31534 invoked by uid 22791); 30 Jun 2010 18:45:40 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mail-pw0-f47.google.com (HELO mail-pw0-f47.google.com) (209.85.160.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 30 Jun 2010 18:45:33 +0000 Received: by pwi10 with SMTP id 10so435992pwi.20 for ; Wed, 30 Jun 2010 11:45:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.142.2.11 with SMTP id 11mr10763820wfb.51.1277923531337; Wed, 30 Jun 2010 11:45:31 -0700 (PDT) Received: by 10.142.231.8 with HTTP; Wed, 30 Jun 2010 11:45:31 -0700 (PDT) In-Reply-To: References: <20100629191246.GA2770@intel.com> Date: Wed, 30 Jun 2010 11:45:31 -0700 Message-ID: Subject: Re: RFC: PR rtl-optimization/44695: [4.6 Regression] ice in simplify_subreg, at simplify-rtx.c:5117 From: "H.J. Lu" To: Paolo Bonzini Cc: gcc-patches@gcc.gnu.org X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org On Wed, Jun 30, 2010 at 4:53 AM, Paolo Bonzini wrote: > On 06/29/2010 09:12 PM, H.J. Lu wrote: >> >> After revision 161329, x86 backend may generate: >> >> (ior:HI (ashift:HI (zero_extend:HI (umod:QI (reg:HI 68) >>                 (reg:QI 61 [ D.2750 ]))) >>         (const_int 8 [0x8])) >>     (zero_extend:HI (udiv:QI (reg:HI 68) >>             (reg:QI 61 [ D.2750 ])))) >> >> combine calls simplify_subreg and leads to >> >> #2  0x00000000009ad621 in simplify_subreg (outermode=HImode, >>     op=0x7ffff7facd40, innermode=QImode, byte=0) >>     at /space/rguenther/src/svn/trunk/gcc/simplify-rtx.c:5116 >> 5116      gcc_assert (GET_MODE (op) == innermode >> 5117                  || GET_MODE (op) == VOIDmode); >> (gdb) call debug_rtx (op) >> (reg:HI 68) >> >> This patch adds simplify_gen_subreg_for_combine to deal with invalid >> combination of outermode, op and innermode generated by combine.  Any >> comments? > > I commented in the PR about the correct fix.  Sorry for not spotting it in > the review (I had a doubt, but in the end I didn't look it up and left the > final call to Uros...). > Here is a patch to change 8bit div/mod to HImode. OK for trunk? Thanks. diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index e361fd7..1bbb0dd 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -7364,15 +7364,18 @@ ;; Divide AX by r/m8, with result stored in ;; AL <- Quotient ;; AH <- Remainder +;; Change div/mod to HImode and extend the second argument to HImode +;; so that mode of div/mod matches with mode of arguments. Otherwise +;; combine may fail. (define_insn "divmodhiqi3" [(set (match_operand:HI 0 "register_operand" "=a") (ior:HI (ashift:HI - (zero_extend:HI - (mod:QI (match_operand:HI 1 "register_operand" "0") + (mod:HI (match_operand:HI 1 "register_operand" "0") + (sign_extend:HI (match_operand:QI 2 "nonimmediate_operand" "qm"))) (const_int 8)) - (zero_extend:HI (div:QI (match_dup 1) (match_dup 2))))) + (div:HI (match_dup 1) (sign_extend:HI (match_dup 2))))) (clobber (reg:CC FLAGS_REG))] "TARGET_QIMODE_MATH" "idiv{b}\t%2" @@ -7383,11 +7386,11 @@ [(set (match_operand:HI 0 "register_operand" "=a") (ior:HI (ashift:HI - (zero_extend:HI - (umod:QI (match_operand:HI 1 "register_operand" "0") + (umod:HI (match_operand:HI 1 "register_operand" "0") + (zero_extend:HI (match_operand:QI 2 "nonimmediate_operand" "qm"))) (const_int 8)) - (zero_extend:HI (udiv:QI (match_dup 1) (match_dup 2))))) + (udiv:HI (match_dup 1) (zero_extend:HI (match_dup 2))))) (clobber (reg:CC FLAGS_REG))] "TARGET_QIMODE_MATH" "div{b}\t%2" --- /dev/null 2010-06-16 10:11:06.602750711 -0700 +++ gcc/gcc/testsuite/gcc.dg/torture/pr44695.c 2010-06-29 11:49:12.186942482 -0700 @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +typedef unsigned char uint8_t; + +static uint8_t +safe_div_func_uint8_t_u_u (uint8_t ui1, uint8_t ui2) +{ + return ui2 ? ui2 : (ui1 / ui2); +} + +int +int81 (int x) +{ + return safe_div_func_uint8_t_u_u (1, 8 & x); +}