]> gcc.gnu.org Git - gcc.git/commitdiff
re PR middle-end/61158 (negative shift at fold-const.c:12095)
authorJakub Jelinek <jakub@gcc.gnu.org>
Thu, 15 May 2014 10:01:11 +0000 (12:01 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 15 May 2014 10:01:11 +0000 (12:01 +0200)
PR tree-optimization/61158
* fold-const.c (fold_binary_loc): If X is zero-extended and
shiftc >= prec, make sure zerobits is all ones instead of
invoking undefined behavior.

* gcc.dg/pr61158.c: New test.

From-SVN: r210467

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr61158.c [new file with mode: 0644]

index beac3a76047aabfb9c7d5d5518b894a7438d6287..3b4e9c28dda430accad1a39d6d0d9f1fc22c54da 100644 (file)
@@ -1,12 +1,19 @@
+2014-05-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/61158
+       * fold-const.c (fold_binary_loc): If X is zero-extended and
+       shiftc >= prec, make sure zerobits is all ones instead of
+       invoking undefined behavior.
+
 2014-05-15  Zhenqiang Chen  <zhenqiang.chen@linaro.org>
 
        * regcprop.h: New file.
        * regcprop.c (skip_debug_insn_p): New decl.
        (replace_oldest_value_reg): Check skip_debug_insn_p.
-       (copyprop_hardreg_forward_bb_without_debug_insn.): New function.
-       * shrink-wrap.c: include regcprop.h
-       (prepare_shrink_wrap):
-       Call copyprop_hardreg_forward_bb_without_debug_insn.
+       (copyprop_hardreg_forward_bb_without_debug_insn): New function.
+       * shrink-wrap.c: Include regcprop.h.
+       (prepare_shrink_wrap): Call
+       copyprop_hardreg_forward_bb_without_debug_insn.
 
 2014-05-15  Zhenqiang Chen  <zhenqiang.chen@linaro.org>
 
index 5e064dfa98ce52bceafa94fdab642b7ebe521be4..8f659db76a210e9860416629cf2df7345800f456 100644 (file)
@@ -11972,11 +11972,17 @@ fold_binary_loc (location_t loc,
                      /* See if we can shorten the right shift.  */
                      if (shiftc < prec)
                        shift_type = inner_type;
+                     /* Otherwise X >> C1 is all zeros, so we'll optimize
+                        it into (X, 0) later on by making sure zerobits
+                        is all ones.  */
                    }
                }
              zerobits = ~(unsigned HOST_WIDE_INT) 0;
-             zerobits >>= HOST_BITS_PER_WIDE_INT - shiftc;
-             zerobits <<= prec - shiftc;
+             if (shiftc < prec)
+               {
+                 zerobits >>= HOST_BITS_PER_WIDE_INT - shiftc;
+                 zerobits <<= prec - shiftc;
+               }
              /* For arithmetic shift if sign bit could be set, zerobits
                 can contain actually sign bits, so no transformation is
                 possible, unless MASK masks them all away.  In that
@@ -11994,7 +12000,7 @@ fold_binary_loc (location_t loc,
          /* ((X << 16) & 0xff00) is (X, 0).  */
          if ((mask & zerobits) == mask)
            return omit_one_operand_loc (loc, type,
-                                    build_int_cst (type, 0), arg0);
+                                        build_int_cst (type, 0), arg0);
 
          newmask = mask | zerobits;
          if (newmask != mask && (newmask & (newmask + 1)) == 0)
index 0146e0cb9cf07047733f36d17fdea35abca7588a..ae257928bda007edbd72ce14d01d4f59d4df9180 100644 (file)
@@ -1,3 +1,8 @@
+2014-05-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/61158
+       * gcc.dg/pr61158.c: New test.
+
 2014-05-15  Andreas Schwab  <schwab@suse.de>
 
        * obj-c++.dg/exceptions-3.mm: Remove check for message no longer
diff --git a/gcc/testsuite/gcc.dg/pr61158.c b/gcc/testsuite/gcc.dg/pr61158.c
new file mode 100644 (file)
index 0000000..d0ba7f3
--- /dev/null
@@ -0,0 +1,12 @@
+/* PR tree-optimization/61158 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-original" } */
+
+unsigned long long
+foo (unsigned int x)
+{
+  return ((unsigned long long) x & 0x00ff000000000000ULL) >> 40;
+}
+
+/* { dg-final { scan-tree-dump "return 0;" "original" { target { ilp32 || lp64 } } } } */
+/* { dg-final { cleanup-tree-dump "original" } } */
This page took 0.115949 seconds and 5 git commands to generate.