PR rtl-optimization/57829
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Jul 2013 08:11:08 +0000 (08:11 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 8 Jul 2013 08:11:08 +0000 (08:11 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@200768 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/simplify-rtx.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr57829.c [new file with mode: 0644]

index 6ece60c..e4fc901 100644 (file)
@@ -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.
index 9bb31e7..be54db8 100644 (file)
@@ -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),
index c0a3b59..f4d0b6f 100644 (file)
@@ -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 (file)
index 0000000..b5c3d18
--- /dev/null
@@ -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;
+}