aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2013-07-08 10:11:08 +0200
committerJakub Jelinek <jakub@gcc.gnu.org>2013-07-08 10:11:08 +0200
commit046f1eeec356d116ef3dcfc512d0ef8085efc8bf (patch)
tree313ca83a7db895760a39111d559cdb9fddfd83a0
parent466c212744b8307eef2e40272ceda90e8fc12f97 (diff)
downloadgcc-046f1eeec356d116ef3dcfc512d0ef8085efc8bf.zip
gcc-046f1eeec356d116ef3dcfc512d0ef8085efc8bf.tar.gz
gcc-046f1eeec356d116ef3dcfc512d0ef8085efc8bf.tar.bz2
re PR rtl-optimization/57829 (Wrong constant folding)
PR rtl-optimization/57829 * simplify-rtx.c (simplify_binary_operation_1) <case IOR>: Ensure that mask bits outside of mode are just sign-extension from mode to HWI. * gcc.c-torture/execute/pr57829.c: New test. From-SVN: r200768
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/simplify-rtx.c1
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr57829.c31
4 files changed, 43 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 6ece60c..e4fc901 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2013-07-08 Jakub Jelinek <jakub@redhat.com>
+
+ PR rtl-optimization/57829
+ * simplify-rtx.c (simplify_binary_operation_1) <case IOR>: Ensure that
+ mask bits outside of mode are just sign-extension from mode to HWI.
+
2013-07-08 Michael Zolotukhin <michael.v.zolotukhin@gmail.com>
* config/i386/i386-opts.h (enum stringop_alg): Add vector_loop.
diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c
index 9bb31e7..be54db8 100644
--- a/gcc/simplify-rtx.c
+++ b/gcc/simplify-rtx.c
@@ -2818,6 +2818,7 @@ simplify_binary_operation_1 (enum rtx_code code, enum machine_mode mode,
HOST_WIDE_INT mask = INTVAL (trueop1) << count;
if (mask >> count == INTVAL (trueop1)
+ && trunc_int_for_mode (mask, mode) == mask
&& (mask & nonzero_bits (XEXP (op0, 0), mode)) == 0)
return simplify_gen_binary (ASHIFTRT, mode,
plus_constant (mode, XEXP (op0, 0),
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index c0a3b59..f4d0b6f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2013-07-08 Jakub Jelinek <jakub@redhat.com>
+
+ PR rtl-optimization/57829
+ * gcc.c-torture/execute/pr57829.c: New test.
+
2013-07-08 Michael Zolotukhin <michael.v.zolotukhin@gmail.com>
* gcc.target/i386/memcpy-vector_loop-1.c: New.
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr57829.c b/gcc/testsuite/gcc.c-torture/execute/pr57829.c
new file mode 100644
index 0000000..b5c3d18
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr57829.c
@@ -0,0 +1,31 @@
+/* PR rtl-optimization/57829 */
+
+__attribute__((noinline, noclone))
+int
+f1 (int k)
+{
+ return 2 | ((k - 1) >> ((int) sizeof (int) * __CHAR_BIT__ - 1));
+}
+
+__attribute__((noinline, noclone))
+long int
+f2 (long int k)
+{
+ return 2L | ((k - 1L) >> ((int) sizeof (long int) * __CHAR_BIT__ - 1));
+}
+
+__attribute__((noinline, noclone))
+int
+f3 (int k)
+{
+ k &= 63;
+ return 4 | ((k + 2) >> 5);
+}
+
+int
+main ()
+{
+ if (f1 (1) != 2 || f2 (1L) != 2L || f3 (63) != 6 || f3 (1) != 4)
+ __builtin_abort ();
+ return 0;
+}