]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR rtl-optimization/75964 (insn combiner removes comparison after ABS)
authorGeorg-Johann Lay <avr@gjlay.de>
Tue, 22 Aug 2017 10:07:51 +0000 (10:07 +0000)
committerGeorg-Johann Lay <gjl@gcc.gnu.org>
Tue, 22 Aug 2017 10:07:51 +0000 (10:07 +0000)
gcc/
Backport from 2017-05-06 trunk r247719.
PR rtl-optimization/75964
* simplify-rtx.c (simplify_const_relational_operation): Remove
invalid handling of comparisons of integer ABS.
gcc/testsuite/
Backport from 2017-05-06 trunk r247719.
PR rtl-optimization/75964
* gcc.dg/torture/pr75964.c: New test.

From-SVN: r251271

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

index bf7af04a34174e7bd88a7e6ac216621d470d4153..fc3d5a57e5e878bb1e946f9937a0fadc745a610a 100644 (file)
@@ -1,3 +1,12 @@
+2017-08-22  Georg-Johann Lay  <avr@gjlay.de>
+
+       Backport from trunk r247719.
+       2017-05-06  Richard Sandiford  <richard.sandiford@linaro.org>
+
+       PR rtl-optimization/75964
+       * simplify-rtx.c (simplify_const_relational_operation): Remove
+       invalid handling of comparisons of integer ABS.
+
 2017-08-22  Georg-Johann Lay  <avr@gjlay.de>
 
        Backport from 2017-07-05 trunk r249995.
index 5f732b279c8c92be9eb34b8758dd9dc6440cd4c8..2388fd0e0b9823a7b37769c7fd6d610b4a8bb416 100644 (file)
@@ -5117,34 +5117,14 @@ simplify_const_relational_operation (enum rtx_code code,
        {
        case LT:
          /* Optimize abs(x) < 0.0.  */
-         if (!HONOR_SNANS (mode)
-             && (!INTEGRAL_MODE_P (mode)
-                 || (!flag_wrapv && !flag_trapv && flag_strict_overflow)))
-           {
-             if (INTEGRAL_MODE_P (mode)
-                 && (issue_strict_overflow_warning
-                     (WARN_STRICT_OVERFLOW_CONDITIONAL)))
-               warning (OPT_Wstrict_overflow,
-                        ("assuming signed overflow does not occur when "
-                         "assuming abs (x) < 0 is false"));
-              return const0_rtx;
-           }
+         if (!INTEGRAL_MODE_P (mode) && !HONOR_SNANS (mode))
+           return const0_rtx;
          break;
 
        case GE:
          /* Optimize abs(x) >= 0.0.  */
-         if (!HONOR_NANS (mode)
-             && (!INTEGRAL_MODE_P (mode)
-                 || (!flag_wrapv && !flag_trapv && flag_strict_overflow)))
-           {
-             if (INTEGRAL_MODE_P (mode)
-                 && (issue_strict_overflow_warning
-                 (WARN_STRICT_OVERFLOW_CONDITIONAL)))
-               warning (OPT_Wstrict_overflow,
-                        ("assuming signed overflow does not occur when "
-                         "assuming abs (x) >= 0 is true"));
-             return const_true_rtx;
-           }
+         if (!INTEGRAL_MODE_P (mode) && !HONOR_NANS (mode))
+           return const_true_rtx;
          break;
 
        case UNGE:
index 139ea0c5e3b0b647c50a069c9d1007c8d62f208f..d437045a937305beda964da1bdbfd39d49af8544 100644 (file)
@@ -1,3 +1,11 @@
+2017-08-22  Georg-Johann Lay  <avr@gjlay.de>
+
+       Backport from trunk r247719.
+       2017-05-06  Richard Sandiford  <richard.sandiford@linaro.org>
+
+       PR rtl-optimization/75964
+       * gcc.dg/torture/pr75964.c: New test.
+
 2017-08-22  Georg-Johann Lay  <avr@gjlay.de>
 
        Backport from 2017-07-05 trunk r249995, r249996.
diff --git a/gcc/testsuite/gcc.dg/torture/pr75964.c b/gcc/testsuite/gcc.dg/torture/pr75964.c
new file mode 100644 (file)
index 0000000..3b895ba
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-do run } */
+
+typedef __UINT8_TYPE__ uint8_t;
+
+uint8_t __attribute__ ((noinline, noclone))
+abs8 (uint8_t x)
+{
+  if (x & 0x80)
+    x = -x;
+
+  if (x & 0x80)
+    x = 0x7f;
+
+  return x;
+}
+
+int
+main (void)
+{
+  if (abs8 (0) != 0
+      || abs8 (1) != 1
+      || abs8 (127) != 127
+      || abs8 (128) != 127
+      || abs8 (129) != 127
+      || abs8 (255) != 1)
+    __builtin_abort ();
+  return 0;
+}