From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 47DFB3846079 for ; Wed, 22 Jul 2020 08:38:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 47DFB3846079 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=richard.sandiford@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E8D19101E for ; Wed, 22 Jul 2020 01:38:17 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 906703F66F for ; Wed, 22 Jul 2020 01:38:17 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Re: [PATCH 2/3] expmed: Fix possible use of NULL_RTX return value from emit_store_flag References: <20200721181715.frr5xycz7wvxxkym@jozef-acer-manjaro> <20200721182649.mrhv4mk2qgigs7tv@jozef-acer-manjaro> Date: Wed, 22 Jul 2020 09:38:15 +0100 In-Reply-To: <20200721182649.mrhv4mk2qgigs7tv@jozef-acer-manjaro> (Jozef Lawrynowicz's message of "Tue, 21 Jul 2020 19:26:49 +0100") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jul 2020 08:38:19 -0000 Jozef Lawrynowicz writes: > diff --git a/gcc/expmed.c b/gcc/expmed.c > index e7c03fbf92c..d3a1735d39e 100644 > --- a/gcc/expmed.c > +++ b/gcc/expmed.c > @@ -4086,9 +4086,12 @@ expand_sdiv_pow2 (scalar_int_mode mode, rtx op0, HOST_WIDE_INT d) > { > temp = gen_reg_rtx (mode); > temp = emit_store_flag (temp, LT, op0, const0_rtx, mode, 0, 1); > - temp = expand_binop (mode, add_optab, temp, op0, NULL_RTX, > - 0, OPTAB_LIB_WIDEN); > - return expand_shift (RSHIFT_EXPR, mode, temp, logd, NULL_RTX, 0); > + if (temp != NULL_RTX) > + { > + temp = expand_binop (mode, add_optab, temp, op0, NULL_RTX, > + 0, OPTAB_LIB_WIDEN); > + return expand_shift (RSHIFT_EXPR, mode, temp, logd, NULL_RTX, 0); > + } > } > > if (HAVE_conditional_move > @@ -4122,17 +4125,20 @@ expand_sdiv_pow2 (scalar_int_mode mode, rtx op0, HOST_WIDE_INT d) > > temp = gen_reg_rtx (mode); > temp = emit_store_flag (temp, LT, op0, const0_rtx, mode, 0, -1); > - if (GET_MODE_BITSIZE (mode) >= BITS_PER_WORD > - || shift_cost (optimize_insn_for_speed_p (), mode, ushift) > - > COSTS_N_INSNS (1)) > - temp = expand_binop (mode, and_optab, temp, gen_int_mode (d - 1, mode), > - NULL_RTX, 0, OPTAB_LIB_WIDEN); > - else > - temp = expand_shift (RSHIFT_EXPR, mode, temp, > - ushift, NULL_RTX, 1); > - temp = expand_binop (mode, add_optab, temp, op0, NULL_RTX, > - 0, OPTAB_LIB_WIDEN); > - return expand_shift (RSHIFT_EXPR, mode, temp, logd, NULL_RTX, 0); > + if (temp != NULL_RTX) > + { > + if (GET_MODE_BITSIZE (mode) >= BITS_PER_WORD > + || shift_cost (optimize_insn_for_speed_p (), mode, ushift) > + > COSTS_N_INSNS (1)) > + temp = expand_binop (mode, and_optab, temp, gen_int_mode (d - 1, mode), Long line. OK otherwise, thanks. I guess these failed attempts will leave a few unused temporary registers around (from the gen_reg_rtxes) but it's going to be hard to avoid that in a clean way. Richard > + NULL_RTX, 0, OPTAB_LIB_WIDEN); > + else > + temp = expand_shift (RSHIFT_EXPR, mode, temp, > + ushift, NULL_RTX, 1); > + temp = expand_binop (mode, add_optab, temp, op0, NULL_RTX, > + 0, OPTAB_LIB_WIDEN); > + return expand_shift (RSHIFT_EXPR, mode, temp, logd, NULL_RTX, 0); > + } > } > > label = gen_label_rtx ();