public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10261] middle-end/100672 - fix bogus right shift folding
@ 2021-11-09 13:05 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-11-09 13:05 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e8311f59c6e2fa1f5aacc3da5e95739886ebdee7
commit r10-10261-ge8311f59c6e2fa1f5aacc3da5e95739886ebdee7
Author: Richard Biener <rguenther@suse.de>
Date: Wed May 19 13:35:07 2021 +0200
middle-end/100672 - fix bogus right shift folding
This fixes the bogus use of TYPE_PRECISION on vector types
from optimizing -((int)x >> 31) into (unsigned)x >> 31.
2021-05-19 Richard Biener <rguenther@suse.de>
PR middle-end/100672
* fold-const.c (fold_negate_expr_1): Use element_precision.
(negate_expr_p): Likewise.
* gcc.dg/torture/pr100672.c: New testcase.
(cherry picked from commit 8d51039cb7c807ed84ff7df5416a1e3ba07a5e63)
Diff:
---
gcc/fold-const.c | 4 ++--
gcc/testsuite/gcc.dg/torture/pr100672.c | 19 +++++++++++++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 6e635382fb4..7b4c9c0eb7f 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -511,7 +511,7 @@ negate_expr_p (tree t)
if (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST)
{
tree op1 = TREE_OPERAND (t, 1);
- if (wi::to_wide (op1) == TYPE_PRECISION (type) - 1)
+ if (wi::to_wide (op1) == element_precision (type) - 1)
return true;
}
break;
@@ -704,7 +704,7 @@ fold_negate_expr_1 (location_t loc, tree t)
if (TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST)
{
tree op1 = TREE_OPERAND (t, 1);
- if (wi::to_wide (op1) == TYPE_PRECISION (type) - 1)
+ if (wi::to_wide (op1) == element_precision (type) - 1)
{
tree ntype = TYPE_UNSIGNED (type)
? signed_type_for (type)
diff --git a/gcc/testsuite/gcc.dg/torture/pr100672.c b/gcc/testsuite/gcc.dg/torture/pr100672.c
new file mode 100644
index 00000000000..cc62e71f9a3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr100672.c
@@ -0,0 +1,19 @@
+/* { dg-do run } */
+/* { dg-additional-options "-w -Wno-psabi" } */
+
+typedef long long __attribute__((__vector_size__ (4 * sizeof (long long)))) V;
+
+V
+foo (V v)
+{
+ return -(v >> 1);
+}
+
+int
+main (void)
+{
+ V v = foo ((V) { -2, -4, -6, -8 });
+ if (v[0] != 1 || v[1] != 2 || v[2] != 3 || v[3] != 4)
+ __builtin_abort ();
+ return 0;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-11-09 13:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 13:05 [gcc r10-10261] middle-end/100672 - fix bogus right shift folding Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).