OSDN Git Service

PR rtl-optimization/51023
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 10 Nov 2011 15:36:48 +0000 (15:36 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 10 Nov 2011 15:36:48 +0000 (15:36 +0000)
* combine.c (simplify_comparison) <case SIGN_EXTEND>: Don't use
val_signbit_known_clear_p for signed comparison narrowing
optimization.  Don't check for non-VOIDmode, use
HWI_COMPUTABLE_MODE_P macro.
<case ZERO_EXTEND>: Don't check for non-VOIDmode.
Optimize even when const_op is equal to GET_MODE_MASK (mode),
don't optimize if const_op is negative.

* gcc.c-torture/execute/pr51023.c: New test.

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

gcc/ChangeLog
gcc/combine.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr51023.c [new file with mode: 0644]

index 404b884..faea63a 100644 (file)
@@ -1,3 +1,14 @@
+2011-11-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/51023
+       * combine.c (simplify_comparison) <case SIGN_EXTEND>: Don't use
+       val_signbit_known_clear_p for signed comparison narrowing
+       optimization.  Don't check for non-VOIDmode, use
+       HWI_COMPUTABLE_MODE_P macro.
+       <case ZERO_EXTEND>: Don't check for non-VOIDmode.
+       Optimize even when const_op is equal to GET_MODE_MASK (mode),
+       don't optimize if const_op is negative.
+
 2011-11-10  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/51042
 2011-11-10  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/51042
index ad9aa38..1714c74 100644 (file)
@@ -11397,9 +11397,10 @@ simplify_comparison (enum rtx_code code, rtx *pop0, rtx *pop1)
             later on, and then we wouldn't know whether to sign- or
             zero-extend.  */
          mode = GET_MODE (XEXP (op0, 0));
             later on, and then we wouldn't know whether to sign- or
             zero-extend.  */
          mode = GET_MODE (XEXP (op0, 0));
-         if (mode != VOIDmode && GET_MODE_CLASS (mode) == MODE_INT
+         if (GET_MODE_CLASS (mode) == MODE_INT
              && ! unsigned_comparison_p
              && ! unsigned_comparison_p
-             && val_signbit_known_clear_p (mode, const_op)
+             && HWI_COMPUTABLE_MODE_P (mode)
+             && trunc_int_for_mode (const_op, mode) == const_op
              && have_insn_for (COMPARE, mode))
            {
              op0 = XEXP (op0, 0);
              && have_insn_for (COMPARE, mode))
            {
              op0 = XEXP (op0, 0);
@@ -11477,10 +11478,11 @@ simplify_comparison (enum rtx_code code, rtx *pop0, rtx *pop1)
 
        case ZERO_EXTEND:
          mode = GET_MODE (XEXP (op0, 0));
 
        case ZERO_EXTEND:
          mode = GET_MODE (XEXP (op0, 0));
-         if (mode != VOIDmode && GET_MODE_CLASS (mode) == MODE_INT
+         if (GET_MODE_CLASS (mode) == MODE_INT
              && (unsigned_comparison_p || equality_comparison_p)
              && HWI_COMPUTABLE_MODE_P (mode)
              && (unsigned_comparison_p || equality_comparison_p)
              && HWI_COMPUTABLE_MODE_P (mode)
-             && ((unsigned HOST_WIDE_INT) const_op < GET_MODE_MASK (mode))
+             && (unsigned HOST_WIDE_INT) const_op <= GET_MODE_MASK (mode)
+             && const_op >= 0
              && have_insn_for (COMPARE, mode))
            {
              op0 = XEXP (op0, 0);
              && have_insn_for (COMPARE, mode))
            {
              op0 = XEXP (op0, 0);
index ecfcdbe..ffa8b57 100644 (file)
@@ -1,3 +1,8 @@
+2011-11-10  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/51023
+       * gcc.c-torture/execute/pr51023.c: New test.
+
 2011-11-10  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/51042
 2011-11-10  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/51042
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr51023.c b/gcc/testsuite/gcc.c-torture/execute/pr51023.c
new file mode 100644 (file)
index 0000000..34252ea
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR rtl-optimization/51023 */
+
+extern void abort (void);
+
+short int
+foo (long int x)
+{
+  return x;
+}
+
+int
+main ()
+{
+  long int a = 0x4272AL;
+  if (foo (a) == a)
+    abort ();
+  return 0;
+}