summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2017-10-13 17:26:28 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2017-10-13 17:26:28 +0000
commit17eb6079cc792114d88763dd9bb49d0a4a47556c (patch)
tree3a6c235f0cfe4c7ee293ac2ce30b9a99b24fd4ea
parent241db3e47d69e3381daa69ce872d2130aa463a26 (diff)
PR target/82274
* internal-fn.c (expand_mul_overflow): If both operands have the same highpart of -1 or 0 and the topmost bit of lowpart is different, overflow is if res <= 0 rather than res < 0. * libgcc2.c (__mulvDI3): If both operands have the same highpart of -1 and the topmost bit of lowpart is 0, multiplication overflows even if both lowparts are 0. * gcc.dg/pr82274-1.c: New test. * gcc.dg/pr82274-2.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@253735 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/internal-fn.c6
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/pr82274-1.c16
-rw-r--r--gcc/testsuite/gcc.dg/pr82274-2.c26
-rw-r--r--libgcc/ChangeLog7
-rw-r--r--libgcc/libgcc2.c3
7 files changed, 63 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4af6fec47150..d7d3034b38ff 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,10 @@
2017-10-13 Jakub Jelinek <jakub@redhat.com>
+ PR target/82274
+ * internal-fn.c (expand_mul_overflow): If both operands have
+ the same highpart of -1 or 0 and the topmost bit of lowpart
+ is different, overflow is if res <= 0 rather than res < 0.
+
PR target/82524
* config/i386/i386.md (addqi_ext_1, andqi_ext_1,
*andqi_ext_1_cc, *<code>qi_ext_1, *xorqi_ext_1_cc): Change
diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c
index 75fe027f7b27..e97f0d80a434 100644
--- a/gcc/internal-fn.c
+++ b/gcc/internal-fn.c
@@ -1754,8 +1754,8 @@ expand_mul_overflow (location_t loc, tree lhs, tree arg0, tree arg1,
}
/* At this point hipart{0,1} are both in [-1, 0]. If they are
- the same, overflow happened if res is negative, if they are
- different, overflow happened if res is positive. */
+ the same, overflow happened if res is non-positive, if they
+ are different, overflow happened if res is positive. */
if (op0_sign != 1 && op1_sign != 1 && op0_sign != op1_sign)
emit_jump (hipart_different);
else if (op0_sign == 1 || op1_sign == 1)
@@ -1763,7 +1763,7 @@ expand_mul_overflow (location_t loc, tree lhs, tree arg0, tree arg1,
NULL_RTX, NULL, hipart_different,
PROB_EVEN);
- do_compare_rtx_and_jump (res, const0_rtx, LT, false, mode,
+ do_compare_rtx_and_jump (res, const0_rtx, LE, false, mode,
NULL_RTX, NULL, do_error,
PROB_VERY_UNLIKELY);
emit_jump (done_label);
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8139d0df9af4..0928fcb65af4 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,9 @@
2017-10-13 Jakub Jelinek <jakub@redhat.com>
+ PR target/82274
+ * gcc.dg/pr82274-1.c: New test.
+ * gcc.dg/pr82274-2.c: New test.
+
PR target/82524
* gcc.c-torture/execute/pr82524.c: New test.
diff --git a/gcc/testsuite/gcc.dg/pr82274-1.c b/gcc/testsuite/gcc.dg/pr82274-1.c
new file mode 100644
index 000000000000..f96b7338fc47
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr82274-1.c
@@ -0,0 +1,16 @@
+/* PR target/82274 */
+/* { dg-do run } */
+/* { dg-shouldfail "trapv" } */
+/* { dg-options "-ftrapv" } */
+
+int
+main ()
+{
+#ifdef __SIZEOF_INT128__
+ volatile __int128 m = -(((__int128) 1) << (__CHAR_BIT__ * __SIZEOF_INT128__ / 2));
+#else
+ volatile long long m = -(1LL << (__CHAR_BIT__ * __SIZEOF_LONG_LONG__ / 2));
+#endif
+ m = m * m;
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/pr82274-2.c b/gcc/testsuite/gcc.dg/pr82274-2.c
new file mode 100644
index 000000000000..a9643b5a923d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr82274-2.c
@@ -0,0 +1,26 @@
+/* PR target/82274 */
+/* { dg-do run } */
+/* { dg-options "-O2" } */
+
+int
+main ()
+{
+#ifdef __SIZEOF_INT128__
+ __int128 m = -(((__int128) 1) << (__CHAR_BIT__ * __SIZEOF_INT128__ / 2));
+ volatile __int128 mv = m;
+ __int128 r;
+#else
+ long long m = -(1LL << (__CHAR_BIT__ * __SIZEOF_LONG_LONG__ / 2));
+ volatile long long mv = m;
+ long long r;
+#endif
+ if (!__builtin_mul_overflow (mv, mv, &r))
+ __builtin_abort ();
+ if (!__builtin_mul_overflow_p (mv, mv, r))
+ __builtin_abort ();
+ if (!__builtin_mul_overflow (m, m, &r))
+ __builtin_abort ();
+ if (!__builtin_mul_overflow_p (m, m, r))
+ __builtin_abort ();
+ return 0;
+}
diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog
index aa1b04bec43b..2c08fe306dc0 100644
--- a/libgcc/ChangeLog
+++ b/libgcc/ChangeLog
@@ -1,3 +1,10 @@
+2017-10-13 Jakub Jelinek <jakub@redhat.com>
+
+ PR target/82274
+ * libgcc2.c (__mulvDI3): If both operands have
+ the same highpart of -1 and the topmost bit of lowpart is 0,
+ multiplication overflows even if both lowparts are 0.
+
2017-09-28 Krister Walfridsson <krister.walfridsson@gmail.com>
Backport from mainline
diff --git a/libgcc/libgcc2.c b/libgcc/libgcc2.c
index 5d3c69f16aae..83f865a04dba 100644
--- a/libgcc/libgcc2.c
+++ b/libgcc/libgcc2.c
@@ -375,7 +375,8 @@ __mulvDI3 (DWtype u, DWtype v)
}
else
{
- if (uu.s.high == (Wtype) -1 && vv.s.high == (Wtype) - 1)
+ if ((uu.s.high & vv.s.high) == (Wtype) -1
+ && (uu.s.low | vv.s.low) != 0)
{
DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
* (UDWtype) (UWtype) vv.s.low};