From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id D41C4385842B; Fri, 4 Nov 2022 08:30:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D41C4385842B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667550626; bh=x2T5dfJMzSpiqqPa1PyMliVXXG7iIfZllhAMU3+6RqI=; h=From:To:Subject:Date:From; b=DWAYo0Ob/hnMrmODJxbrpUkZm/XMpdoinuDlFUJEvhJtGIgDGtwuUE0dx4Ods/8jl XYGh+GqCe73rFDrcmLgwNlVXJkUTI8g+CECzKXCrU98uHJMllXWzLyKQ0yLy2Oci6d /3LoBaY+E3SGA2VEVWTnWzixEhH/r07JjEgFQjRw= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10353] expand: Fix up expand_cond_expr_using_cmove [PR106030] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 732e2315e6782bfc93241027f01cd3dfbdb5269c X-Git-Newrev: d9b72d8d03134813d5fa84cffb190027fd29f6d6 Message-Id: <20221104083026.D41C4385842B@sourceware.org> Date: Fri, 4 Nov 2022 08:30:26 +0000 (GMT) List-Id: https://gcc.gnu.org/g:d9b72d8d03134813d5fa84cffb190027fd29f6d6 commit r11-10353-gd9b72d8d03134813d5fa84cffb190027fd29f6d6 Author: Jakub Jelinek Date: Tue Jun 21 11:38:59 2022 +0200 expand: Fix up expand_cond_expr_using_cmove [PR106030] If expand_cond_expr_using_cmove can't find a cmove optab for a particular mode, it tries to promote the mode and perform the cmove in the promoted mode. The testcase in the patch ICEs on arm because in that case we pass temp which has the promoted mode (SImode) as target to expand_operands where the operands have the non-promoted mode (QImode). Later on the function uses paradoxical subregs: if (GET_MODE (op1) != mode) op1 = gen_lowpart (mode, op1); if (GET_MODE (op2) != mode) op2 = gen_lowpart (mode, op2); to change the operand modes. The following patch fixes it by passing NULL_RTX as target if it has promoted mode. 2022-06-21 Jakub Jelinek PR middle-end/106030 * expr.c (expand_cond_expr_using_cmove): Pass NULL_RTX instead of temp to expand_operands if mode has been promoted. * gcc.c-torture/compile/pr106030.c: New test. (cherry picked from commit 2df1df945fac85d7b3d084001414a66a2709d8fe) Diff: --- gcc/expr.c | 3 ++- gcc/testsuite/gcc.c-torture/compile/pr106030.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/gcc/expr.c b/gcc/expr.c index baf48ea7148..9a2bb29abba 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -8566,7 +8566,8 @@ expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED, expanding_cond_expr_using_cmove = true; start_sequence (); expand_operands (treeop1, treeop2, - temp, &op1, &op2, EXPAND_NORMAL); + mode == orig_mode ? temp : NULL_RTX, &op1, &op2, + EXPAND_NORMAL); if (TREE_CODE (treeop0) == SSA_NAME && (srcstmt = get_def_for_expr_class (treeop0, tcc_comparison))) diff --git a/gcc/testsuite/gcc.c-torture/compile/pr106030.c b/gcc/testsuite/gcc.c-torture/compile/pr106030.c new file mode 100644 index 00000000000..7514b348ff9 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr106030.c @@ -0,0 +1,16 @@ +/* PR middle-end/106030 */ + +int a, b, c; + +char +foo (int x, int y) +{ + return x * y; +} + +void +bar (void) +{ + char d = (foo <= b) * a; + c = foo (2 != bar, d); +}