From 0764a0d275c79d8a81332818e7ff6c6aa6b3a312 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 17 Apr 2019 15:28:39 +0200 Subject: [PATCH] re PR middle-end/90095 (wrong code with -Os -fno-tree-bit-ccp) PR middle-end/90095 * internal-fn.c (expand_mul_overflow): Don't set SUBREG_PROMOTED_VAR_P on lowpart SUBREGs. * gcc.dg/pr90095-1.c: New test. * gcc.dg/pr90095-2.c: New test. From-SVN: r270410 --- gcc/ChangeLog | 6 ++++++ gcc/internal-fn.c | 17 ++--------------- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/pr90095-1.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/pr90095-2.c | 5 +++++ 5 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr90095-1.c create mode 100644 gcc/testsuite/gcc.dg/pr90095-2.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3820fae8ee7..0e9aeb4a91e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2019-04-17 Jakub Jelinek + + PR middle-end/90095 + * internal-fn.c (expand_mul_overflow): Don't set SUBREG_PROMOTED_VAR_P + on lowpart SUBREGs. + 2019-04-17 Claudiu Zissulescu * config/arc/arc.c (arc_init): Format diagnostic string. diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index 4f2ef45a0ff..04081f36c4d 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -1753,22 +1753,9 @@ expand_mul_overflow (location_t loc, tree lhs, tree arg0, tree arg1, /* If both op0 and op1 are sign (!uns) or zero (uns) extended from hmode to mode, the multiplication will never overflow. We can do just one hmode x hmode => mode widening multiplication. */ - rtx lopart0s = lopart0, lopart1s = lopart1; - if (GET_CODE (lopart0) == SUBREG) - { - lopart0s = shallow_copy_rtx (lopart0); - SUBREG_PROMOTED_VAR_P (lopart0s) = 1; - SUBREG_PROMOTED_SET (lopart0s, uns ? SRP_UNSIGNED : SRP_SIGNED); - } - if (GET_CODE (lopart1) == SUBREG) - { - lopart1s = shallow_copy_rtx (lopart1); - SUBREG_PROMOTED_VAR_P (lopart1s) = 1; - SUBREG_PROMOTED_SET (lopart1s, uns ? SRP_UNSIGNED : SRP_SIGNED); - } tree halfstype = build_nonstandard_integer_type (hprec, uns); - ops.op0 = make_tree (halfstype, lopart0s); - ops.op1 = make_tree (halfstype, lopart1s); + ops.op0 = make_tree (halfstype, lopart0); + ops.op1 = make_tree (halfstype, lopart1); ops.code = WIDEN_MULT_EXPR; ops.type = type; rtx thisres diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 937057421e4..3fb6092b3bf 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2019-04-17 Jakub Jelinek + + PR middle-end/90095 + * gcc.dg/pr90095-1.c: New test. + * gcc.dg/pr90095-2.c: New test. + 2019-04-17 Thomas Schwinge PR fortran/90048 diff --git a/gcc/testsuite/gcc.dg/pr90095-1.c b/gcc/testsuite/gcc.dg/pr90095-1.c new file mode 100644 index 00000000000..03968ba7419 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr90095-1.c @@ -0,0 +1,18 @@ +/* PR middle-end/90095 */ +/* { dg-do run } */ +/* { dg-options "-Os -fno-tree-bit-ccp" } */ + +unsigned long long a; +unsigned int b; + +int +main () +{ + unsigned int c = 255, d = c |= b; + if (__CHAR_BIT__ != 8 || __SIZEOF_INT__ != 4 || __SIZEOF_LONG_LONG__ != 8) + return 0; + d = __builtin_mul_overflow (-(unsigned long long) d, (unsigned char) - c, &a); + if (d != 0) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pr90095-2.c b/gcc/testsuite/gcc.dg/pr90095-2.c new file mode 100644 index 00000000000..43f67e1273f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr90095-2.c @@ -0,0 +1,5 @@ +/* PR middle-end/90095 */ +/* { dg-do run } */ +/* { dg-options "-Os -fno-tree-bit-ccp -fno-split-wide-types" } */ + +#include "pr90095-1.c" -- 2.30.2